Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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

by haukex (Prior)
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 '' 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?

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 '' 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.

        AHHH!!! my $file='/home/andy/Desktop/'; works!!!! I'm assuming something happened in a recent update. Edit - './' works too. EDIT2 - use lib '.'; my $file=''; 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1190626]
[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 chanting in the Monastery: (5)
As of 2017-07-26 10:20 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (389 votes). Check out past polls.