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

True, but why not do this:

sub format_email_text { return join("\n", sprintf("%-30s %-50s", "Player Name:", $player), sprintf("%-30s %-50s", "Parent's Name:", $parent), sprintf("%-30s %-50s", "Member ID:", $memberid), ); } ... $text = format_email_text(); ...

It would probably be cleaner if the data was passed as arguments, too:

sub format_email_text { my ($player, $parent, $memberid) = @_; return join("\n", sprintf("%-30s %-50s", "Player Name:", $player), sprintf("%-30s %-50s", "Parent's Name:", $parent), sprintf("%-30s %-50s", "Member ID:", $memberid), ); } ... $text = format_email_text($player, $parent, $memberid); ...

Replies are listed 'Best First'.
Re^3: Format text problem
by b310 (Scribe) on Apr 02, 2005 at 20:29 UTC
    Hi,

    In reply to your second method, the result that appears in my email looks like: print format_email_text(Minnie Mouse, Mickey Mouse, 78787);

    Each variable should appear underneath each other.
      I adjusted it so the result is saved in $text instead of being printed.
Re^3: Format text problem
by b310 (Scribe) on Apr 02, 2005 at 20:45 UTC
    Hi,

    It worked perfectly. Oh, thank you so much.

    Can you explain to me what the "join" portion of the code is doing?

    Thanks for your help.

      join($sep, $string1, $string2, $string3)
      is the same thing as
      $string1 . $sep . $string2 . $sep . $string

      In other words, it takes a list and/or array of strings, and combines them into one long string. The first argument is a seperator. It's inserted bewteen every string in the list. The core perl functions (including join) are documented in perlfunc.

        Hi,

        Thanks.