Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: 'do' command is dead? Surely not?

by ACI (Acolyte)
on May 19, 2017 at 14:45 UTC ( #1190631=note: print w/replies, xml ) Need Help??


in reply to Re^3: 'do' command is dead? Surely not?
in thread 'do' command is dead? Surely not?

Thanks both, nice tips.

Can confirm that both 'test.pl' and 'test-response.pl' are recognised in the following tests

my @files=(); @files=glob('*'); print join("\n",@files),"\n";

and

use Data::Dump qw( pp ); pp <*.pl>;

and that this test yields '/home/Andy/Desktop' as expected

use Cwd; my $dir = getcwd; print "$dir\n";

Finally, %inc contains:

warnings/register.pm /usr/share/perl/5.24/warnings/register.pm overload.pm /usr/share/perl/5.24/overload.pm vars.pm /usr/share/perl/5.24/vars.pm Cwd.pm /usr/lib/x86_64-linux-gnu/perl/5.24/Cwd.pm Exporter.pm /usr/share/perl/5.24/Exporter.pm overloading.pm /usr/share/perl/5.24/overloading.pm File/Glob.pm /usr/lib/x86_64-linux-gnu/perl/5.24/File/Glob.pm warnings.pm /usr/share/perl/5.24/warnings.pm Data/Dump.pm /usr/local/share/perl/5.24.1/Data/Dump.pm strict.pm /usr/share/perl/5.24/strict.pm /etc/perl/sitecustomize.pl /etc/perl/sitecustomize.pl XSLoader.pm /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/XSLoader.pm subs.pm /usr/share/perl/5.24/subs.pm

Confusing!

Replies are listed 'Best First'.
Re^5: 'do' command is dead? Surely not?
by Corion (Pope) on May 19, 2017 at 14:53 UTC

    You don't show us the output of the file existence tests. Maybe the filename has whitespace at its end. If -f 'whatever.pl' fails, then for sure, Perl cannot see that file, for whatever reason.

    Also, the interesting variable is @INC, not %INC.

    You can also check if do './whatever.pl' works for you. That would also work around the problem of . not being in @INC.

    You can also check if do '/home/Andy/Desktop/whatever.pl' works for you. That would also work around the problem of . not being in @INC.

      AHHH!!! my $file='/home/andy/Desktop/test-response.pl'; works!!!! I'm assuming something happened in a recent update. Edit - './test-response.pl' works too. EDIT2 - use lib '.'; my $file='test-response.pl'; also works

      (but, given that my Perl portfolio contains thousands of these, is there a way of telling Perl never to require the absolute path, other than use lib '.'? I think I now understand the importance of '.' in @INC, but soooooo many scripts to edit!)

        See perlrun on how to modify @INC globally via $ENV{PERL5LIB}.

        Personally, I would modify the scripts on an as-needed basis.

      Thanks, Corion

      if (-e $file){ print "File exists\n"; } if (-f $file){ print "File is plain\n"; }

      produces both messages

      @INC contains

      /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/x86_64-linux-gnu/perl5/5.24 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1190631]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2017-10-23 23:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (285 votes). Check out past polls.

    Notices?