当某些值包含=时,如何将字段和值拆分=?

时间:2010-11-19 17:29:01

标签: perl

  

可能重复:
  converting multline string to array

    my $text = "a=10|b=20|c=20|d=\' I am multing line string  A=10
dfasd fas
d
as df
asd
f a
sd
fas
d fsd \'|e=10"

 foreach my $pairing (split(/\|/,$text)) {
        print "$pairing ";
        my ($field,$value)=split(/=/,$pairing);
         print "**$field,$value**";
        }


its not printing  a= 10 , b=20 , c=20 , and 
d=I am multing line string  A=10 dfasd fas
    d
    as df
    asd
    f a
    sd
    fas
    d fsd , e =10 ?

1 个答案:

答案 0 :(得分:2)

指定第二个split的限制:

#!/usr/bin/perl

use strict; use warnings;

my $text = "a=10|b=20|c=20|d=\' I am multing line string  A=10
dfasd fas
d
as df
asd
f a
sd
fas
d fsd \'|e=10";

foreach my $pairing (split qr{\|}, $text) {
    my ($field, $value) = split /=/, $pairing, 2;
    print "**$field,$value**\n";
}