Hi jeff,
When I come to this site with some spare time, I try to work through some script that stretches my game a little bit. I had to add print statements to figure out your syntax but wanted to ask for clarification.
$ perl stat1.pl files are ./causes2.txt ./fears1.pl ./fears1.pl~ ./fears2.txt ./stat1. +pl ./stat1.pl~ ./template_stuff 240 282 242 63 396 362 4096 subroutine says this is your hash: key: ./stat1.pl, value: HASH(0xa1519ac) key: ./causes2.txt, value: HASH(0xa0fe7ec) key: ./fears1.pl, value: HASH(0xa118598) key: ./fears1.pl~, value: HASH(0xa117ddc) key: ./fears2.txt, value: HASH(0xa12c59c) key: ./stat1.pl~, value: HASH(0xa17581c) key: ./template_stuff, value: HASH(0xa22a8d4) $
Q1) Why are directories always 4096 on my linux machine, regardless of whatever is in it?
I really couldn't understand the map and resulting hash until I saw that the values were themselves hash references. I'm not suggesting that I added to your script in any way to improve it; rather it is simply more verbose:
$ cat stat1.pl use strict; use warnings; use 5.010; use lib "template_stuff"; use utils1 qw(print_hash); my @files = glob('./*'); my %stat = map { $_ => { r => (-r $_), w => (-w $_), x => (-x $_), s => (-s $_), } } @files; say "files are @files"; # print out all sizes, as an example print $stat{$_}{s}, $/ for @files; my $hashref = \%stat; print_hash ( $hashref ); $
Q2) Do I have it correct that the stat hash has an array reference as its value, where it references a hash with the letters for filetests as keys and their stat'ed values for any given file as values?
Q3) How would I enumerate them, that is, display all their values for a directory?
Thanks for your interesting post and comment,
In reply to Re^2: Is it possible to localize the stat/lstat cache?
by Aldebaran
in thread Is it possible to localize the stat/lstat cache?
by bounsy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |