Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Regular Expression Help

by pg (Canon)
on Nov 18, 2005 at 20:16 UTC ( #509937=note: print w/replies, xml ) Need Help??


in reply to Regular Expression Help

Or utilize rindex: (this code works regarless whether there is a trailing /)

use strict; use warnings; { my $str = "/rootdir/sub1/sub2/sub3/sub4/"; print substr($str, 0, rindex($str, "/", length($str) - 2)); } print "\n"; { my $str = "/rootdir/sub1/sub2/sub3/sub4"; print substr($str, 0, rindex($str, "/", length($str) - 2)); }

which prints:

/rootdir/sub1/sub2/sub3 /rootdir/sub1/sub2/sub3

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://509937]
help
Chatterbox?
[Corion]: Oooh - what a nice idea - QoS throttling on AWS, test enviroment runs fast, production also, until it doesn't
[Corion]: But then, you can just pay to make it fast again. Be a shame if it were to slow down, wouldn't it?

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2017-07-26 18:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (400 votes). Check out past polls.