Buddyhelp has asked for the wisdom of the Perl Monks concerning the following question:
Can some one please tell me how to get the values after the third piping (|) symbol without the plus signs
This is what i have tried$data = '[-3|1|29x250+46+26|200+300+464|Get][-3|1|29x250+46+26|132+100 ++244|come][-3|1|29x250+46+26|220+124+432|Go][...][...]' I need the output as $val1 = 200 $val2 = 300 $val3 = 464 etc.,
I am getting the output asmy $data = '[-3|1|29x250+46+26|200+300+444|Get][-3|1|29x250+46+26|200+ +300+444|Get][-3|1|29x250+46+26|200+300+444|Get]'; my $REGEX_COLLECTION = '(\[.*?\])'; my $REGEX_TEXT_RESPONSE = '\[(.*?)\|(.*?)\|(\d+)x(\d+)\+(\d+)\+(\d+)\| +(\d+)\+(\d+)\+(\d+)|(.*?)\]'; my @splits = split( $REGEX_COLLECTION, $data ); foreach (@splits) { print "The split value is $_ \n"; if ( $_ =~ m/$REGEX_TEXT_RESPONSE/g ) { print "The first split is $1 \n"; print "The second split is $2 \n"; print "The tird split is $3 \n"; print "The fourth split is $4 \n"; print "The fifth split is $5 \n"; print "The sixth split is $6 \n"; print "The seven split is $7 \n"; print "The eight split is $8 \n"; print "The nine split is $9 \n"; print "The tenth split is $10 \n" } }
The split value is The split value is [-3|1|29x250+46+26|200+300+444|Get] The first split is -3 The second split is 1 The tird split is 29 The fourth split is 250 The fifth split is 46 The sixth split is 26 The seven split is 200 The eight split is 300 The nine split is 444 The tenth split is The split value is The split value is [-3|1|29x250+46+26|200+300+444|Get] The first split is -3 The second split is 1 The tird split is 29 The fourth split is 250 The fifth split is 46 The sixth split is 26 The seven split is 200 The eight split is 300 The nine split is 444 The tenth split is The split value is The split value is [-3|1|29x250+46+26|200+300+444|Get] The first split is -3 The second split is 1 The tird split is 29 The fourth split is 250 The fifth split is 46 The sixth split is 26 The seven split is 200 The eight split is 300 The nine split is 444 The tenth split is
I am not getting the values of Get. Is there another way to do this. Is this the best way. Please suggest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Regex
by hdb (Monsignor) on Oct 10, 2013 at 11:04 UTC | |
by smls (Friar) on Oct 10, 2013 at 11:41 UTC | |
by Buddyhelp (Initiate) on Oct 10, 2013 at 11:21 UTC | |
by Corion (Patriarch) on Oct 10, 2013 at 11:27 UTC | |
by Buddyhelp (Initiate) on Oct 10, 2013 at 11:43 UTC | |
by hdb (Monsignor) on Oct 10, 2013 at 11:43 UTC | |
by Buddyhelp (Initiate) on Oct 10, 2013 at 11:51 UTC | |
|
Re: Perl Regex
by smls (Friar) on Oct 10, 2013 at 11:35 UTC | |
|
Re: Perl Regex
by smls (Friar) on Oct 10, 2013 at 12:39 UTC | |
|
Re: Perl Regex
by AlexTape (Monk) on Oct 10, 2013 at 11:41 UTC | |
|
Re: Perl Regex
by kcott (Archbishop) on Oct 11, 2013 at 02:40 UTC | |
|
Re: Perl Regex
by Lennotoecom (Pilgrim) on Oct 10, 2013 at 23:49 UTC |