Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^7: Parse .csv file from FTP using Perl

by Tux (Monsignor)
on Jun 21, 2012 at 06:45 UTC ( #977580=note: print w/ replies, xml ) Need Help??


in reply to Re^6: Parse .csv file from FTP using Perl
in thread Parse .csv file from FTP using Perl

muba already helped you with the basics, which were quite well explained. muba++. Text::CSV is a wrapper over Text::CSV_XS and Text::CSV_PP. Whatever is developed in Text::CSV_XS is copied into Text::CSV_PP making them behave exacly the same, but the XS version is up to 100 times as fast. Both act on streams of data, wheather that is a file or a pipe. That means that these modules do not allow to go "back" into the stream to look at previous lines. As muba already mentioned, getline_hr_all can be very handy here.

If you need to do many lookups, like in a spreadsheet or a database, consider using DBD::CSV (when you are acquainted with DBI) or Spreadsheet::Read, which enables you to look at CSV file with the eye of a spreadsheet and enables you to direct access any field in a CSV data structure.

One final remark about your original code. The "loop" could easily be shortened a lot:

my @ftpFiles =$ftp->ls (); + my $i = 0; while ($i < $#ftpFiles) { + if ($ftpFiles[$i] =~ m/andv/) { $ftp->get ($ftpFiles[$i]); $myfile = $ftp; } $i++; } $ftp->quit (); => foreach my $file (grep m/andv/ => $ftp->ls ()) { $ftp->get ($file); $myfile = $file; # <= your original code probably does not do what + you want } $ftp->quit ();

update: corrected mumba to muba. sorry.


Enjoy, Have FUN! H.Merijn


Comment on Re^7: Parse .csv file from FTP using Perl
Select or Download Code
Re^8: Parse .csv file from FTP using Perl
by Sherlock Perl (Novice) on Jun 21, 2012 at 13:45 UTC
    Thank you for the clarifications. But why do you think my original code doens't do the job it is supposed to do?

      Only this line is extremely suspicious:

          $myfile = $ftp;

      $ftp is an object which will not ever be a filename. $myfile will now contain something like Net::FTP=GLOB(0x13734b8), which IMHO is most likely not what you want in there.


      Enjoy, Have FUN! H.Merijn
        Hi, I think you right. I am not sure how to use this as I wrote in my edited post couple of minutes ago. I will try your version now. What I want is to connect the code muba kindly wrote (and i altered a very little bit) to the .csv file I get from the ftp. I though this $myfile would in a way have the .csv file but obviously it doesn't. I will try changing to yours now. Is this what your code corrects? Thank you once again!
        I am done. Thank you all very much. I will try to do the SQL part now :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://977580]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-08-22 22:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (168 votes), past polls