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

Re: Writing a new file in Perl

by daxim (Curate)
on Jul 05, 2012 at 11:09 UTC ( [id://980027]=note: print w/replies, xml ) Need Help??


in reply to Writing a new file in Perl

use strictures; use Regexp::Common qw/net/; use autodie qw(:all); open my $in, '<:raw', 'Samplle_2.txt'; open my $out, '>:raw', 'Google_1'; while (my $line = <$in>) { my ($ip) = $line =~ /(?: \d+ [ ] ms \s+ ){3} ($RE{net}{IPv4})/msx; print {$out} "$ip\n" if defined $ip; }

Replies are listed 'Best First'.
Re^2: Writing a new file in Perl
by maheshkumar (Sexton) on Jul 05, 2012 at 11:44 UTC

    Can you explain a bit what have you done here?

      What if the text file in the following format?

      ns2.imagebam.com. 288 IN A 208.100.30.161 ns3.imagebam.com. 288 IN A 80.237.155.76 Traceroute: 7 1291796828 1291796823 1291796823 LocalDNS 0.media.colleg +ehumor.com 92.123.72.112 traceroute to 92.123.72.112 (92.123.72.112), 30 hops max, 60 byte pack +ets 1 192.168.178.1 0.577 ms * * 2 82.135.16.28 43.200 ms 47.166 ms 51.078 ms 3 212.18.7.101 55.219 ms 58.215 ms 62.163 ms 4 212.18.6.166 70.082 ms 74.198 ms 78.128 ms 5 80.81.192.28 83.097 ms 86.971 ms 90.658 ms 6 92.123.72.112 94.970 ms 102.063 ms 66.001 ms Traceroute: 14 1291796828 1291796823 1291796823 OpenDNS 0.media.colleg +ehumor.com 62.41.85.112 traceroute to 62.41.85.112 (62.41.85.112), 30 hops max, 60 byte packet +s 1 * * * 2 82.135.16.28 42.731 ms 45.991 ms 50.306 ms 3 212.18.7.101 56.221 ms 58.592 ms 62.741 ms 4 212.18.6.77 65.781 ms 70.059 ms 74.070 ms 5 217.71.108.93 80.675 ms 84.516 ms 92.326 ms 6 217.71.96.169 97.099 ms 61.316 ms 61.671 ms 7 194.59.190.3 68.525 ms 66.420 ms 67.461 ms 8 134.222.231.49 69.524 ms 70.433 ms 69.926 ms 9 134.222.229.49 70.076 ms 66.691 ms 67.396 ms 10 134.222.229.205 80.651 ms 79.661 ms 76.400 ms 11 134.222.229.222 77.579 ms 71.688 ms 71.845 ms 12 134.222.231.22 71.431 ms 70.759 ms 134.222.231.226 70.182 ms 13 62.41.85.112 70.377 ms 70.854 ms 70.851 ms Traceroute: 10 1291796828 1291796823 1291796823 OpenDNS 0.media.colleg +ehumor.com 213.155.157.35 traceroute to 213.155.157.35 (213.155.157.35), 30 hops max, 60 byte pa +ckets
        Then you simply need to change the regex.
Re^2: Writing a new file in Perl
by Anonymous Monk on Jul 05, 2012 at 11:48 UTC

    The {} isn't needed here

    print {$out} "$ip\n" if defined $ip;

    You can write  print $out "$ip\n";

      It is good style to wrap the dative object in braces.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found