Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Scalar joining, concatenation, involving varying text

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.