Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Parse .csv file from FTP using Perl

by Sherlock Perl (Novice)
on Jun 21, 2012 at 00:03 UTC ( #977511=perlquestion: print w/ replies, xml ) Need Help??
Sherlock Perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi there, I have several questions and I hope there are people with free time and desire to help me :) Please be patient because I wrote a line in Perl for the first time around 25/26 hours ago. I need to get to a .csv file in an ftp and then parse this file to find a specific numerical value and then I need to export it to sql but lets do it step by step :D So here is my code connecting to the ftp and trying to get the csv file. Can you please tell me if it is correct and if so how should I proceed? Open/Activate the file and try to "look" inside? I already have an idea how to find the value but NO IDEA how to do it in Perl :/ I hope you will bear with me. So here is the code (and thank you in advance):

#!/usr/bin/perl use strict; use IO::File; use File::Copy; use Net::FTP; sub main(){ my $ftp = Net::FTP->new("ftp://.....com"); $ftp->login('.....','.....'); + $ftp->binary(); $ftp->cwd('/a/b/c'); + my @ftpFiles =$ftp->ls(); + + my $i = 0; + + + while ($i < $#ftpFiles) { + + if($ftpFiles[$i] =~ m/andv/) + { $ftp->get($ftpFiles[$i +]); $myfile = $ftp; } $i++; } $ftp->quit(); + +

Comment on Parse .csv file from FTP using Perl
Download Code
Re: Parse .csv file from FTP using Perl
by muba (Priest) on Jun 21, 2012 at 00:27 UTC

    You're starting off great. I see you use strict;. Might I suggest that you use warnings; as well? And I see you've discovered how to work with modules, so you're on a good track here.

    As for reading the CSV file, how about Text::CSV? There is a nice section about database programming in our tutorials library, you might want to have a look at that.

    Good luck! Should you run into further problems, don't hesitate to ask.

      Thank you for the quick reply. Could you please direct me to some place where I can read how to parse the csv. The idea is that the file I am reaching to has 2 rows and I want to find the value in the 2nd row that corresponds to a specific value (assume "xyz") in the first row? How exactly should I go about doing this and storing the value from the 2nd row? Thank you in advance!

        Text::CSV will help you do that. I would hack together a little something for you, but uhm, you also need to know which field (or column, or whatever the CSV terminology for that is) the value appears in, am I right? Otherwise you're just saying something like, "search me a thing that is similar to the thing that grows on the tree!" Yeah, okay, but what sort of thing on what tree? Are we talking branches here? Apples? Pears? Leafs?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2014-09-21 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (172 votes), past polls