> I want to extract some word after space from some string.
> Somebody from the mailing list had given me above
> command.
> [snip]
> 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.  It is
> a newbie question actually.
|
| try 
| $abc = ( split /\s+/ )[8];
| 
| you can use the parenth with any function that returns an
| array, and just pop a [] on the end.
| 

Fine, although not the fastest solution.  Slightly better
is:

$abc = (split /\s+/, $_, 9)[8];

which stops it trying to split after the eighth field.

> FYI if you want the last element (not knowing what place
> it's in) just use [$#_].

No, don't bother.  You really want a regex for this
situation:

$abc = /([^\S]*)$/;  

if you really, really wanted to use split:

$abc = (split /\s+/)[-1];

Jonathan Paton

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to