Solved

how to print out list of lists

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl string replace for refred url 9 62
Replace  text in a file 2 104
Using Perl DBI to query oracle 3 40
read an xml file in perl 2 30
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

815 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