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).
In reply to Re: How to name arrays via scalars.
by hdb
in thread How to name arrays via scalars.
by qingdaoghawk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |