From tigerpeng2001 at yahoo.com Thu Oct 22 12:05:17 2009 From: tigerpeng2001 at yahoo.com (tiger peng) Date: Thu, 22 Oct 2009 12:05:17 -0700 (PDT) Subject: [PerlChina] split function and zero-width seperator Message-ID: <106663.60683.qm@web58703.mail.re1.yahoo.com> Hello everyone,   I am trying to isolate numbers from string, manipulate the numbers then put them back to original positions in the string. When I try to use zero-width separator, the split function looks weird, it generated much more elements than I expect.   Are there any mistakes? Why the split behaviors like this? (The regexp looks right when I used it s///)   Could anyone help?   Thanks, Tiger #build the seperator :-) perl -le '$a = "15678.91 ml; r45.12 ";               $a =~ s/((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(? From cnhacktnt at gmail.com Thu Oct 22 17:57:37 2009 From: cnhacktnt at gmail.com (cnhack TNT) Date: Fri, 23 Oct 2009 08:57:37 +0800 Subject: [PerlChina] split function and zero-width seperator In-Reply-To: <106663.60683.qm@web58703.mail.re1.yahoo.com> References: <106663.60683.qm@web58703.mail.re1.yahoo.com> Message-ID: perl -MData::Dumper -le '$a="15678.91 ml; r45.12 "; @a=grep !/^\s*$/, split /([\d\.]+)/, $a; print Dumper \@a' the regex pattern for split don't need to be that complicated. :-) 2009/10/23 tiger peng > Hello everyone, > > I am trying to isolate numbers from string, manipulate the numbers then put > them back to original positions in the string. When I try to use zero-width > separator, the split function looks weird, it generated much more elements > than I expect. > > Are there any mistakes? Why the split behaviors like this? (The > regexp looks right when I used it s///) > > Could anyone help? > > Thanks, > Tiger > > #build the seperator > :-) perl -le '$a = "15678.91 ml; r45.12 "; > $a =~ > s/((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(? print $a' > |15678.91| ml; r|45.12| > > #use the seperator in split > :-) perl -MData::Dumper -le '$a = "15678.91 ml; r45.12 "; > @a = split > /((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(? print Dumper(@a)' > $VAR1 = '15678.91'; > $VAR2 = ''; > $VAR3 = undef; > $VAR4 = '1'; > $VAR5 = undef; > $VAR6 = undef; > $VAR7 = undef; > $VAR8 = ' ml; r'; > $VAR9 = undef; > $VAR10 = undef; > $VAR11 = undef; > $VAR12 = ''; > $VAR13 = '4'; > $VAR14 = undef; > $VAR15 = '45.12'; > $VAR16 = ''; > $VAR17 = undef; > $VAR18 = '2'; > $VAR19 = undef; > $VAR20 = undef; > $VAR21 = undef; > $VAR22 = ' '; > > _______________________________________________ > China-pm mailing list > China-pm at pm.org > http://mail.pm.org/mailman/listinfo/china-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tigerpeng2001 at yahoo.com Thu Oct 22 19:59:15 2009 From: tigerpeng2001 at yahoo.com (tiger peng) Date: Thu, 22 Oct 2009 19:59:15 -0700 (PDT) Subject: [PerlChina] split function and zero-width seperator In-Reply-To: References: <106663.60683.qm@web58703.mail.re1.yahoo.com> Message-ID: <477610.3962.qm@web58702.mail.re1.yahoo.com> Thank. I thought the seperator would lost. I just read perldoc -f split, which says, "If the PATTERN contains parentheses, additional list elements are created from each matching substring in the delimiter." ________________________________ From: cnhack TNT To: china-pm at pm.org Sent: Thu, October 22, 2009 7:57:37 PM Subject: Re: [PerlChina] split function and zero-width seperator perl -MData::Dumper -le '$a="15678.91 ml; r45.12 "; @a=grep !/^\s*$/, split /([\d\.]+)/, $a; print Dumper  \@a' the regex pattern for split don't need to be that complicated. :-) 2009/10/23 tiger peng Hello everyone, >  >I am trying to isolate numbers from string, manipulate the numbers then put them back to original positions in the string. When I try to use zero-width separator, the split function looks weird, it generated much more elements than I expect. >  >Are there any mistakes? Why the split behaviors like this? (The regexp looks right when I used it s///) >  >Could anyone help? >  >Thanks, >Tiger > >#build the seperator >:-) perl -le '$a = "15678.91 ml; r45.12 "; >              $a =~ s/((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(?              print $a' >|15678.91| ml; r|45.12| > >#use the seperator in split >:-) perl -MData::Dumper -le '$a = "15678.91 ml; r45.12 "; >                             @a = split /((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(?                             print Dumper(@a)' >$VAR1 = '15678.91'; >$VAR2 = ''; >$VAR3 = undef; >$VAR4 = '1'; >$VAR5 = undef; >$VAR6 = undef; >$VAR7 = undef; >$VAR8 = ' ml; r'; >$VAR9 = undef; >$VAR10 = undef; >$VAR11 = undef; >$VAR12 = ''; >$VAR13 = '4'; >$VAR14 = undef; >$VAR15 = '45.12'; >$VAR16 = ''; >$VAR17 = undef; >$VAR18 = '2'; >$VAR19 = undef; >$VAR20 = undef; >$VAR21 = undef; >$VAR22 = ' '; > >_______________________________________________ >China-pm mailing list >China-pm at pm.org >http://mail.pm.org/mailman/listinfo/china-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tigerpeng2001 at yahoo.com Thu Oct 22 20:23:35 2009 From: tigerpeng2001 at yahoo.com (tiger peng) Date: Thu, 22 Oct 2009 20:23:35 -0700 (PDT) Subject: [PerlChina] split function and zero-width seperator In-Reply-To: <477610.3962.qm@web58702.mail.re1.yahoo.com> References: <106663.60683.qm@web58703.mail.re1.yahoo.com> <477610.3962.qm@web58702.mail.re1.yahoo.com> Message-ID: <891811.22734.qm@web58705.mail.re1.yahoo.com> Here is what I want:   :-) perl -MData::Dumper -MRegexp::Common -le '$a="15678.91 ml; .121 0.12312  > $VAR1 = [           '15678.91',           ' ml; ',           '.121',           ' ',           '0.12312',           '  ',           '12313.',           ' r',           '45.12',           ' '         ]; ________________________________ From: tiger peng To: china-pm at pm.org Sent: Thu, October 22, 2009 9:59:15 PM Subject: Re: [PerlChina] split function and zero-width seperator Thank. I thought the seperator would lost. I just read perldoc -f split, which says, "If the PATTERN contains parentheses, additional list elements are created from each matching substring in the delimiter." ________________________________ From: cnhack TNT To: china-pm at pm.org Sent: Thu, October 22, 2009 7:57:37 PM Subject: Re: [PerlChina] split function and zero-width seperator perl -MData::Dumper -le '$a="15678.91 ml; r45.12 "; @a=grep !/^\s*$/, split /([\d\.]+)/, $a; print Dumper  \@a' the regex pattern for split don't need to be that complicated. :-) 2009/10/23 tiger peng Hello everyone, >  >I am trying to isolate numbers from string, manipulate the numbers then put them back to original positions in the string. When I try to use zero-width separator, the split function looks weird, it generated much more elements than I expect. >  >Are there any mistakes? Why the split behaviors like this? (The regexp looks right when I used it s///) >  >Could anyone help? >  >Thanks, >Tiger > >#build the seperator >:-) perl -le '$a = "15678.91 ml; r45.12 "; >              $a =~ s/((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(?              print $a' >|15678.91| ml; r|45.12| > >#use the seperator in split >:-) perl -MData::Dumper -le '$a = "15678.91 ml; r45.12 "; >                             @a = split /((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(?                             print Dumper(@a)' >$VAR1 = '15678.91'; >$VAR2 = ''; >$VAR3 = undef; >$VAR4 = '1'; >$VAR5 = undef; >$VAR6 = undef; >$VAR7 = undef; >$VAR8 = ' ml; r'; >$VAR9 = undef; >$VAR10 = undef; >$VAR11 = undef; >$VAR12 = ''; >$VAR13 = '4'; >$VAR14 = undef; >$VAR15 = '45.12'; >$VAR16 = ''; >$VAR17 = undef; >$VAR18 = '2'; >$VAR19 = undef; >$VAR20 = undef; >$VAR21 = undef; >$VAR22 = ' '; > >_______________________________________________ >China-pm mailing list >China-pm at pm.org >http://mail.pm.org/mailman/listinfo/china-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cnhacktnt at gmail.com Thu Oct 22 22:44:12 2009 From: cnhacktnt at gmail.com (cnhack TNT) Date: Fri, 23 Oct 2009 13:44:12 +0800 Subject: [PerlChina] split function and zero-width seperator In-Reply-To: <891811.22734.qm@web58705.mail.re1.yahoo.com> References: <106663.60683.qm@web58703.mail.re1.yahoo.com> <477610.3962.qm@web58702.mail.re1.yahoo.com> <891811.22734.qm@web58705.mail.re1.yahoo.com> Message-ID: Just remove the "grep !/^\s*$/," statement will give you what you want. :-) 2009/10/23 tiger peng > Here is what I want: > > :-) perl -MData::Dumper -MRegexp::Common -le '$a="15678.91 ml; .121 > 0.12312 > > $VAR1 = [ > '15678.91', > ' ml; ', > '.121', > ' ', > '0.12312', > ' ', > '12313.', > ' r', > '45.12', > ' ' > ]; > > > > ------------------------------ > *From:* tiger peng > *To:* china-pm at pm.org > *Sent:* Thu, October 22, 2009 9:59:15 PM > > *Subject:* Re: [PerlChina] split function and zero-width seperator > > Thank. I thought the seperator would lost. I just read perldoc -f split, > which says, "If the PATTERN contains parentheses, additional list elements > are created from each matching substring in the delimiter." > > ------------------------------ > *From:* cnhack TNT > *To:* china-pm at pm.org > *Sent:* Thu, October 22, 2009 7:57:37 PM > *Subject:* Re: [PerlChina] split function and zero-width seperator > > perl -MData::Dumper -le '$a="15678.91 ml; r45.12 "; @a=grep !/^\s*$/, split > /([\d\.]+)/, $a; print Dumper \@a' > > the regex pattern for split don't need to be that complicated. :-) > > > > 2009/10/23 tiger peng > >> Hello everyone, >> >> I am trying to isolate numbers from string, manipulate the numbers then >> put them back to original positions in the string. When I try to use >> zero-width separator, the split function looks weird, it generated much more >> elements than I expect. >> >> Are there any mistakes? Why the split behaviors like this? (The >> regexp looks right when I used it s///) >> >> Could anyone help? >> >> Thanks, >> Tiger >> >> #build the seperator >> :-) perl -le '$a = "15678.91 ml; r45.12 "; >> $a =~ >> s/((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(?> print $a' >> |15678.91| ml; r|45.12| >> >> #use the seperator in split >> :-) perl -MData::Dumper -le '$a = "15678.91 ml; r45.12 "; >> @a = split >> /((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(?> print Dumper(@a)' >> $VAR1 = '15678.91'; >> $VAR2 = ''; >> $VAR3 = undef; >> $VAR4 = '1'; >> $VAR5 = undef; >> $VAR6 = undef; >> $VAR7 = undef; >> $VAR8 = ' ml; r'; >> $VAR9 = undef; >> $VAR10 = undef; >> $VAR11 = undef; >> $VAR12 = ''; >> $VAR13 = '4'; >> $VAR14 = undef; >> $VAR15 = '45.12'; >> $VAR16 = ''; >> $VAR17 = undef; >> $VAR18 = '2'; >> $VAR19 = undef; >> $VAR20 = undef; >> $VAR21 = undef; >> $VAR22 = ' '; >> >> _______________________________________________ >> China-pm mailing list >> China-pm at pm.org >> http://mail.pm.org/mailman/listinfo/china-pm >> > > > _______________________________________________ > China-pm mailing list > China-pm at pm.org > http://mail.pm.org/mailman/listinfo/china-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: