[Melbourne-pm] Unix / Perl
Craig Sanders
cas at taz.net.au
Sun Dec 16 13:46:46 PST 2007
On Mon, Dec 17, 2007 at 07:46:42AM +1100, Craig Sanders wrote:
> start from something like:
>
> ---cut here---
> #! /usr/bin/perl
>
> use strict;
>
> use IO::All
> use Date::Format;
>
> my $dir = io('/dir1/fileserver/dir2/documents');
>
> foreach (sort {$b->size <=> $a->size} $dir->All) {
> my $username = getpwuid($_->uid);
> my $date = time2str('%Y-%m-%d', $_->mtime);
>
> printf "%s,%s,%s,%s\n", $username, $_->size, $date, $_->name
> }
>
> ---cut here---
oops, when cutting and pasting from my test script, i missed a semicolon
after use 'IO::All'.
and, for completeness, after the printf and final '}', too.
and it doesn't hurt to turn on warnings, too.
the script should look like this, instead.
---cut here---
#! /usr/bin/perl -w
use strict;
use IO::All;
use Date::Format;
my $dir = io('/dir1/fileserver/dir2/documents');
foreach (sort {$b->size <=> $a->size} $dir->All) {
my $username = getpwuid($_->uid);
my $date = time2str('%Y-%m-%d', $_->mtime);
printf "%s,%s,%s,%s\n", $username, $_->size, $date, $_->name;
};
---cut here---
craig
--
craig sanders <cas at taz.net.au>
"The hell with the prime directive! Let's kill something!"
More information about the Melbourne-pm
mailing list