in reply to Re: Multiline Regex
in thread Multiline Regex
Although the right solution is to use multiline mode, your code doesn't do anything as the test on the regex reveals. See here:
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:
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:#!/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
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Multiline Regex
by the_slycer (Chaplain) on Feb 16, 2001 at 09:09 UTC | |
by kilinrax (Deacon) on Feb 16, 2001 at 20:54 UTC |
In Section
Seekers of Perl Wisdom