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


In reply to Re^4: Script Issues by haukex
in thread Script Issues by Iowachaser

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.