When you get stuck, and what you think should be matching is not matching, its time to ddumperBasic debugging checklist the data you're matching against ( $textstuff, $from ), so you can figure out if the problem is with the data (missing, not what you expected), or with your regex pattern ( m//matching or s///ubstitution )

The script is composed mostly of bits and pieces of other scripts I have found over the last few months .... ny ideas on what would make this work better, and actually log the urls? make it log any messages that match any of the from addresses, IF they don't have an attachment? Thanks all for your help!

Hello and congratulations, you got pretty far, you've got a prototype, but now you're a little bit stuck, its time to rethink your approach :) its time to start over :)

Why? :) Because you have lines eleven indentation levels deep, there are too many variables around to keep track of ; you need more subroutines

The way I would approach this problem/exercise/task, is to pretend the code you have written doesn't exist, grab a pencil and paper, and draw a few boxes , putting a goal into each box :) say

------ | get list of files ---- \ ------ | check each file for from address ---- \ ------ | if address matching explode plaintext attachment into outdir ---- \ ------ | scan each exploded plaintext for ... links? ---- \ ------ | add each found link to logfile ----

Now that you have goals, start turning them into subroutines, so when you get stuck you can copy/paste only the subroutine which isn't working and concentrate on only fixing it -- easier than fixing entire program :)

So you then write something like

#!/usr/bin/perl -- use strict; use warnings; use MIME::Parser; ... Main( @ARGV ); exit( 0 ); sub Mainsky { ... my @files = get_files( $fromdir ); for my $file ( @files ){ if( matches_adresses_iwant( $file ) ){ informit( "explode_plaintext_fromfile_into( $file, $outdir + )" ); explode_plaintext_fromfile_into( $file, $outdir ); my @links = extract_links( $outdir ); if( @links ){ log_links( @links ); } else { informit( "not extract_links( $file )" ); } } else { informit( "not matches_adresses_iwant( $file )" ); } } } sub get_files { ... } sub matches_adresses_iwant { ... } sub extract_links { ... } sub explode_plaintext_fromfile_into { ... } sub log_links { ... } sub informit { print STDOUT @_,"\n" } __END__

Or like

#!/usr/bin/perl -- use strict; use warnings; use MIME::Parser; ... Main( @ARGV ); exit( 0 ); sub Mainskee { ... my @files = get_files( $fromdir ); for my $file ( @files ){ if( matches_adresses_iwant( $file ) ){ informit( "explode_plaintext_fromfile_into( $file, $outdir + )" ); lincon_plaintext_logs( $file, $outdir ); } else { informit( "not matches_adresses_iwant( $file )" ); } } } sub lincon_plaintext_logs { my( $outdir , $file ) = @_; explode_plaintext_fromfile_into( $file, $outdir ); my @links = extract_links( $outdir ); if( @links ){ log_links( @links ); } else { informit( "not extract_links( $file )" ); } } sub get_files { ... } sub matches_adresses_iwant { ... } sub extract_links { ... } sub explode_plaintext_fromfile_into { ... } sub log_links { ... } sub informit { print STDOUT @_,"\n" } __END__

or something like this, all depending on how complicated the matching/extracting is and how it needs to be grouped , which parts are common/similar/alike/reusable

#!/usr/bin/perl -- use strict; use warnings; use MIME::Parser; ... Main( @ARGV ); exit( 0 ); sub Maincakes { ... my @files = get_files( $fromdir ); for my $file ( @files ){ iwant_iphone_links( $file ) or iwant_other_links( $file ) or iwant_pancake_links( $file ); } } sub iwant_iphone_links { ...; return $stop_or_keep_going } sub iwant_other_links { ...; return 1 } sub iwant_pancake_links { ...; return 0 } __END__

More of this type of idea of rewriting your code in Re: RFC: beginner level script improvement (version control), skimmable code is the idea, more subs, more subs, more subs, more subs, more subs,

More generic advice :) On debugging, verify everything, talk to teddybear ... checklists and more talking to yourself out loud is a pretty good debugging technique :) 1 / 2/3


In reply to Re: Perl MIME parser partially works with my code I wrote (code does not exist , there is no code) by Anonymous Monk
in thread Perl MIME parser partially works by CalebH

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.