Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
If you have your code set up as a standard directory structure, e.g. with the script in ./bin and any modules under ./lib, then you can use libraries like rlib to add the relative paths in your calling script.

Ok, this is helpful and worth exploring. I must say, however, that I'm unable to follow what rlib is doing. Let's look at the source:

package rlib; use strict; use vars qw($VERSION @ISA); use lib (); use File::Basename qw(dirname); use File::Spec; $VERSION = "0.02"; @ISA = qw(lib); sub _dirs { my($pkg,$file) = (caller(1))[0,1]; my @rel = @_ ? @_ : qw(../lib lib); my $dir; # if called from package main then assume we were called # by a script not a module if($pkg eq 'main') { require FindBin; # hide "used only once" warning $dir = ($FindBin::Bin,$FindBin::Bin)[0]; } else { require Cwd; $dir = Cwd::abs_path(dirname($file)); } # If we were called by a package then traverse upwards # to root of lib while($pkg =~ /::/g) { $dir = dirname($dir); } if($^O eq 'VMS') { require VMS::Filespec; @rel = map { VMS::Filespec::unixify($_) } @rel; } map { File::Spec->catdir($dir,$_) } @rel; } sub import { shift->SUPER::import( _dirs(@_) ); } sub unimport { shift->SUPER::unimport( _dirs(@_) ); } 1; __END__

I fail to see how _dirs is populated. Can someone talk through how this works? In particular, I do not understand the syntax of the following lines:

my($pkg,$file) = (caller(1))[0,1]; my @rel = @_ ? @_ : qw(../lib lib);

and

while($pkg =~ /::/g) {

How might I test this? Thx for your comments,


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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-24 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found