Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

perlrc for perl programs

by targetsmart (Curate)
on Feb 06, 2009 at 17:01 UTC ( [id://741957]=perlquestion: print w/replies, xml ) Need Help??

targetsmart has asked for the wisdom of the Perl Monks concerning the following question:

I just wanted to know whether it is possible to set up hooks for every program that I do.

for eg, I am using Data::Dumper,strict, warnings, diagnostics, log::agent::logxxx routines, etc., in most of my everyday programs(from small to large), it is possible to ask perl to include these modules/pragmas from a configuration file like perlrc(eg, bashrc for bash), or is there any other way of mimicking this configuration file feature(parser, compiler... setting up some hooks in those modules).
I know that if too much of routines included this way; it will pollute the program namespace, but I believe that I can carefully use it.

Right now I am using perl-support vim plugin for this purpose; as and when I create the file, these 'use' lines will be added automatically based on some predefined templates.( but I want to be more perl-ish)
UPDATE
You could put your desired items in a perl module and then use -M command line option to include them. This would be explicit. It sounds like you're looking for something that's implicit?
Yes I am looking for something implict.

Any idea is greatly appreciated.


Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.

Replies are listed 'Best First'.
Re: perlrc for perl programs
by moritz (Cardinal) on Feb 06, 2009 at 17:07 UTC
Re: perlrc for perl programs
by osunderdog (Deacon) on Feb 06, 2009 at 17:23 UTC

    You could put your desired items in a perl module and then use -M command line option to include them. This would be explicit. It sounds like you're looking for something that's implicit?

    Example: mystuff.pm

    use strict; use Data::Dumper; use Scalar::Util; 1;

    test.pl

    print Scalar::Util::reftype("foo"); print Dumper("this is some raw text");

    invocation:

    ~/src/perl$ perl -Mmystuff test.pl $VAR1 = 'this is some raw text';

    Still looking... Still searching...

Re: perlrc for perl programs
by mr_mischief (Monsignor) on Feb 06, 2009 at 17:51 UTC
    You could have a shell script call perl for you with command-line arguments.

    On most Unix-alikes under Bourne or bash:

    #!/bin/sh /usr/local/bin/perl -MMyIncludes $@

    On Windows using Strawberry under cmd :

    @"\strawberry\perl\bin\perl" -MMyIncludes %*

    These of course assume fairly standard installation paths. You'll need to change those to match your system. You'd have a new way to call perl, but that way would implicitly include any module or modules you like. The remainder of any command-line arguments are passed on to perl itself in both cases.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://741957]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-23 06:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found