in reply to Issues With Regex

I am getting "uninitialized value" errors every time with this script. I just changed the code to the following:

my ($LSV, $LSN) = $BE_temp =~ m/^\|\s(\w+_\d+)\s+\|\s+(\w+)\s+\|$/m; if ( $LSV =~ m/dsmgt_03_03/ ) { print "LSV Match\n"; } else { print "LSV Fail\n"; }

When I run my script now, I get the following:

Use of uninitialized value $LSV in pattern match (m//) at C:\Users\civ +ey\Documents\Perl\SDM401-LDAP_Config.pl line 405, <STDIN> line 2. LSV Fail

I will move the relevant pieces of code to a test script and see if that helps... any other ideas?

Thanks!!

Replies are listed 'Best First'.
Re^2: Issues With Regex
by AnomalousMonk (Archbishop) on Jan 08, 2014 at 17:37 UTC
    my ($LSV, $LSN) = $BE_temp =~ m/^\|\s(\w+_\d+)\s+\|\s+(\w+)\s+\|$/m;
    if ( $LSV =~ m/dsmgt_03_03/ ) { ... }

    If the initial match against  $BE_temp fails, the subsequent match against  $LSV will produce a "Use of uninitialized value $LSV in pattern match ..." warning (not error) because  $LSV et al are undefined. The initial match should be tested in some way and subsequent matches (or uses of the extracted strings) made dependent on a successful initial match, e.g.:

    if (my ($LSV, $LSN) = $BE_temp =~ m/^\|\s(\w+_\d+)\s+\|\s+(\w+)\s+\|$/ +m) { do_something_with($LSV); do_something_with($LSN); }
Re^2: Issues With Regex
by GotToBTru (Prior) on Jan 08, 2014 at 16:21 UTC

    What results are you expecting?