david <[EMAIL PROTECTED]> writes: > 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. Excuse my skull bone density... not sure I follow this. Not sure I see how `chop' does anything to `\' [...] > 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) This looks usefull... thanks But now about that `\'. I don't see an error here when I use it. like one might in a regex. However the program isn't exactly the same one I posted. This is the actuall useable program. Its designed to scan only headers of mail messages in one message per file format. User sets the regex to search for on the command line. a shift leaves the rest for ARGV. Using a regex like '@\w+\.' Finds all instances in headers of a @,followed by one or more word chars, followed by a dot. Not sure I see where a trailing \ would be involved. Unless one were looking for a trailing slash then the regex would be `@\w+\\', which doesn't cause an error here. Having that error occur on 'some\' might be a good thing since it is not a good regex. Actual program: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #!/usr/local/bin/perl -w # Keywords: hdrscn1 - designed to print selected headers by regex. # Sep 11 17:50:54 2002 3 # && ($myscript = $0) =~ s:^.*/::; if (! $ARGV[0] || $ARGV[0] eq "help"){ &usage; exit; } $regex = shift; ## Note that the empty <> below are really the same as ## <ARGV> while(<>){ $cnt++; $tcnt++; if($cnt == 1){ print "\n$ARGV\n"; } if(/$regex/){ printf "%-3d %s", $cnt, $_; ## Here we can test whether all lines are scanned or ## we stop at the first blank one. }elsif(/^$/){ # }elsif(eof){ $cnt = 0; ## IMPORTANT (From Bob Showalter on perl beginner list ## If we don't close ARGV here we just skip to next blank line ## not next file. close(ARGV); next; } } print "$tcnt\n"; sub usage{ print <<EOM; Purpose: scan and print individual mail headers or all mail headers Usage: \`$myscript 'REGEX' FILES' examples: \`$myscript '^Received: ' ~/Mail/group/[0-9]*' (prints only the Received headers) \`$myscript '.' ~/Mail/group/[0-9]*' (prints all headers) EOM } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]