Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The caller line gets the name of the package and file that called the use rlib. If you use caller with no arguments then it tells you about the sub it is called from, but in this case the argument tells it to go one higher in the call stack. See the docs for caller for more details.

The second line is simply setting default arguments using the ternary operator. If the arguments array @_ is empty then it will add ../lib and lib to @INC, otherwise it will work with the passed arguments.

The while loop is for cases where use rlib is called from a package like Some::Package::PP. In that case it will try to find the ancestral lib dir. It assumes caller(1) will return a file name something like /somepath/lib/Some/Package/ The =~ /::/g will return an array of how many times the package name includes ::, and will go up that many directories to find /somepath/lib/Some. This means it will eventually add /somepath/lib/Some/../lib and /somepath/lib/Some/lib to @INC (I might be off by one on the dirs, as I have not tested, but the principle is the same).

To test the while line:

# on windows - update quotes as needed perl -E"my $x = q|Some::Package::PP|; say 1 while $x =~ /::/g" #produces 1 1

In reply to Re^3: [implementation specific to windows] writing a proper batch file for terminal start-up by swl
in thread [implementation specific to windows] writing a proper batch file for terminal start-up by Aldebaran

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (4)
    As of 2020-10-24 03:22 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (242 votes). Check out past polls.