Thread: help with passing Array and string into subroutine
help with passing Array and string into
subroutine
United States
1969-12-31 18:00:00
Help please. I am new to perl and can't find an answer to this
simple question. I want to pass an array and a string into a
subroutine and I just can't figure out how to do it. Here is what I
have and the string always comes up empty:
## start snippet ----------------------------
sub findMatch {
my (array,$text) = _; ##this is the line that doesn't work
foreach $line (array) {
if (index($line, $text) != -1)
{ tempArray = split(/=/,$line); return $tempArray[1];
}
}
return '';
} myArray =
("time=34","tom=29","josh=41","michele=42","owen=41","todd=29");
$age = findMatch(myArray, "josh"); print $age ## age always comes up blank
## end snippet ----------------------------