in reply to Re^3: Script Issues
in thread Script Issues
Hi Mike,
I don't have a copy of 5.8.8 at the moment to test on, but I did take a look at your code. Here's what I found so far:
You're missing a my in front of the first mention of @show and $x, and you're missing an else between the if and its following block, assuming you didn't want just a bare {...} block after the if. I'd also very much recommend you indent your blocks, perltidy or a good IDE can help there.
It looks like the regex for extracting the name works, it's just that at the moment there's no "Mike Cox" in the list. Assuming you want to print only the records that match the names in @show, then you've got your logic reversed: the print $val; print "End:\n"; needs to go in the if block, not the else block (it can also be written print $val, "End:\n";). Also, I notice you've got an asterisk in the string 'Mike Cox*', is that intentional? Is it supposed to be a regex, or do you want to match 'Mike Cox*' literally?
When I make the above changes and add a name that's on the list to @show, the code works for me and the output looks like what you wanted. If you're still having problems, it would be very helpful if you could include the actual output your program is giving you (including error messages).
Here's another small optimization: the declaration of @show can be changed to my %show = map {$_=>1} 'Mike Cox*', '...'; (i.e. turn it into a hash %show where the keys are the names and the values are just "1", or any other true value), and then you can replace if(grep {$name eq $_} @show) with a simple hash lookup if($show{$name}).
Hope this helps,
-- Hauke D
|
|---|