Link to home
Start Free TrialLog in
Avatar of sud
sud

asked on

Reading Excel File

Hi Experts,
              I want to read  .CSV file using PERL, the file has three columns, list1, list2  and list 3. I want to read values of the three columns.
          Can you please help me how i can do this ?


Thanks

SS
Avatar of ozo
ozo
Flag of United States of America image

while( <> ){
  my($list1,$list2,$list3) = spit/,/;
SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sud
sud

ASKER

Hi Experts,
        my first row is a column name, so how to take care of that?

thanks,

sudhir
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sud

ASKER

Hi Experts,

    I am able to read .CSV file,

   Now I am trying to compare value of first column from .csv file to file name in the directory(A:/temp/RAW), if it matches then print the filename.

        Can you please help me how to do it.

here is my code

use strict;
use warnings;
use File::Find;

open CSV, "A:/temp/test.csv" or die "Can not open file.csv $!\n";

my @columnnames=split(/,/,<CSV>);

while (<CSV>) {
  chomp;
  my ($list1, $list2, $list3) = split /,/;


 find (\&matchPattern, 'A:/temp/Raw');

sub matchPattern
{
        if ($File::Find::name =~ '.txt' )  {
     if ($File::Find::name = "$list1"){
 
         print "$list1";
  }  
   
   
 }

 }

}


I would appreciate ur help or suggestion. Thanks,

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sud

ASKER

Hi Ozo,
    Somehow ur program does not give any output.

My following program gives me correct output except that it prints result twice , any suggestion ?

use strict;
use warnings;
use File::Find;
find (\&matchPattern, ''A:/temp/Raw'');

sub matchPattern
{
       if ($File::Find::name =~ '.xpt'){
      open CSV, "A:/temp/test.csv" or die "Can not open file.csv $!\n";

      my @columnnames=split(/,/,<CSV>);

      while (<CSV>) {
     chomp;
    my ($list1, $list2, $list3) = split /,/;
      if ($File::Find::name = "$list1"){

     print "$list1";
                     }
              }  
       }
}
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial