Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: difference between @, $

by si_lence (Deacon)
on Dec 07, 2011 at 17:01 UTC ( [id://942286]=note: print w/replies, xml ) Need Help??


in reply to difference between @, $

Just to add to the answers already given:
I find it really helpful to visualize data structures with Data::Dumper. It helps me to see the difference. So
use Data::Dumper; my @a = ['1','2','3','4']; my $a = ['1','2','3','4']; print Dumper(\@a); print Dumper($a);
gives
$VAR1 = [ [ '1', '2', '3', '4' ] ]; $VAR1 = [ '1', '2', '3', '4' ];
illustrating the difference quite nicely.

Replies are listed 'Best First'.
Re^2: difference between @, $
by johngg (Canon) on Dec 07, 2011 at 18:12 UTC

    It can also be useful to name the variables using Dump() or Dumpxs() (see Data::Dumper) to avoid confusion.

    knoppix@Microknoppix:~$ perl -MData::Dumper -E ' > @arr1 = ( 1 .. 4 ); > @arr2 = [ 1 .. 4 ]; > $arr3 = [ 1 .. 4 ]; > print Data::Dumper->Dumpxs( > [ \ @arr1, \ @arr2, $arr3 ], > [ qw{ *arr1 *arr2 arr3 } ], > );' @arr1 = ( 1, 2, 3, 4 ); @arr2 = ( [ 1, 2, 3, 4 ] ); $arr3 = [ 1, 2, 3, 4 ]; knoppix@Microknoppix:~$

    I hope this is of interest.

    Cheers,

    JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-24 04:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found