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

HI Monks,

My first post.Wish you all.

I want to print the contents of @INC from the Shell,is it possible?
Do we always need a .pl file?
If type 'perl' in the shell, the cursor moves to a new line and receives my input, but the commands I enter there are not executing.I use CONTROL+C to return back to shell.

Replies highly appreciated.....Spread the AROMA!!!
  • Comment on printing @INC contents and Command line interpretation

Replies are listed 'Best First'.
Re: printing @INC contents and Command line interpretation
by FunkyMonk (Bishop) on Aug 07, 2007 at 12:06 UTC
    I want to print the contents of @INC from the Shell,is it possible?
    Yes, easily:

    perl -e "print \"@INC\""

    This will work on *nix & Windows. On *nix you don't need to juggle with quotes as much.

    Do we always need a .pl file?
    No. See the above example

    If type 'perl' in the shell, the cursor moves to a new line and receives my input, but the commands I enter there are not executing.I use CONTROL+C to return back to shell.
    Use Control-D on Unix variants or Control-Z on Windows

    Have a look at PerlMonks FAQ and The Perl Monks Guide to the Monastery for more information on how the Monastery works. Voting/Experience System is essential reading if you intend to be here for some time. Finally, don't forget there's hundreds of thousands of posts here, Super Search is your friend.

    Finally, welcome to the Monastery. I hope you enjoy your stay.

    update: added pointers to FAQs

      Hi,

      Welcome to the monastery. When you get a chance, please go through How (Not) To Ask A Question also :)

      Cheers !

      --VC



      There are three sides to any argument.....
      your side, my side and the right side.

Re: printing @INC contents and Command line interpretation
by citromatik (Curate) on Aug 07, 2007 at 12:11 UTC

    You got some possibilities from the CB (from shmem, graq and me)

    $ perl -le 'print for @INC' $ perl -e 'print "$_\n" for @INC' $ perl -e 'print join"\n",@INC' $ perl -e'$"="\n"; print"@INC\n"'

    All of them prints the contents of @INC from the command line

    citromatik

      I tend to favor the join myself for one-liners like that, but I always include an empty item after @INC so the last line will get a newline on it.
      perl -e 'print join "\n", @INC, ""'
      The variant that uses "for @INC" avoids that question; perhaps I may need to make a style change. I wonder how they compare for performance, when run in a tight loop?
      push @things_to_do, performance_test( $foreach, $join );
Re: printing @INC contents and Command line interpretation
by chakram88 (Pilgrim) on Aug 07, 2007 at 14:04 UTC

    What you're interested in is command line processing -- notice the '-e' switch all the users here supplied to the perl command. think of it as 'execute'.

    You'll find the information you need in perldoc perlrun in the Command Switches section.

    A bit of document searching that is often suggested here, and I've found quite useful is 'perldoc -q FAQRegex' -- where FAQRegex is, a, well, regex.

Re: printing @INC contents and Command line interpretation
by thezip (Vicar) on Aug 07, 2007 at 16:22 UTC

    Also , if you don't mind the noise, you can view many of the particulars of your Perl installation (including the contents of @INC) if you enter perl -V on the command line.


    Where do you want *them* to go today?
Re: printing @INC contents and Command line interpretation
by agianni (Hermit) on Aug 07, 2007 at 15:12 UTC
    This is probably overkill, but if you have the Data::Dumper module installed, you can get a nicely formatted output of the contents of @INC from the command line thusly: perl -MData::Dumper -e "print Dumper \@INC" the -M option (mnemonic: module) does a use on the module before running the quoted code.
    perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'
Re: printing @INC contents and Command line interpretation
by Anonymous Monk on Aug 29, 2007 at 09:42 UTC
    C:\>perl -le " print for @INC C:/Perl/lib C:/Perl/site/lib . C:\>perl -l print for @INC; __END__ C:/Perl/lib C:/Perl/site/lib . C:\>perl -l print for @INC; ^Z C:/Perl/lib C:/Perl/site/lib . C:\>