in reply to Re: Format text problem
in thread Format text problem

Hi,

I applied your suggestion to my script.

The variables $player to $event line up perfectly. All the variables starting with $street are not lining up at all.

This is the subroutine that generates the result:
sub send_confirmation_email { my $text = format_email_text(30,50, "Player Name", $player, "Parent's Name", $parent, "Member ID", $memberid, "Email Address", $email, "Camp Date(s)", $dates, "Camp Event", $event, "Street", $street, "City", $city, "State", $state, "Zip Code", $zip, "Payment Method", $payment, "Message", $message); my %mail = ( From => "info\@anywhwere.com", To => $email, Subject => "Registration", Message => "" ); my $page; $mail{Message} = <<EOF; This is the information you submitted. $text EOF sendmail (%mail) or $page .= p (escapeHTML ("Oops, failure sending mail to $mai +l{To}")); return (defined ($page) ? $page : ""); }

Plus, this is the subroutine you gave me:
sub format_email_text { my ($name, $val, $out, $nd, $vd); $nd = shift; $vd = shift; while ($name = shift) { $val = shift; $out .= sprintf('%-'.$nd.'s %-'.$vd.'s', "$name:", $val) . "\n +"; } return $out; }

Any ideas why some of the variables are appearing differently?

Also, can you explain to me what your code is doing? I'm not sure what this line is doing:
sprintf('%-'.$nd.'s %-'.$vd.'s',
Thanks.

Replies are listed 'Best First'.
Re^3: Format text problem
by nobull (Friar) on Apr 03, 2005 at 12:46 UTC
    Any ideas why some of the variables are appearing differently?
    No. Perhaps it's something that's happinging after the fact. Try printing out $text before you construct the mail and seeing if it layed out correctly.
    I'm not sure what this line is doing:
    sprintf('%-'.$nd.'s %-'.$vd.'s',
    Rathar than ask us to explain everything you could possibly being having trouble understanding, it would more efficient if you could be more precise about what about this you are finding difficult to understand.
    • Something documentation for the sprintf()
    • The effect of '-' in printf templates?
    • Concatenation of strings using the . operator?
    • Something else...?