i255d has asked for the wisdom of the Perl Monks concerning the following question:
How does $age know to apply -M to the file going through the foreach loop?#!/usr/bin/perl use strict; use warnings; use 5.010; die "No file names supplied!\n" unless @ARGV; my $oldest_name = shift @ARGV; my $oldest_age = -M $oldest_name; foreach (@ARGV) { my $age = -M; ($oldest_name, $oldest_age) = ($_, $age) if $age > $oldest_age; } printf "The oldest file was %s, and it was %.1f days old\n", $oldest_name, $oldest_age;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: First Question, why something works? (-M)
by toolic (Bishop) on Apr 16, 2014 at 12:30 UTC | |
by i255d (Initiate) on Apr 16, 2014 at 12:44 UTC | |
by Athanasius (Archbishop) on Apr 16, 2014 at 13:38 UTC | |
by i255d (Initiate) on Apr 16, 2014 at 13:51 UTC | |
by Anonymous Monk on Apr 16, 2014 at 20:44 UTC | |
by Laurent_R (Canon) on Apr 16, 2014 at 13:20 UTC |