in reply to Re: Search for a string in a file
in thread Search for a string in a file

#!/usr/bin/perl -l my $word = shift; open my $in, '<', shift or die $!; open my $out, '<', shift or die $!; while (<$in>) { print $out $_ if $_ eq $word; } close $in; close $out;

Howdy, Uncle Bob! Nice error checking!


print map{substr'hark, suPerJacent other l',$_,1}(11,7,6,16,5,1,15,18..23,8..10,24,17,0,12,13,3,14,2,4);

Replies are listed 'Best First'.
Re^3: Search for a string in a file
by Fletch (Bishop) on Mar 02, 2010 at 13:38 UTC

    Ruby's File.open throws an exception which the default runtime behavior handles pretty well on its own (not to mention the error message includes the filename which yours doesn't), so yes.

    $ ruby -e 'File.open( ARGV.shift, "r" ) { |f| puts f.readlines }' nott +here -e:1:in `initialize': No such file or directory - notthere (Errno::ENO +ENT) from -e:1:in `open' from -e:1

    And if you're going to be that pedantic you might want to check for the error from print when you try and print to a filehandle you've opened for reading . . .

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Well played. Also it goes to show I need to learn some of these other languages better—I thought that was written in Python!


      print map{substr'hark, suPerJacent other l',$_,1}(11,7,6,16,5,1,15,18..23,8..10,24,17,0,12,13,3,14,2,4);