Hi
Am Dienstag, 24. Mai 2005 18.05 schrieb [EMAIL PROTECTED]
with funny quoting:
[John:]
> my @a=
> map {$hdir.$_->[1]} # select filename
> grep {$_->[0] > 100} # exclude age <= 100
> map { [
> sprintf ("%.0f",( $now - ( stat("${hdir}$_" ) )[9] ) / ONE_DAY ),
> $_
> ] } # create aref [age, filename]
> grep {$_ ne "." and $_ ne ".."} # exclude unwanted
> sort readdir DH; # get all files
>
>
> The map-grep-map-construct is quite common for problems like yours
> ("But I cannot use $_ b/c $_ is the dir name.").
[Derek:]
> This is working but it not printing the calculation "days old" for each
> filename???
No, obviously not... I wanted to demonstrate the principle where
some kind of additional attributes (here: age) of a list of entities (files)
is created on the fly and kept together (in an aref), and taken as base for
further treatment (selection). [ Hope this english is understandable :-) ]
> I want to print the aref.
> I verified that it is indeed only printing those files over 100 days old,
> but I need output such as,
>
> ABDELFATTAH__FAITH_M702515438: 101
>
> as opposed to
>
> ABDELFATTAH__FAITH_M702515438
Ok, then some minimal changes in the first two lines are necessary (although
there are other possibilities to do what you want; my proposal is possibliy
not the most performant, but splits the problem into smaller parts that can
be chaned)
[also untested...]
print
map {$_->[1].": ".$_->[0]."\n"} # create entity output
grep {$_->[0] > 100} # exclude age <= 100
map { [
sprintf ("%.0f",( $now - ( stat("${hdir}$_" ) )[9] ) / ONE_DAY ),
$_
] } # create aref [age, filename]
grep {$_ ne "." and $_ ne ".."} # exclude unwanted
sort readdir DH; # get all files
> I will also follow up with a line by line question of the code.
Just go on, questions are half of the answers :-)
joe
[...]
[maybe I should have snipped the rest?]
> Am Montag, 23. Mai 2005 20.05 schrieb [EMAIL PROTECTED]:
> > Hi all.....
> >
> > This is a continuation from my original question, but with a twist. I am
> > now using sprintf to assign to an array, but I only want to assign to
>
> this
>
> > array of I find a number over 100 from my calculation. In the array/hash
> > also needs to be the directory name. Here is my code and the sample
> > output:
> > So in the end my goal is to store the data in this array if the number is
> > over 100 and if it is over 100 store the directory name and its
>
> associative
>
> > "days old calc."
> > I have tried my @a =(); my $e =0;
> > $a[$e++] = sprintf ("%.0f",( $now - ( stat( "${hdir}${file}" ) )[9] ) /
> > ONE_DAY ) if ??? > 100;
> >
> > But I cannot use $_ b/c $_ is the dir name.
> >
> > thank you,
> >
> > derek
> >
> >
> >
> >
> > use strict;
> > use warnings;
> > $ENV{"PATH"} = qq(/opt/SUNWsamfs/sbin:/usr/bin:/usr/sbin:/usr/local/log);
> >
> > my $hdir = qq(/heartlab/db studies/);
> > #my $fdirs =
> > qq(/fuji/original/RMH/,/fuji/original/GMC/,/fuji/clinical/GMC/,/fuj
> > i/clinical/RMH/);
> > $^T=time;
> > our $now = time();
> > use constant ONE_DAY => 86400;
> >
> >
> > sub date_manip
> > {
> > my ($month, $day, $year) = (localtime)[4,3,5];
> > sprintf ("%02d/%02d/%02d\n", $month+1,$day,($year %
>
> 100));
>
> > }
> >
> > my $dm = &date_manip;
> >
> > sub date_manip1
> > {
> > my $days = (shift);
> > my ($d, $m, $y) = (localtime($now - $days * ONE_DAY))
> > [3..5];
> > sprintf ("%02d/%02d/%02d", $m+1,$d,($y % 100));
> > }
> >
> > #my $dmm = &date_manip1(1);
> > #chomp $dm;
> > #chomp $dmm;
> >
> >
> >
> > opendir (DH, $hdir) or die "unable to open directory: $hdir $!";
> >
> > my @a =();
> > my $e =0;
> > foreach my $file (sort readdir (DH))
> > {
> > next if $file eq "." or $file eq "..";
> > print "\n";
> > print "Days old of HL image files are:\t",$file,":\t";
> > #printf ("%.0f", ( $now - ( stat( "${hdir}${file}" ) )[9]
>
> )
>
> > / ONE_DAY );
> > $a[$e++] = sprintf ("%.0f",( $now - ( stat(
> > "${hdir}${file}" ) )[9] ) / ONE_DAY );
> > #date_manip1($1);
> > }
>
> instead of the foreach loop you could use a single statement [untested]:
> (read from bottom to top)
>
> my @a=
> map {$hdir.$_->[1]} # select filename
> grep {$_->[0] > 100} # exclude age <= 100
> map { [
> sprintf ("%.0f",( $now - ( stat("${hdir}$_" ) )[9] ) / ONE_DAY ),
> $_
> ] } # create aref [age, filename]
> grep {$_ ne "." and $_ ne ".."} # exclude unwanted
> sort readdir DH; # get all files
>
>
> The map-grep-map-construct is quite common for problems like yours
> ("But I cannot use $_ b/c $_ is the dir name.").
>
> (Schwarz'sche Transformation in german).
>
>
> hth, joe
>
> > closedir (DH) or warn "unable to close DH: $hdir $!;"
> >
> > ___END CODE___
> >
> > ___BEGIN_DATA___
> >
> > Days old of HL image files are: 0_LEARY_ALANRA002848: 68
> > Days old of HL image files are: AARON_YAZAWA_CHRISTEHD006871: 48
> > Days old of HL image files are: AARON_YAZAWA_CHRISTERF015357: 64
> > Days old of HL image files are: ABBOTT_ANNA_MAERF014496: 49
> > Days old of HL image files are: ABBOTT_CONSTANCEMK003126: 69
> > Days old of HL image files are: ABBOTT_DONALDHE011252: 67
> > Days old of HL image files are: ABBOTT_FLORENCE068148_15857: 20
> > Days old of HL image files are: ABBOTT_HARRYRA002652: 68
> > Days old of HL image files are: ABBOTT_THOMASMKOOOO61: 66
> > Days old of HL image files are: ABBOTT__FLORENCEHC008241: 20
> > Days old of HL image files are: ABBRUZZESE_BETTYMK004528: 78
> > Days old of HL image files are: ABBRUZZESE_BETTYML002169: 80
> > Days old of HL image files are: ABDALLA__PATRICIAHA014365: 56
> > Days old of HL image files are: ABDELFATTAH_FAITH0702515438: 98
> > Days old of HL image files are: ABDELFATTAH__FAITH_M702515438: 101
> > Days old of HL image files are: ABDULLAHI__ABDIRAHMAMJ003339: 62
> > Days old of HL image files are: ABELL_MARKRF015325: 66
> > Days old of HL image files are: ABEL_HUBERTMJ003654: 21
> > Days old of HL image files are: ABEL_RICHARDMK003922: 82
> > Days old of HL image files are: ABEL_STEVENHD007640: 75
> > Days old of HL image files are: ABEL_STEVENRA003253: 75
> > Days old of HL image files are: ABEL__LARRYRF013486: 73
> >
> >
> >
> >
> > Derek B. Smith
> > OhioHealth IT
> > UNIX / TSM / EDM Teams
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>