Ajit P Singh wrote:
>
> Could some good samaritan help me out with this pls...
>
> I am trying to find a regular expression for the below string..
>
> ExchangeName = MOLD%20WEST
> ExpectedDate = ZZZZZZZZ
> LineStatus = Z
> Status = NO
> 200 OK -
>
> and i am trying with something as below:
> $line =~ /([a-zA-Z_0-9.]+)\s*=\s*([a-zA-Z_0-9.]+)/;
>
> I am able to fix the first three lines; but the last line (200 OK - )
> is giving me problems...
>
> I also tried.
>
> $line =~ /([a-zA-Z_0-9.]+)\s*=\-\s*([a-zA-Z_0-9.]+)/;
>
> but it gives me an error as i m trying put the above values in a hash.
Hi Ajit.
I'm not clear what result you want for the last line, but this should help.
Cheers,
Rob
use strict;
use warnings;
while (<DATA>) {
if (/(.*?)\s*-/) {
printf "\$1 = %s\n", $1;
}
elsif (/([^\s=]+).*?([^\s=]+)/) {
printf "\$1 = %-14s \$2 = %s\n", $1, $2;
}
}
__DATA__
ExchangeName = MOLD%20WEST
ExpectedDate = ZZZZZZZZ
LineStatus = Z
Status = NO
200 OK -
**OUTPUT
$1 = ExchangeName $2 = MOLD%20WEST
$1 = ExpectedDate $2 = ZZZZZZZZ
$1 = LineStatus $2 = Z
$1 = Status $2 = NO
$1 = 200 OK
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>