Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: How to name arrays via scalars.

by hdb (Prior)
on May 03, 2014 at 10:04 UTC ( #1084880=note: print w/replies, xml ) Need Help??

in reply to How to name arrays via scalars.

Due to a feature of Perl called Autovivification, you only need this:

use strict; use warnings; while(<FGLCS>){ chomp; my ($scfd_name_frgt,$stt_pst_frgt,$stp_pst_frgt,$lgh_frgt)=split /\t +/,$_; $scfd_name_frgt=reverse $scfd_name_frgt; push @{$frgtlocs{$scfd_name_frgt}},($stt_pst_frgt,$stp_pst_frgt,$lgh +_frgt); }

If @{$frgtlocs{$scfd_name_frgt}} does not exist, Perl just creates an array and you are done.

UPDATE: Also looking at these two lines:

@{$scfd_name_frgt}=($stt_pst_frgt,$stp_pst_frgt,$lgh_frgt); $frgtlocs{$scfd_name_frgt}=\@{$scfd_name_frgt};

They can be abbreviated using square brackets to create a reference to an array:


There is no need to create a named array first and then store a reference to it (if that is what you want).

Replies are listed 'Best First'.
Re^2: How to name arrays via scalars.
by qingdaoghawk (Initiate) on May 03, 2014 at 12:03 UTC

    Thanks very much. Your answer has directly solved my problem. I now understand more about the reference.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1084880]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-05-28 19:29 GMT
Find Nodes?
    Voting Booth?