in reply to Re: Get Parent Directory
in thread Get Parent Directory

Hello, My requirement is to split the path into two strings from a given string. given string pattern : \default\main\(.*)\Tutorials\internet. Here the split delimiter will be "(.*)" and this will not be a part of any of the split strings. The first split string will contain all characters before the delimiter while the second string needs to hold all characters appearing after the delimitor viz., $string1="\default\main\"; $string2="\Tutorials\internet"; Hope the above info will clarify as to what i am tryiing. Thanks in advance. Anandatirtha

Replies are listed 'Best First'.
Re: Get Parent Directory : redefined
by BrowserUk (Patriarch) on Oct 22, 2002 at 12:42 UTC

    If I understand you, this may be what you are wanting.

    #! perl use warnings; # Always use this, it will help you enormously. use strict; # And this also. use diagnostics; # This gives some very useful hints when you are +developing. #I assume that this will come from somewhere else. my $path = "\\default\\main\\Anand\\toipcs\\Tutorials\\internet"; # And that you know this or know how to find it out (hint: use Cwd; is + one way). my $CurDir = 'Anand'; # And that what you want its find the parts before and after the curre +nt directory in the path my ($Pdir, $Sdir) = $path =~ m!(.+)Anand\\toipcs(.+)!; print "Pdir = '$Pdir' and Sdir = '$Sdir'\n";

    When the above program is run, it produces the following output.

    c:\test>207011 Pdir = '\default\main\' and Sdir = '\Tutorials\internet' c:\test>

    I hope this helps, if not or if I can clarify anything for you, ask away :).


    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!
      Hello BrowserUK, Thanks for the clarificationa and the code . It's perfectly what i wanted. Greetings!!!! Anandatirtha