>file name. When I run this code, the full path is printed. Do I have to use
>split or something and get the name myself? I've been reading the
MacPerl >and do not see an example of this.
This would be one way of doing it:
foreach $filename (@ARGV) {
my @array = split (/:/, $filename);
@array = reverse @array; print "$array[0]\n";
}
We throw all of the split() into an array because we can't ever assume how
many levels deep we are in the users filesystem. We then reverse the array
to get the final element (note, there are a number of ways to get the last
element of an array. I use the above because it's more readable / semantic
to a human). The following are other options:
my $val = $array[$#array];
my $val = $array[-1];
You can also do the "get filename" via a regexp, but that gets a little
hairier and isn't as pretty of a code. Finally, I used the ":" inside the
split() above, but if you're going to look into cross platform
possibilities, you probably want to find out the delimiter very early in
your script, and then use $delimiter for the rest.
--
Morbus Iff ( .sig on other machine. )
http://www.disobey.com/ && http://www.gamegrene.com/
"where's there's a will, there's a morbus ready to collect!"