Michael Alipio <[email protected]> asked:
> 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."
Obviously you can't expect split to guess which comma is part of a field and
which is a record separator.
Without more information I'd say that you've chosen the wrong separator to
split on - instead just a comma, it should be a comma and whitespace. That in
turn means that there are only
#!/usr/bin/perl -w
use strict;
my $string = q(1, 3, 0. 0. 0. 0, 22, Zak',adfk $&! mac., );
my $i = 0;
foreach ( split /,\s+/, $string ){
print "$i: >$_<\n";
$i++;
}
__END__
HTH,
Thomas
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/