Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
piece of code
Vallari
can you plz help me in understanding this piece of code
if ($file =~ ".shtml" or $file =~ ".html") {
$thisFile="Y:$AREAVPATH/$file" ;
open(HTMLFILE,"<$thisFile") ;
while ($line = <HTMLFILE>) {
if ($line =~ '<meta name="Content File"') {
my $contentpos = index("$line","content=") + 9 ;
my $content = substr("$line",$contentpos) ;
($contentFile,$rest) = split('"',$content) ;
if ($contentFile ne "#") {
__INSERT__("<file path='$contentFile' comment='Associated content.'/>\n");
}
}
}
close(HTMLFILE) ;
Find more posts tagged with
Comments
Adam Stoller
# If the contents of the variable, $file, contains within it,
anywhere
,
# the string "shtml" or "html" preceded by
any
character ...
if ($file =~ ".shtml" or $file =~ ".html") {
# set $thisfile to be the file-system-path to $file
$thisFile="Y:$AREAVPATH/$file" ;
# open $thisfile for reading [NOTE: no error checking performed]
open(HTMLFILE,"<$thisFile") ;
# read each line of content within the file
while ($line = <HTMLFILE>) {
# if the line read in contains the string of text indicated
# [NOTE: the line of text should probably have been chomp'ed
if ($line =~ '<meta name="Content File"') {
# set $contentpos to the index position of the string
# "content=" (the position of the 'c' character) and then
# advance 9 characters from there (one character after the '='
# the assumption being that it is an opening double-quote
my $contentpos = index("$line","content=") + 9 ;
# set $content to the contents of $line, minus all text prior
# $contentpos
my $content = substr("$line",$contentpos) ;
# split the contents of $content on double-quote characters
# putting everything before the first double-quote into
# $contentFile, and everything else into $rest
($contentFile,$rest) = split('"',$content) ;
# If the contents of $contentFile does not equal (exactly) '#'
if ($contentFile ne "#") {
# insert the text below into the instantiated wft code
__INSERT__("<file path='$contentFile' comment='Associated content.'/>\n");
}
}
}
# close the file that was [may have been] opened for reading
close(HTMLFILE) ;
}
Although it is questionable about what this code is actually supposed to be doing, a better way to write it would be:
if ($file =~ "
\
.shtml
$
" or $file =~ "
\
.html
$
") {
$thisFile="Y:$AREAVPATH/$file" ;
if (
open(HTMLFILE,"<$thisFile")
){
while ($line = <HTMLFILE>) {
chomp($line);
if ($line =~ '<meta name="Content File"') {
my $contentpos = index("$line","content=") + 9 ;
my $content = substr("$line",$contentpos) ;
($contentFile,$rest) = split(
/[\'\"]/
,$content) ;
if ($contentFile ne "#") {
__INSERT__("<file path='$contentFile' comment='Associated content.'/>\n");
}
}
}
close(HTMLFILE) ;
}
}
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Vallari
thank you