in reply to RegEx Confusion
It prints 1 for me, as I expected. If you run the program below and it prints 1 for you as well, something you said is not true. Find out what, and you'll find your problem.
$dev_ref->{hostname} = '2383-RWAN-1'; $dev_ref->{grbr } = '2383'; my $pattern = qr{HOSTNAME:\s*(?:\d{4}-)?$dev_ref->{hostname}\s+GRBR:\s +*$dev_ref->{grbr}}i; my $buffer = <<'__EOI__'; 9600/ARQ Some Company ---> Unauthorized use of this router is prohibited <--- ******************************************************* * Hostname: 2383-rwan-1 GRBR: 2383 * * Model: Cisco 1234 * * Location: Ansalon , DL * ******************************************************* ---> Unauthorized Access is strictly prohibited <--- User Access Verification Username: __EOI__ my $hostname = $buffer =~ m/$pattern/i ? 1 : 0 ; print($hostname, "\n");
By the way, the i option on m/$pattern/i is useless, since it's already on for $pattern. Also, you should probably escape what you putt in from $dev_ref:
qr{HOSTNAME:\s*(?:\d{4}-)?\Q$dev_ref->{hostname}\E\s+GRBR:\s*\Q$dev_ref->{grbr}\E}i
Neither change would affect the result here, though.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RegEx Confusion
by Argel (Prior) on Sep 21, 2005 at 20:05 UTC | |
by ikegami (Patriarch) on Sep 21, 2005 at 20:25 UTC |