The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 05-14-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,609
And $arr[-1] is the last element of @arr, no matter how many elements you ended up with. You could also use a regex match:

Code:
$str =~ m%([^/]*)$%;  print $1
This searches for characters adjacent to end of line ($) which are not slashes [^/] -- the * wildcard will match as many as possible.
Reply With Quote