Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
20.9.2014 - We have just updated our course layouts and descriptions and added our 2015 schedule.

how to read and display from csv file using perl

Posted by kirankumargt (kirankumargt), 20 March 2007
Hi friends,

           i am beginner to the perl ,in my project i want to read the data from csv file, so please help me if any body knows this.................

Posted by admin (Graham Ellis), 20 March 2007
Will a split function help?

Posted by kirankumargt (kirankumargt), 21 March 2007
sorry to say this, i dont know that split function will work or not....

i got how to read from that file but while displaying it is displaying all fields continuously, i want line by line display can u please tell me that how i can display that.......

Posted by admin (Graham Ellis), 21 March 2007
If you can paste up a few lines of code to show us what you mean, we might be able to help.

Posted by kirankumargt (kirankumargt), 21 March 2007
Colavo      jaison-san      january      1      1      lhk      hhk      kl      kh      kl      khl      Fri Mar 16 11:40:17 2007      jaison.j@ap.sony.com
Colavo      jaison-san      january      1      1      yu      ytue      etu      tyeu      tyeu      ytu      Fri Mar 16 11:41:30 2007      jaison.j@ap.sony.com
Colavo      jaison-san      january      1      1      e      re      er      re      re      re      Fri Mar 16 11:46:29 2007      jaison.j@ap.sony.com
Colavo      jaison-san      january      1      1      f      f      f      ff      f      f      Fri Mar 16 11:47:03 2007      jaison.j@ap.sony.com


like this i want line by line display.......if i have book1.csv  like one csv file (comma delimiter) in that data is stored one line in one row and each word in line are stored in separate column  above shown way.....
while retrying from html page i want to display line by line as i shown, but i am getting continuously so please help  me

#!d:/perl/bin/perl

&parse_form_data (*simple_form);
$emailid=$simple_form{'EmailId'};

my $mail_to     =  'kirankumar.gt@ap.sony.com' ;
my $server      =  '43.88.102.10';
my $mail_from   =  $emailid;
use Mail::Sendmail;
$receive = "true";
$project_name=$simple_form{'Projectname'};
$sproject_members = $simple_form{'projectmembers'};
#$sname = $simple_form{'name'};
$month=$simple_form{'month'};
$fromdate = $simple_form{'fromdate'};
$todate = $simple_form{'todate'};
#$status = $simple_form{'status'};
$work_mon = $simple_form{'monday'};
$work_tue = $simple_form{'tuesday'};
$work_wed = $simple_form{'wednesday'};
$work_thu = $simple_form{'thursday'};
$work_fri = $simple_form{'friday'};
$workplaned = $simple_form{'workplaned'};
$sendmail=$simple_form{'sendmail'};
$choosing_report=$simple_form {'choosingreport'};
$day_report=$simple_form{'days'};
$textreportforday=$simpl_form{'textreport'};
if($receive eq "true")
{
 if($choosing_report eq "false")      {
     open(FILE,">>Book21.csv")
  || die "cannot open file";
  #print FILE "\n"."$sproject_members";
  $submitiondateandtime=ctime(time());
     print FILE "\n"."$project_name".","."$sproject_members".","."$month".","."$fromdate".","."$todate".","."$work_mon".","."$work_tue".","."$work_wed".","."$work_thu".","."$work_fri".","."$workplaned".","."$submitiondateandtime".","."$emailid";
     close(FILE);
     }
     else      {
     open(FILE1,">>Book22.csv")
  ||die "cannot open file";
   $submitiondateandtime=ctime(time());
     print FILE1 "\n"."$project_name".","."$sproject_members".","."$month".","."$fromdate".","."$todate".","."$day_report".","."$workplaned".","."$submitiondateandtime".","."$emailid";
     close(FILE1);
     }
     
print "Content-Type: text/html\n\n";
print "<html> <head>\n";
print "<title>Minimal Input</title>\n";
print "</head>\n";
print "<body>\n";
print "<br>Inserting report successfuly\n\n";
print "\n\n</body> </html>\n";
}

else
{
print "Content-Type: text/html\n\n";
print "<html> <head>\n";
print "<title>Minimal Input</title>\n";
print "</head>\n";
print "<body>\n";
print "<br>Inserting report failed";
print "</body> </html>\n";
}
print "\n";
***THIS PORTION I WANT THIS IS READING FROM FILE***
open(DIR,"Book21.csv")
  || die "NO SUCH Directory: Images";
$file=<DIR>;
while ($file ne "" )
{
#if ($file =~ $delimeter)
 #      {
               #print("........................\n"); /\s*\b    \b\s*/
                       #print(@file);
              @wrds=split(/,/,$file);
                   
                    print (@wrds[0]);
                    #print("\n");
                    print (@wrds[1]);
                    #print("\n");
                       print (@wrds[2]);
                       #print("\n");
                       print (@wrds[3]);
                       #print("\n");
                       print (@wrds[4]);
                       #print("\n");

#}

     $file=<DIR>;
  }
close(DIR);




Posted by admin (Graham Ellis), 21 March 2007
Should you be generating a <br> rather than a \n?    \n will give you a new line if you view source, but on a browser it will just give you a space.

Posted by kirankumargt (kirankumargt), 22 March 2007
Thanks  GRAHAM  for u'r well suggestion ............



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho