http://www.perlmonks.org?node_id=150166


in reply to remove the part of the string that is after the second to last '/'

Or the non cool way! Regular expression are for weenies! :)
$var = "one/two/three/four/five/six/"; split /\//, $var; pop; $var = $var . $_ foreach(@_);
  • Comment on Re: remove the part of the string that is after the second to last '/'
  • Download Code

Replies are listed 'Best First'.
Re: Re: remove the part of the string that is after the second to last '/'
by Juerd (Abbot) on Mar 08, 2002 at 09:10 UTC
    You weenie! You used a regular expression! :)

    I think I like this way of avoiding regexes better:
    substr($var, rindex($var, '/', length($var) - 2)) = '';

    ++ vs lbh qrpbqrq guvf hfvat n ge va Crey :)
    Nabgure bar vs lbh qvq fb jvgubhg ernqvat n znahny svefg.
    -- vs lbh hfrq OFQ pnrfne ;)
        - Whreq