Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Scalar joining, concatenation, involving varying text

by Animator (Hermit)
on Jun 27, 2005 at 21:38 UTC ( [id://470393]=note: print w/replies, xml ) Need Help??


in reply to Scalar joining, concatenation, involving varying text

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:

foreach my $e ( ["a", $a], ["c", $c], ["b", $b]/) { if ($e->[1]) { $combined .= $e->[0] . "=" . $e->[1]; } }
(You could write this one using one long list aswell, but then you would need to use a C-style for loop.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://470393]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-25 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found