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

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

by Corion (Pope)
on May 19, 2017 at 14:53 UTC ( #1190634=note: print w/replies, xml ) Need Help??


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

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.

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

    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.

Re^6: 'do' command is dead? Surely not?
by ACI (Acolyte) on May 19, 2017 at 15:03 UTC

    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://1190634]
help
Chatterbox?
and dust plays in a shaft of sunlight...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2017-08-19 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (310 votes). Check out past polls.

    Notices?