my $short = (split /\//, $Server->File())[$#]

C

cate

Is it possible to do something like that? I can make it work with in
index number. I can make it work with the last array index.

my $short = (split /\//, $Server->File())[$#]

Thank you.
 
X

Xho Jingleheimerschmidt

cate said:
Is it possible to do something like that? I can make it work with in
index number.

Ah, so then what is the problem/question? Why not use the solution that
works if it works?

my $short = (split /\//, $Server->File())[-1]
I can make it work with the last array index.

my $short = (split /\//, $Server->File())[$#]

You can? That certainly surprises me.

Xho
 
C

cate

cate said:
Is it possible to do something like that?  I can make it work with in
index number.

Ah, so then what is the problem/question?  Why not use the solution that
works if it works?

my $short =  (split /\//, $Server->File())[-1]
I can make it work with the last array index.
   my $short =  (split /\//, $Server->File())[$#]

You can?  That certainly surprises me.

Xho

thanks.... typo... only in the borros world thanks again
 
D

Dr.Ruud

cate said:
my $short = (split /\//, $Server->File())[$#]

my ($short) = $Server->File() =~ m~(?:.*/)?(.*)~;

my ($short) = $Server->File() =~ m~([^/]*)$~;

File::Basename
 
W

Wanna-Be Sys Admin

cate said:
Is it possible to do something like that? I can make it work with in
index number. I can make it work with the last array index.

my $short = (split /\//, $Server->File())[$#]

Sure you can do it, but not with $Server->File(), since it's not an
array. Of course, you can build an array by using / as a delimiter and
then split, but that would be doing double the work when you can
determine the last element by split in the first place, or by using a
regex instead.
 
S

sln

Is it possible to do something like that? I can make it work with in
index number. I can make it work with the last array index.

my $short = (split /\//, $Server->File())[$#]

Thank you.

Not really a good way to do it.
Untested.

$short = (reverse split(/\//, $Server->File) )[0] || 'empty';

or

$short = (@_= split /\//, $Server->File )[$#_] || 'empty';

-sln
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top