John W. Krahn wrote:
John W. Krahn wrote:
$ perl -le'
my $text = q![20060911 14:47:11]p_var1=<SD> KQt=1 HZZ=2: 83,68//p_var2=<QR44>
KQt=1 HZZ=4: 77,57,52,52//p_var3=<543210987> KQt=1 HZZ=9:
52,54,48,52,50,57,49,56,50//p_var4=<001> KQt=1 HZZ=3: 48,48,49//p_var5=<12345>
KQt=1 HZZ=5: 49,50,51,52,53//p_var6=<20060907> KQt=1 HZZ=8:
50,48,48,54,48,57,48,55//p_var7=<0000000WR44> KQt=1 HZZ=11:
48,48,48,48,48,48,48,77,57,52,52//p_var8<X> KQt=1 HZZ=2: 83,68//p_var9=<>
NULL!;
my @p_var = $text =~ /<([^>]*)>/g;
print ">$_<" for @p_var;
'
>SD<
>QR44<
>543210987<
>001<
>12345<
>20060907<
>0000000WR44<
>X<
><
Oops!
my $text = q![20060911 14:47:11]p_var1=<SD> KQt=1 HZZ=2: 83,68//p_var2=<QR44>
KQt=1 HZZ=4: 77,57,52,52//p_var3=<543210987> KQt=1 HZZ=9:
52,54,48,52,50,57,49,56,50//p_var4=<001> KQt=1 HZZ=3: 48,48,49//p_var5=<12345>
KQt=1 HZZ=5: 49,50,51,52,53//p_var6=<20060907> KQt=1 HZZ=8:
50,48,48,54,48,57,48,55//p_var7=<0000000WR44> KQt=1 HZZ=11:
48,48,48,48,48,48,48,77,57,52,52//p_var8<X> KQt=1 HZZ=2: 83,68//p_var9=<>
NULL!;
my @p_var = map {
( my $x = $_ ) =~ s/=?</='/; "$x'"
} $text =~ /(p_var\d+=?<[^>]*)>/g;
print for @p_var;
I'm not clear what the problem was with your original solution John: it's
exactly what I wrote. Except, of course, that we haven't been told that the
value names are always formed in the same way and in sequence. To fix that,
surely just
foreach ($line =~ /\w+=?<[^>]*>/g) {
s/=?</='/;
s/>/'/;
print "$_\n";
}
fits the bill?
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>