Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Join a file piped to a perl script

by tradez (Pilgrim)
on Apr 12, 2002 at 19:49 UTC ( #158653=perlquestion: print w/replies, xml ) Need Help??
tradez has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks, I recently needed to write some code to join a file piped to a perl script. Rather then coding the whole
my $file = $argv[0]; open (MYFILE, "$argv[0]"); while(<MYFILE){ .....
I remembered there being a special perl way of handling files piped to a script. a $_ type thing ( special character) that fills a data structure with the array for you, saving me precious key strokes. Please inform.

"Never underestimate the predicability of stupidity"
- Bullet Tooth Tony, Snatch (2001)

Edit kudra, 2002-04-15 Changed title

Replies are listed 'Best First'.
Re: Lazy Coder
by dws (Chancellor) on Apr 12, 2002 at 20:27 UTC
    open (MYFILE, "$argv[0]");

    Unless this script is for controlled use, you might consider untainting $argv[0] before using it. Otherwise, you risk having a day ruined when some lamer passes    'rm -rf * |'
    as an argument.

Re: Lazy Coder
by Zaxo (Archbishop) on Apr 12, 2002 at 20:11 UTC

    You may be looking for the diamond operator, <>. see perldoc perlop.

    After Compline,

      Lazy in a good way:
      my $input = join ('', <>);
      Or, if you prefer named arguments:
      my $input = open (IN, $ARGV[0]) && join ('', <IN>);
      Don't forget that it's @ARGV and not @argv.

      If you're using this as a CGI application, it virtually, but not entirely, goes without saying:
      use CGI;
False lazyness
by Fletch (Chancellor) on Apr 12, 2002 at 19:54 UTC

    perldoc perlopentut, perldoc -f open

      Not really what I was going for, i meant if like prompt$:./ somefile was ran.

      "Never underestimate the predicability of stupidity"
      - Bullet Tooth Tony, Snatch (2001)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://158653]
Approved by jlk
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2016-10-21 20:07 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.