----- Forwarded by Derek Smith/Staff/OhioHealth on 05/24/2005 03:47 PM
-----
                                                                           
             Derek                                                         
             Smith/Staff/OhioH                                             
             ealth                                                      To 
                                       John Doe                            
             05/24/2005 12:05          <[EMAIL PROTECTED]>      
             PM                                                         cc 
                                       beginners@perl.org                  
                                                                   Subject 
                                       Re: assigning printf statement to   
                                       an array(Document link: Derek       
                                       Bellner Smith)                      
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           



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.").



This is working but it not printing the calculation "days old" for each
filename???  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

I will also follow up with a line by line question of the code.
thanks again!
derek




Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams




                                                                           
             John Doe                                                      
             <security.departm                                             
             [EMAIL PROTECTED]>                                              To 
                                       beginners@perl.org                  
             05/24/2005 01:34                                           cc 
             AM                                                            
                                                                   Subject 
                                       Re: assigning printf statement to   
                                       an array                            
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




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>


Reply via email to