Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Returning Array

by linuxkid (Sexton)
on Jun 27, 2012 at 23:07 UTC ( [id://978791]=note: print w/replies, xml ) Need Help??


in reply to Returning Array

sub findLines{ foreach $line (@data) { if ($line =~ /notice/) { if ($line =~ /rdy/) { $line =~ s/ /,/g; @L1 = split(/|notice|[[]|,mpmstats:,|[\t]|rdy,|bsy,|rd+,|wr,|k +a,|log,|dns,|cls,/, $line); } } } return @L1; }
should look similar to that.

--linuxkid


imrunningoutofideas.co.cc

Replies are listed 'Best First'.
Re^2: Returning Array
by muba (Priest) on Jun 28, 2012 at 00:01 UTC

    Depending on where in the rest of the code @L1 lives, this would or wouldn't fail to compile under strictures. But let's say, for the sake of argument, that @L1 lives in a scope that encompasses the subroutine. What do you think that @L1 will contain by the time the foreach loop is done? That is, what do you think this subroutine will return?

    Valid answers are:

    1. The first line that matched /notice/ and /rdy/ - the first time @L1 was set, it was to that line, so it's gonna stick, right? You always remember your first time.
    2. The last line that matched /notice/ and /rdy/ - the last time @L1 was set, it was set to that line, so that's what's gonna stick, right?
    3. All lines that matched /notice/ and /rdy/ - each time a line matched, the line got put into @L1, which is an array, which can hold multiple pieces of data, so @L1 remembers all those lines that matched, right?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://978791]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-29 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found