Split strings

  • Thread starter chinmoy.chittaranjan
  • Start date
C

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
 
A

anno4000

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
 
D

Dan Otterburn

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.
 
C

chinmoy.chittaranjan

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 .
 
D

Dr.Ruud

(e-mail address removed) schreef:
Dan Otterburn:

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top