Solved

how to print out list of lists

Posted on 1998-08-20
3
139 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 50 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This video discusses moving either the default database or any database to a new volume.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now