Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: command line perl reading from STDIN

by perlhappy (Novice)
on Jan 22, 2013 at 18:12 UTC ( #1014749=note: print w/replies, xml ) Need Help??


in reply to Re^2: command line perl reading from STDIN
in thread command line perl reading from STDIN

Actually, I think I've just worked it out my head. Took a bit of thinking but this is what i think it is doing
first line gets sent, but because <> is unassigned (before $s), it skips; then reads the second line and assigns $s to the line and does whatever; then reads third line but because <> is unassigned, it skips; reads fourth line and the same happens; restarts with 5 line but again because <> is unassigned before the $s it skips; reads 6th line and assigns it to $s and does whatever again
this continues until end of file

If this is incorrect, let me know. Otherwise I hope this helps anyone else who might look at it. Thanks for your help choroba
  • Comment on Re^3: command line perl reading from STDIN

Replies are listed 'Best First'.
Re^4: command line perl reading from STDIN
by Anonymous Monk on Jan 23, 2013 at 23:32 UTC
     perl -ne ' $s=<>; <>; <>; do_something_with_$s'

    is equivalent to

     perl  -e ' while (<>) { $s=<>; <>; <>; do_something_with_$s} '

    so 4 lines will be read each pass, but only the second line will be used for anything

    Personally, I'd go with something like

     perl -ne 'chomp; print length($_)."\n" if (/^@/);'

    instead.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014749]
help
Chatterbox?
[Corion]: choroba: Yeah - I basically have the same for regenerating README and README.mkdown already, except that I do that in Makefile.PL, but I guess one or the other thing should somehow work ;)
[ambrus]: was this bug: https://rt.cpan. org/Public/Bug/ Display.html?id= 59814
[Corion]: ambrus: Oh - that one would be much harder to automate... The SYNOPSIS section should mostly be a runnable program IMO, but I write only small snippets in my documentation for single functions/methods, and creating the appropriate environment for ...
[Corion]: ... those in an automated fashion seems somewhat hard to me. Although it should do wonders for the test coverage ;)
[haukex]: Corion: I once wrote an automated thingy for that here
[haukex]: here's the code that uses it

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2017-02-27 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (385 votes). Check out past polls.