Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: how to handle the warnings in a find statement

by Aldebaran (Curate)
on Dec 20, 2016 at 09:12 UTC ( [id://1178177]=note: print w/replies, xml ) Need Help??


in reply to Re^3: how to handle the warnings in a find statement
in thread how to handle the warnings in a find statement

Thanks all for responses, and I have more perl reading than time, which will suit my dental cleaning appointment just fine tomorrow. I've skimmed what was posted mod one and taken what I thought most relevant for scripts moving forward. Right now, I'm drawing cpan errors with my strawberry perl install. I'm putting this output between readmore tags again along with the new source listing the way windows sees it.

+ cpan> install Devel +::Refcount Devel::Refcount is up to date (0.10). + cpan> install Win32 +::LongPath Running install for module 'Win32::LongPath' Checksum for C:\STRAWB~1\cpan\sources\authors\id\R\RB\RBOISVERT\Win32- +LongPath-1.07.tar.gz ok Scanning cache C:\STRAWB~1\cpan\build for sizes ...................................................................... +......DONE Configuring R/RB/RBOISVERT/Win32-LongPath-1.07.tar.gz with Makefile.PL Writing ppport.h Checking if your kit is complete... Looks good Generating a dmake-style Makefile Writing Makefile for Win32::LongPath Writing MYMETA.yml and MYMETA.json RBOISVERT/Win32-LongPath-1.07.tar.gz C:\Strawberry\perl\bin\perl.exe Makefile.PL -- OK Running make for R/RB/RBOISVERT/Win32-LongPath-1.07.tar.gz cp lib/Win32/LongPath.pm blib\lib\Win32\LongPath.pm Running Mkbootstrap for LongPath () "C:\Strawberry\perl\bin\perl.exe" "-Iinc" -MExtUtils::Command -e chmod + -- 644 "LongPath.bs" "C:\Strawberry\perl\bin\perl.exe" "-Iinc" -MExtUtils::Command::MM -e c +p_nonempty -- LongPath.bs blib\arch\auto\Win32\LongPath\LongPath.bs 6 +44 "C:\Strawberry\perl\bin\perl.exe" "-Iinc" "C:\Strawberry\perl\lib\ExtU +tils\xsubpp" -typemap C:\STRAWB~1\perl\lib\ExtUtils\typemap xs\Long +Path.xs > xs\LongPath.xsc "C:\Strawberry\perl\bin\perl.exe" "-Iinc" -MExtUtils::Command -e mv -- + xs\LongPath.xsc xs\LongPath.c gcc -c "-I." "-I." -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -DPERL_ +TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fwrapv +-fno-strict-aliasing -mms-bitfields -Wall -W -Wno-comment -s -O2 + -DVERSION=\"1.07\" -DXS_VERSION=\"1.07\" -o xs\LongPath.o "-IC: +\STRAWB~1\perl\lib\CORE" -DUSE_PPPORT -DWINVER=0x0a00 -D_WIN32_WINNT +=0x0a00 xs\LongPath.c In file included from C:/STRAWB~1/perl/lib/CORE/hv.h:631, from C:/STRAWB~1/perl/lib/CORE/perl.h:3904, from xs\\LongPath.xs:21: C:/STRAWB~1/perl/lib/CORE/hv_func.h: In function `S_perl_hash_murmur3' +: C:/STRAWB~1/perl/lib/CORE/hv_func.h:403: warning: cast from pointer to + integer of different size xs\\LongPath.xs: In function `MakeSymbolicLink': xs\\LongPath.xs:79: warning: implicit declaration of function `CreateS +ymbolicLinkW' xs\\LongPath.xs:80: error: `SYMBOLIC_LINK_FLAG_DIRECTORY' undeclared ( +first use in this function) xs\\LongPath.xs:80: error: (Each undeclared identifier is reported onl +y once xs\\LongPath.xs:80: error: for each function it appears in.) xs\\LongPath.xs: In function `XS_Win32__LongPath_find_close': xs\\LongPath.xs:179: warning: cast to pointer from integer of differen +t size xs\\LongPath.xs: In function `XS_Win32__LongPath_find_first_file': xs\\LongPath.xs:191: warning: cast from pointer to integer of differen +t size xs\\LongPath.xs: In function `XS_Win32__LongPath_find_next_file': xs\\LongPath.xs:281: warning: cast to pointer from integer of differen +t size dmake.exe: Error code 129, while making 'xs\LongPath.o' RBOISVERT/Win32-LongPath-1.07.tar.gz C:\STRAWB~1\c\bin\dmake.exe -- NOT OK Stopping: 'install' failed for 'Win32::LongPath'. Failed during this command: RBOISVERT/Win32-LongPath-1.07.tar.gz : make NO + cpan>

The way I see it is that I was doing alright. I believe to have cleared the cpan dependencies, but see complaints that look like things a C compiler says. Perl on windows 10 is such an odd platypus that I can't think of where C libraries are and how to remediate that.

Update

Source listing and errors:

C:\Users\Fred>type virus6.pl #!/usr/bin/perl use warnings; use strict; use File::Find; use Cwd; my $current = cwd; find( \&pm_beneath, $current, ); sub pm_beneath { use File::Basename; use 5.01; my $file = $File::Find::name; my $ref_to_file = \$file; my $days = .1; #hard-coded my $basename = basename($file); return if $file =~ /.*AppData.*/; use Fcntl ':mode'; use Win32::LongPath qw(:funcs :fileattr); # get object testL ('e', $file) or die "$file doesn't exist!"; $stat = statL ($file) or die ("unable to get stat for $file ($^E)"); # this test for directory $stat->{mode} & S_IFDIR ? print "Directory\n" : print "File\n" +; # is the same as this one $stat->{attribs} & FILE_ATTRIBUTE_DIRECTORY ? print "Directory +\n" : print "File\n"; # show file times as local time printf "Created: %s\nAccessed: %s\nModified: %s\n", scalar localtime $stat->{ctime}, scalar localtime $stat->{atime}, scalar localtime $stat->{mtime}; my $access_age = -M $basename; return if ( $access_age > $days ); print "$file\n"; printf "$basename: M age in days: %.4f\n\n", $access_age; say "ref to file is $ref_to_file"; } __END__ C:\Users\Fred>perl virus6.pl Can't locate Win32/LongPath.pm in @INC (you may need to install the Wi +n32::LongPath module) (@INC contains: C:\Users\Fred\Documents\perl5\l +ib\perl5/5.24.0/MSWin32-x64-multi-thread C:\Users\Fred\Documents\perl +5\lib\perl5/5.24.0 C:\Users\Fred\Documents\perl5\lib\perl5/MSWin32-x6 +4-multi-thread C:\Users\Fred\Documents\perl5\lib\perl5 C:\Users\Fred\ +perl5\lib\perl5/5.24.0/MSWin32-x64-multi-thread C:\Users\Fred\perl5\l +ib\perl5/5.24.0 C:\Users\Fred\perl5\lib\perl5/MSWin32-x64-multi-threa +d C:\Users\Fred\perl5\lib\perl5 C:/Strawberry/perl/site/lib C:/Strawb +erry/perl/vendor/lib C:/Strawberry/perl/lib .) at virus6.pl line 22. BEGIN failed--compilation aborted at virus6.pl line 22. C:\Users\Fred>

Replies are listed 'Best First'.
Re^5: how to handle the warnings in a find statement
by huck (Prior) on Dec 20, 2016 at 09:55 UTC

    Wow

    Im not sure you realize that the "wanted" sub gets passed directories too. i often have a return unless (-f $file); in there.

    another thing the wanted sub can do is signal to prune the tree. $File::Find::prune = 1 is a signal to File::Find not to follow a directory. You want to prune junction points.

    # this test for directory $stat->{mode} & S_IFDIR ? print "Directory\n" : print "File\n" +; # is the same as this one $stat->{attribs} & FILE_ATTRIBUTE_DIRECTORY ? print "Directory +\n" : print "File\n"; my $isjunction= <.. some code to see if its a junction ..> ; if ($isjunction){ $File::Find::prune = 1 return; }
    now you may even be able to contrive a test <.. some code to see if its a junction ..> that does not require "use Win32::LongPath", i dont know what it is now. Otherwise i think you are stuck trying to install that module. , sorry

      https://github.com/rdboisvert/Win32-LongPath is the repository for this module. I'm almost glad for the opportunity to clone this, as using git was part of the exercises for _Intermediate Perl_, as well as using find statements. The readme says to dmake the product:

      What this shows is the exact same litany of errors I got yesterday with cpan. This will mean something to a prognosticator. Let me first trot out the actual command:

      gcc -c  "-I." "-I."     -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE  -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fwrapv -fno-strict-aliasing -mms-bitfields -Wall -W -Wno-comment -s -O2       -DVERSION=\"1.07\"    -DXS_VERSION=\"1.07\" -o xs\LongPath.o  "-IC:\STRAWB~1\perl\lib\CORE"  -DUSE_PPPORT -DWINVER=0x0a00 -D_WIN32_WINNT=0x0a00 xs\LongPath.c

      I know C well enough to see that this seems syntactic, whilst not really knowing more than half of the flags. (You tell me what -DCONSERVATIVE is, and I'll be impressed.) The first errors cite hv.h, which seems to be how perl defines hashes. I believe this is how perl pre-declares C to achieve that data structure:

      The way I read it, gcc fails in the early phases because we've got the warnings/strictness dialed up pretty darn high. So I'm twice a loser with installing this mod, once with cpan, u takzhe dmaking as per README. So those are my woes that I offer undo the gods of perl. I didn't wash out completely, though and cleared one variety of diagnostic by inclusion of:

      return unless (-f $file);

      But I achieved something else with the part of the script that doesn't depend on cpan. I downloaded the module at pi time, and put it in my local::lib for strawberry perl, which was set to "My Documents". Lo and behold, they are showing up only under 'Documents', so the warning that I can't open the directory "My Documents" doesn't correspond to something that went unsearched. I'd still like to handle the event so my script is clear of warnings.

      As a bonus insight, I got to see where the machine model for C stopped. It's close to M = .19 in these data:

      Seek help with LongPath.

        Hi

        The first errors cite hv.h ...

        Its a warning, and its not in the target distribution (longpath) so ignore it :)

        LongPath.xs:80: error: `SYMBOLIC_LINK_FLAG_DIRECTORY' undeclared (first use in this function) xs\\LongPath.xs:

        Thats the show stopper :)

        On my machine that is defined in

        ...mingw32\i686-w64-mingw32\include\winbase.h 2752:#define SYMBOLIC_LINK_FLAG_DIRECTORY 0x1

        So two ways to fix this, edit winbase.h to define this constant, or edit LongPath.xs

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178177]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-23 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found