Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Search for a string in a file

by bv (Friar)
on Mar 01, 2010 at 19:57 UTC ( [id://825992]=note: print w/replies, xml ) Need Help??


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);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://825992]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-19 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found