Hi Jeff, Here's a solution u can have a look at:
open(INPUTFILE, "d:/data.log");
open(OUTPUTFILE, ">d:/output.log");
my $last_str = "INIT";
RECORD: while(<INPUTFILE>){
chomp;
$str = $_;
if ($last_str ne "INIT" && length($str) != 0){
print OUTPUTFILE "$last_str $str\n";
}
$last_str = $str;
if (length($str) == 0){
$last_str = "INIT";
print OUTPUTFILE "\n";
}
}
Bedanta
-----Original Message-----
From: Jeff Pang [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 29, 2005 11:53 AM
To: Perl Beginners
Subject: help about regex matching
hi,list,
I have a file looking as below:
356.5
192.168.2.20
283.3
192.168.2.21
261.9
192.168.2.22
135.9
192.168.2.23
557
192.168.2.24
79.4
192.168.2.25
349
192.168.2.26
265.1
192.168.2.27
326
192.168.2.28
404
192.168.2.29
331
192.168.2.30
612
192.168.2.31
...
I want to get this result:
356.5 192.168.2.20
283.3 192.168.2.21
261.9 192.168.2.22
...
and,I write this regex for matching:
{
local $/="";
while (<FILE>)
{
next unless /^(.+?)$(?=.*(\d+\.\d+\.\d+\.\d+))/sm;
print $1,"\t",$2,"\n";
}
}
but it can't work correctly.
So,I want to know how to adjust this regex?Thanks.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
output.log
Description: Binary data
data.log
Description: Binary data
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
