Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Get Parent Directory

by alfie (Pilgrim)
on Oct 22, 2002 at 10:38 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found