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:

$frgtlocs{$scfd_name_frgt}=[$stt_pst_frgt,$stp_pst_frgt,$lgh_frgt];

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.