I'm trying to split an HTML document into its head and body:
my @contentsArray = split( /<\/head>/is, $fileContents, 1);
if( scalar @contentsArray == 2 ){
$bodyContents = $dbh->quote(trim($contentsArray[1]));
$he开发者_开发技巧adContents = $dbh->quote(trim($contentsArray[0]) . "</head>");
}
is what i have. $fileContents
contains the HTML code. When I run this, it doesn't split. Any one know why?
The third parameter to split is how many results to produce, so if you want to apply the expression only once, you would pass 2.
Note that this does actually limit the number of times the pattern is used to split the string (to one fewer than the number passed), not just limit the number of results returned, so this:
print join ":", split /,/, "a,b,c", 2;
outputs:
a:b,c
not:
a:b
sorry, figured it out. Thought the 1 was how many times it would find the expression not limit the results. Changed to 2 and works.
精彩评论