Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: getting syntex error in pattern search

by 2teez (Priest)
on Aug 22, 2012 at 10:08 UTC ( #989003=note: print w/replies, xml ) Need Help??

in reply to getting syntex error in pattern search


Please, format your post question effectively
Even when that is done. There are other some other best practice I think you should still look into.

  • Avoid barewords usage like FILE, FH, etc. Instead use a lexically scoped variable like $fh etc
  • use use warnings; use strict;
  • use the 3 argument open function like so:open my $fh, '<',"config.txt" or die "cannot open file : $!";
  • Close your file handles like so: close $fh or die "can't close file: $!";
  • Your construction here will only print "1", after you have corrected the syntax error
    Use this instead:
    ... while(<$fh>){ chomp; (my $ip = $_) =~ m/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/; print $ip,$/; } ...

    I think is even alot better to TEST each of your matched value using "if" like so:
    ... while (<$fh>) { chomp; my $ip=""; if (m/(?<matched_ip>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))/){ $ip = $+{matched_ip}; } print $ip,$/; } ...
Hope this helps

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989003]
LanX wonders, do we have a rule against systematic down voting?
[erix]: we frown :)
[marto]: Does the command line arg --product-version@ help?
[LanX]: xD
[erix]: 'systematic' is going to be hard to define I think
[marto]: Err no @
LanX Much enemy much ore
[Corion]: marto: Naah, my module doesn't care, but the users of my module might expect some things to work in Chrome that only work in later builds (or, as seems to be the case, don't work there either ;) )
[Corion]: But I really wonder - I can tell Chrome to go offline, but requesting pages over the network still succeeds. But if I manually click the "offline" checkbox, that's different :-/

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2017-12-12 20:19 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (335 votes). Check out past polls.