this sounds like a perfect use for a hash....

%month = (
   1 => "Jan",
   2 => "Feb",
);

print $month{"1"}, "\n";


On 10/10/06, Goke Aruna <[EMAIL PROTECTED]> wrote:
i want to process the attached file and i want to replace the $data[1] with
equivalent month is strings.

i have this code but it giving me errors... i only try the january case at
least.

#!c:/perl/bin/perl
  use warnings ;
 use strict ;
 use POSIX 'strftime';

 my $file = "c:/Perl/test.csv" ;

 { local ($\, $,) = ("\n", ', ') ;
   my $sum ;
   open my $fh, '<', $file or die "open '$file': $!" ;

   while (<$fh>)
   {
     s/\s+$// ;  # chomps-and-more
     /^$/ and die "$file, line $. is empty\n" ;
     my @data = (split /,/)[0, 1, 2, 3, 4, 5, 6] ;
     # $data[0] or next ;  # skips
   #  my $cnt_ans = 0;
     if($data[1] == 1)
          {
            while($data[1] == 1)
            {$data[1]=~ tr/1/January/;}
      } elsif ($data[1] == 2){
         replace all occurence of 2 with February
       } elsif ($data[1] == 3){
         replace all occurence of 3 with March
       } elsif ($data[1] == 5){
        replace all occurence of 5 with May
      } elsif ($data[1] == 6){
      replace all occurence of 6 with June
      } elsif ($data[1] == 7){
      replace all occurence of 7 with July
      } elsif ($data[1] == 8){
       replace all occurence of 8 with August
      }  elsif ($data[1] == 9){
         replace all occurence of 9 with September
       } elsif ($data[1] == 10){
         replace all occurence of 10 with Octomber
       } elsif ($data[1] == 11){
         replace all occurence of 11 with November in the column
       } elsif ($data[1] == 12){
         replace all occurence of 12 with December
       }
 }



--
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