focus310 has asked for the wisdom of the Perl Monks concerning the following question:

Hello: I have a piece of code which holds values in an array. I want to format the results when they are being called to print. Right now, it just prints the name and the value for that name. Example: email: test@email.com. I would like to at least make the word "email" appear in bold or capitalize the first letter.

How do I do that? Thank you in advance for all the help. I posted all portions of the code which leads up to the final printing. I believe this is the line of code which prints the results: return ("$name: ", $value);

sub send_main_email_body_header { my ($self, $date) = @_; my $dashes = '-' x 75; $dashes .= "\n\n" if $self->{CFG}{double_spacing}; $self->mailer->print(<<END); This is the information which was submitted. END } sub send_main_email_print_config { my ($self) = @_; if ($self->{FormConfig}{print_config}) { foreach my $cfg (@{ $self->{FormConfig}{print_config} }) { if ($self->{FormConfig}{$cfg}) { $self->mailer->print("$cfg: $self->{FormConfig}{$cfg}\n"); $self->mailer->print("\n") if $self->{CFG}{double_spacing}; } } } } sub send_main_email_fields { my ($self) = @_; foreach my $f (@{ $self->{Field_Order} }) { my $val = (defined $self->{Form}{$f} ? $self->{Form}{$f} : ''); $self->send_main_email_field($f, $val); } } sub send_main_email_field { my ($self, $name, $value) = @_; my ($prefix, $line) = $self->build_main_email_field($name, $value); my $nl = ($self->{CFG}{double_spacing} ? "\n\n" : "\n"); if ($self->{CFG}{wrap_text} and length("$prefix$line") > $self->emai +l_wrap_columns) { $self->mailer->print( $self->wrap_field_for_email($prefix, $line) +. $nl ); } else { $self->mailer->print("$prefix$line$nl"); } } sub build_main_email_field { my ($self, $name, $value) = @_; return ("$name: ", $value); }

Replies are listed 'Best First'.
Re: Formatting Help
by Melly (Chaplain) on Mar 22, 2006 at 11:48 UTC

    Not, imho, really enough info, but I'd guess that you might want (for uppercase first char):

    sub build_main_email_field { my ($self, $name, $value) = @_; $name = ucfirst $name; return ("$name: ", $value); }

    Bold will depend on where you are displaying the value - if html, then (although not really bold):

    $name = '<em>' . $name . '</em>';
    Tom Melly, tom@tomandlu.co.uk
Re: Formatting Help
by timos (Beadle) on Mar 22, 2006 at 11:49 UTC
    What do you mean by "appear in bold or capitalize"? To turn a string $foo into uppercase, just use $foo = uc $foo; To print in different color or something similar in the Terminal use
    use Term::ANSIColor; print color 'bold blue'; print "This text is bold blue.\n";
    which will print the line "This text is bold blue" in bold blue of course. :-)