padawan_linuxero has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Urgent help !!!!
by moritz (Cardinal) on Oct 17, 2007 at 18:27 UTC
    I don't really know what your problem is, or what you are trying to achieve.

    So you want:

    1. Read a CSV file 'patentes.csv', and for each line take the first and third column, and do something with that data

    2. With the ID you extracted in Step 1 you create a filename.

    3. now you write something into that file.

    Is that correct?

    In the last SQL query you have a 'SELECT' but now 'FROM', this looks suspicious to me. Where do you want to take your data from?

    In the first query you select '*' but you only use the first column - where's the sense in that?

    BTW I recommend to derefernce array refs as $row->[0].

    And please use warnings;

Re: Urgent help !!!!
by jZed (Prior) on Oct 17, 2007 at 19:58 UTC
    > my $sql = "SELECT * INTO OUTFILE 'g:/dbf2csv/$filename'
    > FIELDS TERMINATED BY ','
    > LINES TERMINATED BY '\r\n' FROM reg501";

    That syntax is specific to MySQL and won't work with DBD::CSV. You can accomplish the same thing like this:

    $dbh->{csv_files}->{outfile} = { file => "g:/dbf2csv/$filename", sep_char => ',', eol => '\r\n' }; $dbh->do(" CREATE TABLE outfile AS SELECT * FROM sourceTable ");
Re: Urgent help !!!!
by Fletch (Bishop) on Oct 17, 2007 at 18:54 UTC

    Nebulous problem declaration aside, I'm sure those three other people are going to love the increased volume of spam they're going to get thanks to you posting their email addresses unmangled on the intarweb . . .

Re: Urgent help !!!!
by andreas1234567 (Vicar) on Oct 17, 2007 at 18:42 UTC
    padawan_linuxero,

    It's very unclear to me what's your problem. Is it merely to create filenames?

    use strict; use warnings; use DateTime; my $dt = DateTime::->now(); my (undef, $weekNo) = $dt->week(); for my $row (<DATA>) { my @array = split(q{,}, $row); print 'sem'.$weekNo.$array[0].'data.csv'; } __DATA__ 1458,juan armando 2500,Armando Guajardo 3500,AAA 4500,padawan $ perl -wl 645533.pl sem421458data.csv sem422500data.csv sem423500data.csv sem424500data.csv
    Update: Removed intarweb addresses as suggested by Fletch.

    Update 2: This is by no means an advice to abandon the initial set of modules (as suggested by jZed), but merely an attempt to understand to expected output.

    --
    Andreas
      So in other words, you suggest that the OP abandon a module that properly handles CSV and replace it with a split that ignores embedded commas and newlines and that the OP abandon a known interface (SQL) for one they should roll on their own for each new problem? Even if I didn't have a vested interest, I'd consider that bad advice. What you show is fine for one-off stuff but fails badly in the general case.