in reply to Get Parent Directory
Your parsing errors result due to different things:
--
use signature; signature(" So long\nAlfie");
- 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.
HTH & HAND,# 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";
--
use signature; signature(" So long\nAlfie");
In Section
Seekers of Perl Wisdom