Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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

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

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

Thanks haukex - swift reply!

What, me, not using strict and warnings? ;-) Have changed '' to the following:

use strict; use warnings; print "Hello world!\n"; my $file=''; unless (my $return = do $file) { warn "couldn't parse $file: $@" if $@; warn "couldn't do $file: $!" unless defined $return; warn "couldn't run $file" unless $return; } print "Did that work?\n";

Output is now

Hello world! couldn't do No such file or directory at lin +e 10. couldn't run at line 11. Did that work?

The file '' is certainly there.... (the files are on my desktop and I'm calling them from a command prompt having changed directory to the desktop, by the way).

Replies are listed 'Best First'.
Re^3: 'do' command is dead? Surely not?
by Eily (Parson) on May 19, 2017 at 14:24 UTC

    You can check perl's current directory with Cwd (no matter how unlikely it seems for something to be the cause of a defect, if you're stuck, it's better to check than "just know"). You can also check which files .pl perl sees in the current folder with:

    use Data::Dump qw( pp ); pp <*.pl>;
    I used Data::Dump instead of a simple print, because it will explicitly display characters that might go otherwise unnoticed. If you don't want to install it, you can use Data::Dumper and set $Data::Dumper::Useqq to 1

Re^3: 'do' command is dead? Surely not?
by KurtZ (Monk) on May 19, 2017 at 14:28 UTC
    do docs say "searches the @INC", so maybe check if "." is missing.

      Recent versions of Perl (v5.24.1+) removed '.' from @INC, so this is probably right on the mark. If the OP is using a recent enough Perl version it will not look in the dot path unless something like this happens:

      use lib '.';

      Though that is subject to the challenges that the dot path has always faced. It would be better to do something like this:

      use FindBin; use lib "$FindBin::Bin/../lib"; # Or whatever is accurate for this scr +ipt's needs.

      This eliminates sensitivity to where the script was invoked from.

      See also: FindBin, lib, and perl5241delta.


        Recent versions of Perl (v5.24.1+) removed '.' from @INC

        I knew this is coming for 5.26.0+ ... but backporting it before 5.26.0 is released seems rather extraordinary to me.

        For the OP's case, I think
        do './';
        is sufficient.


        Intriguing, though a bit technical for me to grasp. I update the OS religiously, and this might have been a trigger. Currently seem to be on Perl v5.24.1.

        Recent versions of Perl (v5.24.1+) removed '.' from @INC,

        Ehm , why?

Re^3: 'do' command is dead? Surely not?
by haukex (Prior) on May 19, 2017 at 14:25 UTC
    The file '' 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/';. Also, what version of Perl are you using?

      Thanks both, nice tips.

      Can confirm that both '' and '' are recognised in the following tests

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


      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/ /usr/share/perl/5.24/warnings/ /usr/share/perl/5.24/ /usr/share/perl/5.24/ /usr/lib/x86_64-linux-gnu/perl/5.24/ /usr/share/perl/5.24/ /usr/share/perl/5.24/ File/ /usr/lib/x86_64-linux-gnu/perl/5.24/File/ /usr/share/perl/5.24/ Data/ /usr/local/share/perl/5.24.1/Data/ /usr/share/perl/5.24/ /etc/perl/ /etc/perl/ /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/ /usr/share/perl/5.24/


        You don't show us the output of the file existence tests. Maybe the filename has whitespace at its end. If -f '' 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 './' works for you. That would also work around the problem of . not being in @INC.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1190622]
[marto]: better: "If a type of behaviour, event, or situation is par for the course, it is not good but it is normal or as you would expect"
[Discipulus]: thanks i was unable to decide where to split the sentece
[marto]: FWIW search.cpan rarely has issues, see http://noc.perl. org for a route to report problems
[oakbox]: thanks, marto.
[marto]: there was a period where search.cpan had some frequent outages for (IIRC) a couple of weeks. I've not had any problems since, until today.
[marto]: this was about 16 months ago maybe. the noc team are, in my experience, very responsive to reports of issues, so please raise the issue after checking known problems/outages

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-07-26 10:16 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (389 votes). Check out past polls.