Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I need to regex the next line of a given match and have contents of next line which will be a domain or ip address assign as a variable. The match will either be a domain or an ip on the external ip match on the internal it will always be an ip. The match will be after the headings. Some domains will have www. at the beginning and i need to get rid of this and just have domain.com or .net or whatever


#!perl use strict; use warnings; use DateTime; use LWP::UserAgent; use HTML::Tree; my $newline; my $textfile_new; my @textfiles = <*.txt>; foreach my $textfile (@textfiles) { if ($textfile =~ /(\d+.\d+.\d+.\d+.txt)/) { my ($output_file) = $textfile =~ /(\d+.\d+.\d+.\d+).txt/; open(my $input_fh, '<', $textfile) or die "Failed to open $textfile: $!"; open(my $output_fh, '>', "${output_file}_report.txt") or die "Failed to open ${output_file}_report.txt: $!"; print $output_fh "my description of stuff.\n\n"; my $ua = new LWP::UserAgent; $ua->timeout(10); #10 second timeout $ua->proxy(['http'], 'http://mywebproxy:8080'); while ( <$input_fh> ) { print $output_fh $_; #need to regex for the following then use LWP to get d +ata based on the IP on the next line. my $internal_ip =~ /Internal IP\n(\d+.\d+.\d+.\d+)/; my $external_ip =~ /SIP\(s\)\n(\d+.\d+.\d+.\d+)/; #lwp stuff my $response_internalip = $ua->get("http://myinternali +p_referentialdatasearch"); my $content_internalip = $response_internalip->content +; my $tree_internalip = HTML::Tree->new(); $tree_internalip->parse($content_internalip); print {$output_fh} $tree_internalip, "\n"; my $response_externalip = $ua->get("http://myexternali +plookup/phpwhois-4.2.2/example.php?query=$external_ip&output=normal") +; my $content_externailip = $response_externalip->conten +t; my $tree_externalip = HTML::Tree->new(); $tree_externalip->parse($content_externalip); print {$output_fh} $tree_externalip, "\n"; } } }

In reply to trouble regexing the next line by diamondsandperls

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

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

      Is guessing a good strategy for surviving in the IT business?





      Results (116 votes), past polls