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

Re: my $var = join('|',@array) not behaving

by grep (Monsignor)
on May 09, 2008 at 02:24 UTC ( #685586=note: print w/replies, xml ) Need Help??


in reply to my $var = join('|',@array) not behaving

Square brackets [] are for creating a reference to an anonymous array. Parens () construct a list which you can assign to an array.
You can read more at perldata and perlref

Try This:

my @array = ( 1, "word", 2 ); my $print_string = join ('|', @array); print "$print_string\n";
grep
One dead unjugged rabbit fish later...

Replies are listed 'Best First'.
Re^2: my $var = join('|',@array) not behaving
by chromatic (Archbishop) on May 09, 2008 at 06:50 UTC
    Parens () construct a list which you can assign to an array.

    Nit: parens group a list. The list is already there, but the precedence of = and , are such that without parentheses, only the first element of the list gets assigned.

      such that without parentheses, only the first element of the list gets assigned.

      Since we're being picky about the language, the list being assigned only has one element, so it's odd to refer to its first element. The assignment is the first element of the larger list.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://685586]
help
Chatterbox?
[holli]: perl 6 is really well thought trough

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2017-09-23 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (272 votes). Check out past polls.

    Notices?