Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: printing arrays

by borisz (Canon)
on Dec 31, 2008 at 14:35 UTC ( #733473=note: print w/replies, xml ) Need Help??


in reply to printing arrays

There are several ways:
use List::MoreUtils qw/mesh/; print join ' ', mesh @ID, @name;
or
# you lose the order and every id must be unique my %h; @h{@ID} = @name ; print join ' ', %h;
or ...
Boris

Replies are listed 'Best First'.
Re^2: printing arrays
by rir (Vicar) on Dec 31, 2008 at 16:23 UTC
    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.

      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

Re^2: printing arrays
by Spooky (Beadle) on Dec 31, 2008 at 15:13 UTC
    ..thanks so much!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://733473]
help
Chatterbox?
[Corion]: Yeah, you need bool to get a true value, and the rest to return the other value ;)
[choroba]: perl -wE '{package o; use Tie::Scalar; use parent -norequire => "Tie::StdScalar" ;sub FETCH { "x" x int rand 2}} tie my $x, "o" ; say $x for 1 .. 10'
[choroba]: for complete ness

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2017-07-27 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (414 votes). Check out past polls.