>>>>> "sw" == shawn wilson <[email protected]> writes:
sw> On Wed, Mar 2, 2011 at 3:37 PM, Uri Guttman <[email protected]> wrote: >> >>>>> "M" == Matt <[email protected]> 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 ------ [email protected] -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] http://learn.perl.org/
