astronogun has asked for the wisdom of the Perl Monks concerning the following question:
Im currently testing and studying regular expression with splitting. Right now I have this code:
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";} }
The test.txt contains the ff:
host1 dns:192.168.243.30,asdf host2 dns:192.168.243.1,qwert
When I run the code it doesn't displayed anything... It seems the expression didn't matched... But when I tried changing the input file with only "dns:x.x.x.x" it matched. Is there something missing with my code? Thanks so much..
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex and splitting
by GrandFather (Saint) on Apr 29, 2012 at 04:34 UTC | |
|
Re: Regex and splitting
by AnomalousMonk (Archbishop) on Apr 29, 2012 at 07:29 UTC | |
|
Re: Regex and splitting
by jwkrahn (Abbot) on Apr 29, 2012 at 06:31 UTC | |
|
Re: Regex and splitting
by Kenosis (Priest) on Apr 29, 2012 at 05:45 UTC | |
by Anonymous Monk on Apr 30, 2012 at 04:22 UTC | |
|
Re: Regex and splitting
by 2teez (Vicar) on Apr 29, 2012 at 07:38 UTC | |
|
Re: Regex and splitting
by Anonymous Monk on Apr 29, 2012 at 04:31 UTC | |
|
Re: Regex and splitting
by Kenosis (Priest) on Apr 29, 2012 at 16:17 UTC |