This may help you understand what the code trying to do.

# Set the path variable. $path = "\\default\\main\\Anand\\toipcs\\Tutorials\\internet"; # Make a copy of it $curPath = $path; # Extract (what I assume to be) your user/home directory ("Anand"). # However this line won't work because the substitution operator is m +issing the 's' $curPath =~ !\default\main\(.*)\Tutorials\internet!$1!; # ^ There should be an 's' here # Make a copy of the extracted directory name ("Anand") and print it +out $parentdir = $curPath; print "parent Directory : $curPath\n"; # This line doesn't doesn't make any sense at all??. # It's obviously trying to extract 2 different parts of the path fro +om something # But # a) The is no variable to operate on! It would need to look somethi +ng like: # ($Pdir, $Sdir) = $path =~ m!(.*)\\(.*)!; !!!NOTE the double +d backslash (\\)! # b) Quite what the intent of the '$1,$2' at the end was meant to d +o. ($Pdir,$Sdir) =~ m!(.*)\(.*)$!$1,$2; # Nothing will be printed as the line above did nothing! print "parent branch : $Pdir \t sub branch $Sdir";

However, I think you need to try and explain what it is that you want the code to do, then it may be possible to help you further.


Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

In reply to Re: Get Parent Directory by BrowserUk
in thread Get Parent Directory by Ananda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.