Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (5)
    As of 2017-08-21 00:14 GMT
    Find Nodes?
      Voting Booth?
      Who is your favorite scientist and why?

      Results (317 votes). Check out past polls.