Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: input from STDIN or from a file

by naikonta (Curate)
on Jan 28, 2008 at 17:16 UTC ( #664713=note: print w/replies, xml ) Need Help??

in reply to input from STDIN or from a file

I don't know how complex your program would be, but I usually just use,
$ cat file.txt a b c $ cat #!/usr/bin/perl -l while (<>) { $_ = uc; print; } $ perl file.txt A B C $ cat file.txt | perl A B C
Or, just perl -lpe '$_=uc' if it's really that simple. Anyway, I don't see anything wrong with your code.

Update: Fixed missing -l (only the dash was there). Thanks almut :-)

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Replies are listed 'Best First'.
Re^2: input from STDIN or from a file
by almut (Canon) on Jan 28, 2008 at 19:17 UTC
    #!/usr/bin/perl - ^

    I'm not sure you want the dash at the end of the shebang line...

    It doesn't do any harm when invoking the code like you did, but when I try to run your sample code/data without explicitly calling perl (rather letting the OS handle the shebang), I'm getting

    $ cat file.txt | ./ Can't locate object method "a" via package "b" (perhaps you forgot to +load "b"?) at - line 1.

    I suppose this is because what comes in through stdin is being interpreted as Perl code, rather than as content to be read via <> ...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://664713]
[Tanktalus]: perldigious: I'm not looking to get rich. I'm looking for interesting work, with good continuity of employment, and maintenance of our current lifestyle. (An improvement wouldn't be bad, either, but that's not a requirement ;) )
erix enjoys the confusion++
[Your Mother]: :P
[Tanktalus]: Without confusion, I'd be out of a job ;)
[Tanktalus]: Already. :D
[Lady_Aleena]: Your Mother, I wish it did have a way to put in a directory to search.
[Your Mother]: Thatís silly. Itís a string op tool.
[Lady_Aleena]: So I guess I'll go argue with File::Find and grep.
[Your Mother]: I would probably use Path::Tiny instead for it's slurp and such.
[Your Mother]: s/it's/its/

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2017-05-23 19:35 GMT
Find Nodes?
    Voting Booth?