#! /usr/bin/perl ### basic list processing ### my @array = split /,/, $list; foreach my $item (@array) { # do something with $item } ### pick item from array at random ### my $item = $array[ int( rand( scalar @array ) ) ]; ### clean up and sort lists ### sub sort_list { my ($list) = @_; $list eq '' and return ''; # empty list my %hash = (); my @array = split /,/, $list; foreach (@array) { # use hash to ensure unique values $hash{$_} = 1; } my $sorted = ''; foreach (sort keys %hash) { # sort alphabetically $sorted .= $_ . ' '; } chop $sorted; # nuke trailing space return $sorted; } ### get file mod timestamp ### $secs = (stat($path))[9]; ### make human readable timestamp from system time ### sub format_time { my ($secs) = @_; my ($sec,$min,$hour,$mday,$mon,$year) = localtime($secs); $year += 1900; $mon += 1; my @months = ('*','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); return sprintf("%03s %02s %04d %02s:%02s", $months[$mon], $mday, $year, $hour, $min); }