Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Regex and splitting

by jwkrahn (Prior)
on Apr 29, 2012 at 06:31 UTC ( #967906=note: print w/ replies, xml ) Need Help??


in reply to Regex and splitting

open my $infile, "<", "test.txt" or die "cannot open input: $!"; my @infile1= <$infile>; close $infile; foreach my $dns ( @infile1 ) { chomp $dns; if ($dns =~ /(dns:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$ +/){ my ($ip, $dns1) = split /dns:/, $dns; ($ip) = split /,/, $dns1; print "$ip";} }

Perhaps you want something like this:

open my $infile, "<", "test.txt" or die "cannot open input: $!"; while ( my $dns = <$infile> ) { if ( $dns =~ /dns:([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) +/ ) { print "$1"; } } close $infile;


Comment on Re: Regex and splitting
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2013-06-19 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How many continents have you visited?









    Results (656 votes), past polls