Would be possible to have it without a loop
What's wrong with loops? They're low in fat, high in fiber... oh, nevermind.
use warnings; use strict; my $info = send_values({ name => 5, address => 6, id => 7, pic => 8, }); print $info; sub send_values { my ($args) = @_; my @params = qw( name address pic id zip phone ); my $values = "<results>\n"; for (@params) { $values .= " <$_>$args->{$_}</$_>\n" if exists $args->{$_ +}; } $values .= "</results>\n"; return $values; } __END__ <results> <name>5</name> <address>6</address> <pic>8</pic> <id>7</id> </results>

You could do the above without a loop, but it wouldn't be as scalable or as easy to maintain. For example, you would have to type 'address' 4 times instead of once:

$values .= " <address>$args->{address}</address>\n" if ex +ists $args->{address};

In reply to Re^3: Subroutine question on use of uninitialized value. by toolic
in thread Subroutine question on use of uninitialized value. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":