in reply to help on reg ex

I'm assuming your second example of $a is a typo and should have read $a = '/export/home/test'. If you want to chop out great specifically, you can do:
$a =~ s/\/great$//;
If you want to generically remove the last element, and save it to $bar, you can do:
$a =~ s/(\/.*)$//; $bar = $1;
I hope this helps.

Replies are listed 'Best First'.
(z) Re^2: help on reg ex
by zigdon (Deacon) on May 07, 2003 at 16:23 UTC
    Your example: would put in $bar everything starting from the first slash. You should instead do:
    $a =~ s#(/[^/]*)$##; $bar = $1;

    -- zigdon

      Oops, you're right. My bad -- I don't know what I was thinking :) You provide a good example to the user of a case where it's a good idea to use a nonstandard regex delimiter, BTW. Cool.