in reply to Re: what is @$varname in perl
in thread what is @$varname in perl

i read up on reference and understand a scalar is assigned as reference :

my @array = (1, 2, 3, 'four'); my $reference = \@array;

i modified using your suggestion as below

foreach $line (@lines){ chomp $line; $count++; next unless $count; my @row = (); @row = split(/,/, $line ); push @sheet2 , \@row; } foreach my $row ( sort {$a->[0] cmp $b->[0] || $a->[1] cmp $b- +>[1]} @sheet2 ) #sorting based on date ,then stockcode { chomp $row; print hanw join (',', @$row ),"\n"; }

then why assign @sheet2 as reference

Replies are listed 'Best First'.
Re^3: what is @$varname in perl
by 2teez (Vicar) on Jul 03, 2014 at 15:35 UTC

    this :

    ... my $row; @$row = split(/,/, $line ); push @$sheet2 , $row; ...
    OR
    ... my @row = (); @row = split(/,/, $line ); push @sheet2 , \@row; ...
    Could be written like this in one line instead of three
    ... push @sheet2, [ split(/,/, $line ) ]; ...
    And there is no need for the array variable row at all.
    You could use Data::Dumper to view your variable @sheet2 to confirm.

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re^3: what is @$varname in perl
by perlfan (Parson) on Jul 04, 2014 at 03:18 UTC
    push @sheet2 , \@row;
    You're pushing a reference to @row as an item into @sheet2. In order to create complex data structures (array of arrays, array of hashes, etc) you need to assign references.