Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks, I am trying to return an array with no luck. I would like to return @L1 but am not sure how to do this. I get a "Can't return outside a subroutine" error. Code is as follows:
sub findLines; foreach $line (@data) { if ($line =~ /notice/) { if ($line =~ /rdy/) { $line =~ s/ /,/g; @L1 = split(/|notice|[[]|,mpmstats:,|[\t]|rdy,|bsy,|rd +,|wr,|ka,|log,|dns,|cls,/, $line); return @L1; } } }
The array contains this:
Wed,Jun,13,01:00:29,2012,777,23,0,15,6,0,0,2 Wed,Jun,13,01:01:29,2012,782,18,0,14,3,0,0,1 Wed,Jun,13,01:02:29,2012,787,13,0,10,3,0,0,0
What I would like to do is iterate through the array in another subroutine. What am I doing wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Returning Array
by MidLifeXis (Monsignor) on Jun 27, 2012 at 14:08 UTC | |
by Anonymous Monk on Jun 27, 2012 at 14:14 UTC | |
by MidLifeXis (Monsignor) on Jun 27, 2012 at 14:23 UTC | |
by muba (Priest) on Jun 27, 2012 at 14:51 UTC | |
|
Re: Returning Array
by Anonymous Monk on Jun 27, 2012 at 14:04 UTC | |
|
Re: Returning Array
by linuxkid (Sexton) on Jun 27, 2012 at 23:07 UTC | |
by muba (Priest) on Jun 28, 2012 at 00:01 UTC |