>>>>> "sw" == shawn wilson <ag4ve...@gmail.com> writes:
sw> On Wed, Mar 2, 2011 at 3:37 PM, Uri Guttman <u...@stemsystems.com> wrote: >> >>>>> "M" == Matt <lm7...@gmail.com> writes: >> >> 2 lines will do it: >> >> use File::Slurp ; >> >> unless( read_file( $file ) =~ /$whatever/ ) { >> >> # do something >> } >> >> >> what's better about File::Slurp than just doing: sw> my( $file, $string ) = @argv; sw> open my $fh, '<', $file; sw> while( <$fh> ) { sw> print "found" if /$string/ ; sw> } less code, much much faster. you loop over each line. my code does one regex call and stays inside perl for that. inside perl is usually faster than running perl op. use the benchmark module and look at the difference. it will be noticeable. also your code looks at every line whereas my will match the first time and then quit. that is another optimization. you could do the same if you exited the loop upon a match. uri -- Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/