Split strings

Split strings

am 24.08.2007 10:29:17 von chinmoy.chittaranjan

Hi All ,

I am ver new to perl and trying to take out the last word
from a string.Like that -.E:\user\chinmoy\bsp ->
here i am trying to take out "bsp" word only from this string but i
was unable to do that . I will be appreciated if someone help me on
this matter.


Thanks
Chinmoy

Re: Split strings

am 24.08.2007 11:23:56 von anno4000

wrote in comp.lang.perl.misc:
> Hi All ,
>
> I am ver new to perl and trying to take out the last word
> from a string.Like that -.E:\user\chinmoy\bsp ->
> here i am trying to take out "bsp" word only from this string but i
> was unable to do that . I will be appreciated if someone help me on
> this matter.

To answer your question conclusively a single example isn't sufficient.
You'd have to describe the variability of the input. The way you put
the problem, one could rightly answer "$last_word = 'bsp'", because
that is the only case given. Here is one possibility:

my $last_word = ( /\w+/g)[ -1];

Anno

Re: Split strings

am 24.08.2007 11:56:41 von Dan Otterburn

On 24 Aug, 09:29, chinmoy.chittaran...@gmail.com wrote:

> E:\user\chinmoy\bsp

That looks like a Windows file path. If you are trying to parse file
paths you might want to look at File::Basename core module.

Re: Split strings

am 24.08.2007 20:59:10 von chinmoy.chittaranjan

On Aug 24, 2:56 am, Dan Otterburn wrote:
> On 24 Aug, 09:29, chinmoy.chittaran...@gmail.com wrote:
>
> > E:\user\chinmoy\bsp
>
> That looks like a Windows file path. If you are trying to parse file
> paths you might want to look at File::Basename core module.

Some path is there . So actually i am trying to get the last word from
this path .like from that full string path only bsp word i want .

Re: Split strings

am 25.08.2007 00:30:07 von rvtol+news

chinmoy.chittaranjan@gmail.com schreef:
> Dan Otterburn:
>> chinmoy:

>>> E:\user\chinmoy\bsp
>>
>> That looks like a Windows file path. If you are trying to parse file
>> paths you might want to look at File::Basename core module.
>
> Some path is there . So actually i am trying to get the last word from
> this path .like from that full string path only bsp word i want .

Why do you keep calling it a "word"? What if the filename is
"C:\Program Files\Acme\READ ME FIRST!!!.txt"?

Use a module, like the already mentioned File::Basename.

--
Affijn, Ruud

"Gewoon is een tijger."