Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to print out list of lists

Posted on 1998-08-20
3
Medium Priority
?
148 Views
Last Modified: 2010-03-05
.......
push(@$list{$_},$name);
......
how can I print out all elements of this list of lists? Thanks.
0
Comment
Question by:tian
3 Comments
 

Expert Comment

by:kaijen
ID: 1204422
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.
0
 

Author Comment

by:tian
ID: 1204423
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}.......
 
0
 
LVL 5

Accepted Solution

by:
b2pi earned 200 total points
ID: 1204424
use strict;


my($i, $j, %list, $ndx);
$i = 0;
foreach $ndx (qw(a b c d)) {
    for ($j = $i; $j < $i +4;$j++) {
      push(@{$list{$ndx}}, $j);
    }
    $i += 4;
}

## Now print it
print "Printing:\n";
foreach $ndx (sort keys %list) {
    print "$ndx:";
    foreach (@{$list{$ndx}}) {
      print "\t$_\n";
    }
    for ($i = 0; $i <= $#{$list{$ndx}}; $i++) {
      print "\t$list{$ndx}->[$i]\n";
    }
    print "\n";
   
}

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question