CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Array of Arrays in subroutin

 



leszczyn07
New User

Feb 6, 2008, 2:15 AM

Post #1 of 4 (401 views)
Array of Arrays in subroutin Can't Post

Why my "sub druk" print nothig. I've spend a fiew houers on this.
#!/usr/bin/perl
open IN, "AL";
$i = 0;
foreach $line (<IN>) {
chomp $line;
$a[$i++] = [split /:/, $line];
}
druk (\@a);
sub druk {
my $p = @_;
for my $i (0 .. 2) {
for $j (0 .. 3) {
print "$p->[$i][$j] ";
}
print "\n";
}
}
end
$cat AL
0:1:2:3
4:5:6:7
8:9:0:1


rajiv_chennai
Novice

Feb 6, 2008, 4:00 AM

Post #2 of 4 (396 views)
Re: [leszczyn07] Array of Arrays in subroutin [In reply to] Can't Post

Try my $p = shift; instead of $p = @_;

Hope it help

Regards
Rajiv


KevinR
Veteran


Feb 6, 2008, 11:15 AM

Post #3 of 4 (391 views)
Re: [leszczyn07] Array of Arrays in subroutin [In reply to] Can't Post

this:

my $p = @_;

assigns the length of @_ to $p, not the data in @_. The value of $p will be 1 (one). Do as Rajiv suggested or alternately assign the list to a list:

my ($p) = @_;

next time use "strict" and "warnings" with your perl scripts:

use strict;
use warnings;
-------------------------------------------------


leszczyn07
New User

Feb 7, 2008, 2:37 PM

Post #4 of 4 (386 views)
Re: [KevinR] Array of Arrays in subroutin [In reply to] Can't Post

Thanks, $p = shift works. I guessed it but didn't test because ?...
I had no time to replay I've to play with my daughter 'one two three witch can see' and many things to do.
or maybe its not truth.
I considered to shift to java because notoriously have problem like this,
not yet.
Thank you

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives