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

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.

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

Edit kudra, 2002-04-15 Changed title

Comment on Join a file piped to a perl script
Download Code
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$:./perlscript.pl somefile was ran.

      Tradez
      "Never underestimate the predicability of stupidity"
      - Bullet Tooth Tony, Snatch (2001)
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,
    Zaxo

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2014-12-28 18:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls