Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

Hi,

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


Comment on Re: getting syntex error in pattern search
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989003]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2014-07-22 22:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (129 votes), past polls