Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Get Parent Directory

by alfie (Pilgrim)
on Oct 22, 2002 at 10:38 UTC ( #207029=note: print w/replies, xml ) Need Help??


in reply to Get Parent Directory

Your parsing errors result due to different things:
  • You have to escape the \ in the regexp. \d has a special meaning (a digit) within a regexp, \t is a tab and so on, so you have to double the \ in your substitute, too.
  • You should not use .* at all. Please read Death to Dot Star! for more information on this. In here you like to replace it with [^\\]* to match everything except an \.
  • You were missing the s infront of the substitute you liked to do.
  • In your assignment to $Pdir and $Sdir you did forgot that you want to match $parentdir, and the $1,$2 at the end is, uhm, simply wrong.
Your code might look like this:
# I dislike having to escape everything when I can use '' instead $path = '\default\main\Anand\toipcs\Tutorials\internet'; $curPath = $path; $curPath =~ s!\\default\\main\\([^\\]*)\\Tutorials\\internet!$1!; $parentdir = $curPath; print "parent Directory : $curPath\n"; ($Pdir,$Sdir) = $parentdir =~ m!([^\\]*)\([^\\]*)$!; print "parent branch : $Pdir \t sub branch $Sdir";
HTH & HAND,
--
use signature; signature(" So long\nAlfie");

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://207029]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2022-01-24 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (64 votes). Check out past polls.

    Notices?