in reply to stat function used with linux find gives me no data

You don't chomp newlines from your filenames you read back from find so my guess is that since you call stat with "/home/blah/foo\n" (note the trailing newline) it's failing and you don't notice since you don't check the return fron stat. Also you might look at File::Find or File::Find::Rule (or Path::Tiny might be of related interest) rather than shelling out to find.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: stat function used with linux find gives me no data
by daggett (Novice) on Oct 13, 2022 at 10:48 UTC

    Thank you. At first I tried:

    $output = chomp($_);

    That didn't work. So I found, from the online documentation, how to properly use chomp(). I tried:

    $output = $_; chomp($output);

    ... and it worked!

    Thank you, also, for those other suggestions. I will also give File::Find, File::Find::Rule and Path::Tiny a try soon.

      Well done for consulting the docs - they really are rather good.

      You might also want to know that a simple assignment can be chomped as well so you could write this as chomp ($output = $_); instead. Full demo script:

      #!/usr/bin/env perl use strict; use warnings; $_ = "foo\n"; print "in: '$_'\n"; chomp (my $output = $_); print "out: '$output'\n";

      I concur with others in warning against shelling out to find for your original task, not least because of the vagaries of the arguments and output formats of such a utility across platforms. Stick with the modules which come with Perl or are on CPAN for better portability.


      🦛

      from the online documentation

      In case you didn't know, you can also find out about any perl function with perldoc -f chomp from the command line, or perldoc MODULENAME for any installed perl module. On Unix, you can often see them as manual pages as well: man MODULENAME, but that depends on your distro.