Hi Michael,


Michael Alipio wrote:
I have a string that looks like this:

my $string = "1, 3, 0. 0. 0. 0, 22, Zak',adfk $&! mac., ";


Basically, there are seven fields. after the bird, everything up to the last 
comma is the 5th field. 6th field is blank.

Now my problem is splitting it and extracting the 5th field.

If I will do a (split/,/,$string)[-2]) then i will only get "adfk $&! mac."
I need to get the entire "Zak' , adfk $&! mac."


I doubt this is the best way, but I would use both split and a regular expression. The first split, I would specify there are only five fields so that the 5th, 6th, and 7th fields ends up in the "remainder" of split (split with three arguments). Then I would use a regular expression on these three fields and pull out the last two.

I suppose a human looking at the line would do something similar (remove the fields known not to have commas first and what's left is the 5th). If two fields can have commas...then I'm not sure what to do. :-)

Ray



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to