As I see it you have two options: one that requires 'no strict qw/refs/' and one that works fine under use strict. Both of these use a simple foreach loop. (both of these examples are similar to the one ikegami posted in the read-more tags.)
Or do you really want a solution that uses map?
It is also my opinion that using eval for this is simply a bad idea... why use a complex, slow and dangerous (if used incorrectly) function for something soo simple?
First one: uses soft-reference, and does not work with lexical variables
no strict qw/refs/; foreach my $e (qw/a c b/) { if ($$e) { $combined .= $e . "=" . $$e; } }
Second one:
(You could write this one using one long list aswell, but then you would need to use a C-style for loop.)foreach my $e ( ["a", $a], ["c", $c], ["b", $b]/) { if ($e->[1]) { $combined .= $e->[0] . "=" . $e->[1]; } }
In reply to Re: Scalar joining, concatenation, involving varying text
by Animator
in thread Scalar joining, concatenation, involving varying text
by mhearse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |