Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Stream and Atom flexibility

by seedstitch (Initiate)
on Mar 15, 2008 at 00:28 UTC ( [id://674323]=perlquestion: print w/replies, xml ) Need Help??

seedstitch has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks:

This seems so simple, yet I've not found a clue in the O'Reilly book nor an extensive library of scripts at my disposal:

I need to process either a stream of millions of data points or a single atom with the same script:

> cat stream | foo

> foo bar (where bar is a single element form the stream)

I'm using the following convenient method to processing a stream from STDIN:

while (<>){
process stuff---
}
I tried this hack:

if ($ARGV[0]) {$inline = $ARGV[0]}

do{
process stuff--
}while ($inline = <>);

Course, now perl thinks $ARGV[0] is a file for input, and if I delete @ARGV, perl now waits patiently on STDIN.

I need to be able to disable STDIN when an invocation argument is suppplied. Is that possible?

thanks!

Replies are listed 'Best First'.
Re: Stream and Atom flexibility
by hipowls (Curate) on Mar 15, 2008 at 01:29 UTC

    You could do something like

    if (@ARGV) { process($_) for @ARGV; } else { while (<>) { process($_); } }
    where sub process does the real work.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (11)
As of 2024-04-19 16:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found