Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Perl MIME

by Tux (Canon)
on Mar 16, 2012 at 07:39 UTC ( [id://959930]=note: print w/replies, xml ) Need Help??


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

The code tags help. Now you should use perltidy to make it show as real code :)

Maybe you can elaborate on the error you get, as the code you posted is pretty long, and the "problem" you are facing is not well-enough defined for us to make a good advice or analysis.


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^4: Perl MIME
by Pan20 (Novice) on Mar 21, 2012 at 23:19 UTC

    Hi Tux, I was playing around with the code and now i have one set of data, currently stored in mimex, how can i get that data to make it run through the while loop below? basically, i want to be able to open and read the txt file created after it was parsed... use MIME::Parser; my $parser = new MIME::Parser; my $output = "/tmp/mimex"; $parser->output_dir($output); my $entity = $parser->read(\*STDIN); --> the file that appears in mimex.... Hi Tux, thanks for having a look. The problem that am facing is that i have this file that is sent from my email to the server. it has a number of different formats in it... like html/text , plain text etc . am interested in the text/plain format. Am using the Mime Parser to extract it from the mail and then want to convert it to csv ... to go through the loop... adn update my database...

    currently when am running it i can see that is going to the point if($type eq 'text/plain') and stops, is not not giving me any errors or going through the rest of the code.... can you suggest me something different? thanks so much,,
    use MIME::Parser; my $parser = new MIME::Parser; my $output = "/tmp/mimex"; $parser->output_dir($output); my $entity = $parser->read(\*STDIN); open CSVFILE $csv = Text::CSV->new(); $processed = 0; #print "test4\n"; while (<CSVFILE>) { $line = $_; if($line =~ /^$/) { } elsif ($indata ==0) { @data = split(/[| ]/,$line); if($data[0] eq 'Subject:') {

      Just replying to the CSV part. Why do you declare a csv parser object and never use it?

      And how is the data separated? The regex shows a pipe or a space. I know of pipe-separated rows that can be named csv, but space OR pipe? Let me assume you meant pipes, where spaces are allowed around the pipes ...

      use MIME::Parser; my $parser = new MIME::Parser; my $output = "/tmp/mimex"; $parser->output_dir ($output); my $entity = $parser->read (\*STDIN); open my $fh, "<", $csv_filename; # That line was missing a lot my $csv = Text::CSV->new ({ binary => 1, auto_diag => 1, sep_char => " +|", allow_whitespace => 1 }); my $processed = 0; #print "test4\n"; while (my $row = $csv->getline ($fh) { @$row or next; # skip empty lines if ($indata == 0) { @data = @$row; if ($row->[0] eq "Subject:") {

      Would that be a start?


      Enjoy, Have FUN! H.Merijn

        Hi Tux,thanks so much for your help, much appreciated. The data is separated by comma, the data is extracted after it goes through the while loop so am getting each column and row etc... The file is parsed so am getting a txt file in the mimex directory, obviously I cant refer to the file directly cause everytime i am running the code a different file is generated... how am gonna get the tx file..(which is text/plain format/csv..

        open my $fh, "<", $csv_filename;
        is the $csv_filename; will open that txt file stored in mimex directory? How can i open that txt file with all of my data so it gets through the while loop? Thanks a lot for your help.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2024-04-23 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found