G'day daggett,

I noticed your location -- hope you're not inundated with current floods.

You should start all of your Perl code with the strict and warnings pragmata. You've removed debugging statements, so I've no idea what you tried. When printing variables, add markers so that you can see characters, such as tabs and newlines, that may be difficult to notice. Compare these two:

$ perl -E 'my $var = "123\n"; say $var;' 123 $ perl -E 'my $var = "123\n"; say "|$var|";' |123 |

There are a number of functions (e.g. stat & localtime) which return many values; you rarely want all of them. Capture everything then just pull out what you need. I suspect you may be getting a "can't see the wood for the trees" situation with the code you posted.

Given your description, here's how I might have tackled this.

#!/usr/bin/env perl use strict; use warnings; use constant { INODE => 1, FSIZE => 7, MTIME => 9, }; use Cwd 'cwd'; use File::Find; use Time::Piece; my $wDirectory = cwd(); find(\&wanted, $wDirectory); transform($wDirectory); display(); { my ($data_for, $ignore_re, $display_fmt); BEGIN { $ignore_re = qr{(?mx: \. (?: pl | swp \z ) )}; $display_fmt = "%-6s %3d %6d %-10s %17d [%d]\n"; } sub wanted { return unless -f $File::Find::name; return if $_ =~ $ignore_re; $data_for->{$File::Find::name} = { dir => $File::Find::dir, file => $_, stat => [ stat _ ], }; return; } sub transform { my ($cwd) = @_; for my $path (keys %$data_for) { my $data = $data_for->{$path}; my $t = localtime($data->{stat}[MTIME]); my $date = $t->ymd(); $date =~ y/-//d; my $rel_dir = join substr($data->{dir}, length $cwd), qw{. + /}; @$data{qw{date rel_dir inode size mtime}} = ($date, $rel_dir, @{$data->{stat}}[INODE, FSIZE, MTI +ME]); } return; } sub display { my @display_fields = qw{file size date rel_dir inode mtime}; printf $display_fmt, @{$data_for->{$_}}{@display_fields} for sort { $data_for->{$a}{mtime} <=> $data_for->{$b}{mtime} } keys %$data_for; return; } }

Output:

f1 0 20221013 ./d1/d3_3/ 10977524094816598 [1665639046] f1 0 20221013 ./d1/d1_1/ 10133099164684663 [1665639074] f2 0 20221013 ./d1/d1_1/ 9570149211263361 [1665639080] f3 0 20221013 ./d1/d1_1/ 9851624187974024 [1665639088] f1 0 20221013 ./d1/d1_2/ 9007199257842058 [1665639107] f2 0 20221013 ./d1/d1_2/ 9851624187974028 [1665639115] f3 0 20221013 ./d1/d1_2/ 10696049118105998 [1665639120] f2_2 0 20221013 ./d2/ 10414574141395314 [1665639154] f2_3_1 0 20221013 ./d2/d2_3/ 10414574141424462 [1665639207] f2_2_2 0 20221013 ./d2/d2_2/ 9851624187973976 [1665639223] f2_2_1 0 20221013 ./d2/d2_2/ 8725724281131669 [1665639238]

Notes:

— Ken


In reply to Re: stat function used with linux find gives me no data by kcott
in thread stat function used with linux find gives me no data by daggett

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.