in reply to parsing out alias string better in perl to .htm
As a note, your regular expression scares the willies out of me, a strong case for Death to Dot Star!. You probably mean to do something like this:$varalias =~ s/=.*//; # Delete everything(.*) from the equals on $vartarget =~ s/"$//; # Delete the quote at the end($)
Here's a few general tips which can help you simplify your program.# If able to delete the stuff(.*) between the beginning # of the line(^) and the word 'alias' and one-or-more spaces(\s+) # found after that ... if (s/^.*?alias\s+//) { # Extract the 1st, 5th and 7th "words" my ($varalias, $varsource, $vartarget) = (split(' '))[1,5,7]; # Then whatever... }
Also, you can increment a variable with the ++ operator, like so: $i++ and that is the same as $i = $i + 1 but is much shorter.print OUT <<END_HTML; <FOO> <FOO>$varsource <FOO> <FOO>$vartarget <FOO> <FOO> END_HTML
if ($something) { some_code(); if ($something_else) { some_other_code(); } }
|
|---|