I'm a bit stuck right now and was hoping for some divine monk intervention so I can kind of move past this current block that been eating away @ myt brain for the past 24 hours. I'm sure the answer is simple and I'm just not "seeing it" because I'm so caught up with the entire script.

I basically need to pass a hash to a subroutine and then iterate through the hash in the subroutine and email it's contents to myself. I used the Perl Cookbook's emailing recipe (18.3) because it seemed a bit easier then invoking SendMail directly (I don't know how to do that) - where I'm stuck is how to iterate through the hash and assign it to the $body variable so the hash contents can be sent via email. I know the snippet I'm including has a scoping problem.

Is there any way I could get some answers and just a short discussion of how to implement the solution properly and a way I could avoid this in the future. I'm sure it's a design problem - that's what I get for not being a programmer.

#!/usr/local/bin/perl -w use strict; use Mail::Mailer; my %hash = ( '742+evergreen+terrace' => '60516', '1094+evergreen+terrace' => '60187' ); notify(\%hash); sub notify { my $error_hash = shift; foreach my $address (keys %$error_hash) { $contents = "$address $error_hash->{$address}"; } my $from = 'system@system.com'; my $to = 'me@system.com'; my $subject = 'Warning'; my $body = $contents; my $mailer = Mail::Mailer->new("sendmail"); $mailer->open({ From => $from, To => $to, Subject => $subject, }) or die "Can't open: $!\n"; print $mailer $body; $mailer->close(); }

In reply to Iterating Through a Hash and Emailing the Result by bivouac

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.