in reply to Re^6: Perl MIME
in thread Perl MIME - Open file

If the data is separated by comma's, your own example is horribly wrong, as it splits the data by space or pipe.

Text::CSV (or Text::CSV_XS) don't need an actual file. They operate on "stream"s just as well. If your data is something that is looking like a filehandle, just pass it to getline () and it should work fine ...

# make sure $fh is the file-handle to the CSV stream # with the CSV data in memory (say it is in $data), you can # use perlio: # open my $fh, "<", \$data; my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 }); while (my $row = $csv->getline ($fh) { @$row or next; # skip empty lines if ($indata == 0) { @data = @$row; if ($row->[0] eq "Subject:") {

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^8: Perl MIME
by Pan20 (Novice) on Mar 22, 2012 at 13:49 UTC

    Hi Tux, once last question, the /data to open the text file, in my case is /mimex or is the \*STDIN ? just putting it all together , see below.... looks ok to you? Thanks so much!!!

    #! /usr/bin/perl open FILE,">>/tmp/SRP_RMS.xlog"; print FILE "\nInitialising\n"; my $dbh = DBI->connect($dsn,$user,$pass) or die "Can't Connect to the DB: $DBI::errstr\n"; $indata=0; use MIME::Parser; $parser = new MIME::Parser; $output = "/tmp/mimex"; $parser->output_dir($output); my $entity = $parser->read(\*STDIN); open my $fh, "<", \$data; my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 }); while (my $row = $csv->getline ($fh) { @$row or next; # skip empty lines if ($indata == 0) { @data = @$row; if ($row->[0] eq "Subject:") {

      You have never set anything to $data, so this will fail. If I read MIME::Parser, it stores the "part"s in the folder you tell it to store them, and the API does not mention how to check what parts are stored and how. Maybe you should use MIME::Tools instead, as its documentation suggests. For what you try to solve, this looks pretty promising.

      In the scheme you now present, you will have to opendir DIR, $output; and use readdir () to find out what files were written and then open the required file.

      As long as you do not have a pointer to a valid CSV stream, I think my help is rather dim.


      Enjoy, Have FUN! H.Merijn