Harry Putnam wrote:
> #!/usr/local/bin/perl -w
>
> $regex = shift;
> while(<>){
> $cnt++;
> if($cnt == 1){
> print "$ARGV\n";
> }
> if(/$regex/){
> printf "%-3d %s", $cnt, $_;
> }elsif(/^$/){
> $cnt = 0;
> next;
> }
> }
you are feeding reg directly to Perl from the user in 'if(/$regex/)' there
is a chance that this will crash your program consider:
#!/usr/bin/perl -w
use strict;
eval{
while(<STDIN>){
chop;
/$_/o;
}
};
print $@ if($@);
__END__
the program crash if i supply '\':
Trailing \ in regex m/\/ at ./tmp.pl line 31, <STDIN> line 2.
you should consider things like that when you taking stuff directly from the
user. you should also consider putting a 'o' like:
if(/$regex/o)
since $regex don't change after your program start running, this will save
you sometime to recompile the whole reg when it's encountered.
david
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]