Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by haukex (Monsignor)
on May 19, 2017 at 14:25 UTC ( #1190626=note: print w/replies, xml ) Need Help??


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

The file 'test-response.pl' is certainly there...

Not to Perl it seems... I would investigate this further. For example, try things like print -e $file ? "exists\n" : "doesn't exist\n";, use Cwd; print getcwd, "\n";, or my $file='/absolute/path/to/test-response.pl';. Also, what version of Perl are you using?

Replies are listed 'Best First'.
Re^4: 'do' command is dead? Surely not?
by ACI (Acolyte) on May 19, 2017 at 14:45 UTC

    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!

      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!)

        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://1190626]
help
Chatterbox?
holli scratches his head
holli feels silly

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2017-09-24 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (274 votes). Check out past polls.

    Notices?