Front page | perl.beginners |
Postings from January 2002
Re: split and extraction
Thread Previous
From:
John W. Krahn
Date:
January 30, 2002 07:48
Subject:
Re: split and extraction
Message ID:
3C5815BD.CAF9D766@acm.org
Dhiraj P Nilange wrote:
>
> Hi there
Hello,
> I want to extract some word after space from some string.
> Somebody from the mailing list had given me above
> command.
>
> suppose I wanto extract 8th word...
Perl arrays are indexed starting at zero (0) so the eighth word in an
array would be index seven (7).
> #suppose $abc has the string;
> $abc=split[/\s+/]->[8]; #somebody told me like this.
>
> but it doesnt work. if i use some array in the split function like:-
>
> @array=split(/\s+/,$abc);
> print $array[8];
>
> this way it works. But I dont want to use array. Its newbie question actually.
my $eighth_word = (split ' ', $abc)[7];
split() with a single space character instead of a regular expression is
a special form of split (explained in perlfunc.)
John
--
use Perl;
program
fulfillment
Thread Previous