Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Although the right solution is to use multiline mode, your code doesn't do anything as the test on the regex reveals. See here:
#!/usr/bin/perl -w use strict; my $data = join '', <DATA>; if($data =~ s|(?=^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\nOS Type: unknown +$)|\n|gm) { print "yes, it worked!"; } #print $data; exit(1); __DATA__ 10.1.1.1 bogus info 10.1.1.2 this could be anything 10.1.1.3 OS Type: unknown 10.1.1.4 filler information 10.1.1.5 OS Type: unknown
The above code returns nothing, meaning that the regex never does the substitution. From a quick rereading of the algorithm, it looks like he is trying to do the following:
1. Read through the file
2. find lines that start with IP addresses
3. ASK if the next line following it has some specific text
4. write an extra space BETWEEN the IP address line and the specific text line
I may be wrong, as the spec. was pretty poorly written. A quick command line example that does this is as follows:
perl -e "$q = qq(the brown dog\n is hailing a cab); if (($q=~m/\n(.*)/ +mg) && ($1 eq q( is hailing a cab))) { print qq(\n$1;)} else {print ' +no luck buddy.';}"

Celebrate Intellectual Diversity


In reply to Re: Re: Multiline Regex by InfiniteSilence
in thread Multiline Regex by Cosmivalin

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2022-07-05 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?