Link to home
Start Free TrialLog in
Avatar of tian
tian

asked on

how to print out list of lists

.......
push(@$list{$_},$name);
......
how can I print out all elements of this list of lists? Thanks.
Avatar of kaijen
kaijen

I'm not sure what you're doin' with the push statement. I think $name should be something like ($name) or another slice.
Am I right?

In general printing LoLs works like:

@strArray = ("a;b;c;d", "e;f;g;h", "i;j;k" );

for $i ( 0 .. 2 )
{
  push @LoL, [ split /;/, $strArray[$i] ];
}

for ( @LoL )
{
  for ( @$_ )
    {
      print "$_\n";
    }
}

Best regards,
Kai.
Avatar of tian

ASKER

Thanks Kai,
I still can not solve it seeing your comment.(maybe i am too stupid)
In fact What I am trying to do is:(you can see my last question:"implement it in elegant way"for reference)

    ....
 foreach $f (@files){
    $name=$f;
    $open(FILE,$f) || die "cannot open";

    while(<FILE>){
      if(exists $pattern{$_}){
         push @{$list{$_}},$name; # push(@$list{$_},$name); doesnot work
      }
    }
}

   ....
 #then how to print content of the @list{pattern1} @list{pattern2}.......
 
ASKER CERTIFIED SOLUTION
Avatar of b2pi
b2pi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial