On Sunday, Nov 9, 2003, at 16:32 US/Pacific, Dan Anderson wrote: [..]
while ($_ = <FILE>) { if ($_ =~ m/CREATE.*TABLE/) { $_ = $'; while (not ($_ =~ m/)//)) { # match last parenthesis $_ .= <FILE>; } my $table_name = $`; $table_name = tr/ \t\n\r//d; return $table_name; } }
My Programming Perl book says not to use $' $` and $&. Is there a better way to do this?
well a bit of it has to do with how the Perl Regular Expression Engine works, the other part has to do with making your code a bit more readable, and maintainable. The use of the $' and $` as the "perldoc perlvar" pages will tell you imposes a considerable performance penalty.
right, a bit of clean up of the code:
while (<FILE>) { # it will set the line to $_ by default
# cut off everything BEFORE our 'pattern'
if ( s/.*CREATE.*TABLE//)
{
chomp; # remove any 'newline tokens'
my $line = $_ ; # save off what we have
# read until we have come to the closing paren
while ( $line !~ m/\)/ ) {
$_ = <FILE>;
chomp;
$line .= $_;
}
# we will either have seen that last paren, or it did not exist
( my $table_name = $line ) =~ s/.*\)//;
$table_name = tr/ \t\n\r//d;
return $table_name;
} # found opening line
}# end while loopbeing a bit of a tight translation.
ciao drieux
---
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
