SPUG: How to use database variable in place of other variable

Matt Tucker tuck at whistlingfish.net
Thu Mar 14 14:10:18 CST 2002


-- James Moore <james at banshee.com> spake thusly:

> First off, you're setting $mail{To} to $email - that's dollar sign
> email.  You probably want to set it to the contents of the email
> variable, so just leave off the ':  To => $email instead of To =>
> '$email'.  You could do
> To => "$email", but there's no reason to in this case.

Another example of this is in:

    Subject => 'Your $row[10] Mailing Information',

This should be in double-quotes. So that $row[10] is interpolated into
the string.

Another comment I had was on the sample code:

    my $email = "$row[12]";

I see this sort of thing done frequently, and I consider it bad style.
I'm not sure how much extra work it creates for Perl (probably just a
string copy, and maybe it's optimized out), but there's really no point
in including those double quotes, since you'll get exactly the same
thing without them.

In this particular example, you could even do:

    %mail = (
        To      => $row[12],
        From    => 'someemail at someplace.com',
        Subject => "Your $row[10] Mailing Information",
        Message => "Some message information"
     );

and dispense with the $email variable entirely. Some people would
prefer keeping it, since it makes the script more readable. I actually
prefer to do fetchrow_arrayref(), since that makes the script even more
readable:

    %mail = (
        To      => $row->{email},
        From    => 'someemail at someplace.com',
        Subject => "Your $row->{info} Mailing Information",
        Message => "Some message information"
     );


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list