in reply to Re^3: Regular expression match in code
in thread Regular expression match in code

The code I gave in my last reply with hard-coded values for IP addresses, works. Even adding your snippet for "if exists" works. But when I use it in my original code, which reads values from config file, then it doesn't work. Yes, even the snippet you suggested doesn't work. I'm really at my wits end here... :(

Replies are listed 'Best First'.
Re^5: Regular expression match in code
by moritz (Cardinal) on May 12, 2010 at 09:24 UTC
    Try to inspect your data with
    use Data::Dumper; $Data::Dumper::Useqq = 1; print Dumper $var; print Dumper \@allServers;

    You might have some non-printable characters either in the server list or in $var that prevent you from getting matches.

      Surprise surprise,
      print Dumper \@allServers; print Dumper \@bigArray;
      prints nothing; just  $VAR1 = []  print Dumper $var; correctly prints the IP present in the incoming SNMP trap. So my reading from file part is going wrong?! How? Its fairly straight forward and I have even tested it by writing  exit(0); after the read from config (populates @allServers) and write into @bigArray (<ip,server>) format. Help... :(
        The easist explanation is that your open call fails. Since you don't check the return value, it does that silently.
        open my $fh, '<', $configFile or die "Can't open '$configFile' for reading: $!"; my @allServers; while (<$fh>) { push (@allServers, $_) if /^\w/; } close $fh or warn "Error while closing file: $!";
        Perl 6 - links to (nearly) everything that is Perl 6.
Re^5: Regular expression match in code
by AnomalousMonk (Archbishop) on May 12, 2010 at 20:48 UTC
    The code I gave in my last reply with hard-coded values for IP addresses, works.

    truptivk: what follows is intended not as a rebuke, but for future reference. When moritz asked for example code to run, the implicit assumption was that the code would demonstrate the problem, not that it would run just fine. I may not have been the only monk who spent time trying to figure out what (nothing) was wrong with the code. (Well, maybe just a little bit of a rebuke:)

      I understand, and I'm extremely sorry for taking some/many monks' time. I should've found a way to provide code that demonstrated my problem, rather than hard-code values which made it run correctly. Not to make an excuse, but I'm overwhelmed at work with lots to do, and I did the mistake. I sincerely apologise once again. Meanwhile, I'm still trying to figure out what's wrong with my code.
Re^5: Regular expression match in code
by ig (Vicar) on May 12, 2010 at 09:20 UTC

    It might help if you posted a copy of your log file.