Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: join program in one-liner

by themage (Friar)
on Aug 19, 2005 at 20:21 UTC ( [id://485297]=note: print w/replies, xml ) Need Help??


in reply to join program in one-liner

Hi ppl,

A little better than [id://eric256], based in the [id://Joost]'s idea:

perl -lne '$a[$.].=$_;$.=0 if eof;END{print for@a}'

I don't know also why $. don't reset, but we can always help it.

Replies are listed 'Best First'.
Re^2: join program in one-liner
by bmann (Priest) on Aug 19, 2005 at 22:16 UTC

    Same as yours, but cut out unnecessary space and get rid of the END block:

    # 1 2 3 4 #23456789012345678901234567890123456789012345 perl -lne'$a[$.].=$_;$.=0if eof}{print for@a'

    BTW, perldoc perlvar says:

    $. is reset when the filehandle is closed, but not when an open filehandle is reopened without an intervening close(). For more details, see "I/O Operators" in perlop. Because "<>" never does an explicit close, line numbers increase across ARGV
      And $.=0if eof can be changed:
      # 1 2 3 4 #234567890123456789012345678901234567890123 perl -lne'$a[$.].=$_;$.*=!eof}{print for@a'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-03-28 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found