Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Regex host portion of IPv6 address

by steph_bow (Pilgrim)
on Mar 28, 2008 at 08:56 UTC ( [id://676931]=note: print w/replies, xml ) Need Help??


in reply to Regex host portion of IPv6 address

My suggestion ( tested)

my $infile = "try.txt"; open my $INFILE, q{<}, $infile or die; my $outfile = "results.txt"; open my $OUTFILE, q{>}, $outfile or die; while (my $line = <$INFILE>){ $line =~ s/\s+$//; print STDOUT "the line is $line\n"; #if ($line =~ /(\d+):(\d)::\/(\d+)/){ if ($line =~ /(\d+):(.*)\/(\d+)/){ print $OUTFILE "the first decimals are $1\n"; print $OUTFILE "the last decimals are $3\n"; print $OUTFILE "the middle element is $2\n"; } print $OUTFILE "\n"; } close $INFILE; close $OUTFILE;

In $1: you have 2001

Perl understands the ":" in the regex

in $2, you have 1:: or 0:6:4003:: or :12

in $3, you have 64 or 128

Hope it helps !

Here are the reuslts

the first decimals are 2001 the last decimals are 64 the middle element is 1:: the first decimals are 2001 the last decimals are 64 the middle element is 0:6:4003:: the first decimals are 2001 the last decimals are 128 the middle element is :12

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found