Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: printing arrays

by rir (Vicar)
on Dec 31, 2008 at 16:23 UTC ( [id://733498]=note: print w/replies, xml ) Need Help??


in reply to Re: printing arrays
in thread printing arrays

Once you have the list that you want to print; you don't need to use a join join, instead you can just print it with $, set appropriately. $, is also known as $OFS and $OUTPUT_FIELD_SEPARATOR; use perldoc perlvar. This can be much more efficient even with small lists.
my @arr = ( 1, "Ali", 2, "Bobbi", 3, "Charli" ); local $, = " "; print @arr, $/;
Be well,
rir

Updated: join usage

Updated: efficiency comment deleted.

Replies are listed 'Best First'.
Re^3: printing arrays
by borisz (Canon) on Jan 01, 2009 at 13:43 UTC
    Using $, is just another way. But internally $, use join and is __not__ faster or more efficient as the join statement.
    Boris
      You are right; thanks for the correction.

      Be well
      rir

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-03-29 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found