Thanks chromatic. Here's the script with additional tests to see what's in $_. at each point.
use strict; use warnings; my $username; my $color; while(<>){ chomp; s/"//g; ($username,$color) = (split /,/,$_)[2,3]; print STDOUT "test of username: $username\n";#NEW print STDOUT "test of dollar-underscore: $_\n";#NEW ALSO if ("agag" =~ m/($username)/){ print STDOUT "here is the username: $username\n"; print STDOUT "here is dollar-underscore: $_\n"; } }
here's the output of 'perl test.pl test.txt' (script includes "use warnings" this time, so they are included in the output)
test of username: adad test of dollar-underscore: ADELMAN,John,adad,Ray test of username: agag test of dollar-underscore: AGAN,John,agag,Aditya test of username: ahah test of dollar-underscore: AHMED,John,ahah,Conor Use of uninitialized value $username in concatenation (.) or string at + test.pl line 11, <> line 4. test of username: test of dollar-underscore: Use of uninitialized value $username in regexp compilation at test.pl +line 13, <> line 4. Use of uninitialized value $username in concatenation (.) or string at + test.pl line 14, <> line 4. here is the username: here is dollar-underscore:

Note that $_ and $username are both coming out as they should (i.e. the split is working) before we get to the if statement. It just looks as though the match "agag" =~ m/($username)/ is failing. (note that the warnings are only being issued at the fourth "line" of the text file -- that is at the empty last line.)

still stumped. Perhaps I'm missing something really basic and obvious about the match operator?


In reply to Re^3: scoping problem? by rocroc
in thread scoping problem? by rocroc

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.