Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: how do I edit multiple variables at once?

by liverpole (Monsignor)
on Jul 04, 2009 at 03:08 UTC ( [id://777160]=note: print w/replies, xml ) Need Help??


in reply to how do I edit multiple variables at once?

Hi keiusui,

I would suggest using a hash (or, as in the following example, a hash reference) to contain those variables, in conjunction with map, like this:

use strict; use warnings; my $h_vars = { 'name' => '<h1>Fred Flintstone</h1>', 'location' => 'Bedrock', 'favorite movie' => 'One <i>Million</i> Years B.C.', 'favorite book' => 'Danny the <b>Dinosaur</b>', }; map { s/\</\&lt\;/g; s/\>/\&gt\;/g } values %$h_vars; # Test code use Data::Dumper; printf "Results %s\n", Dumper($h_vars); __END__ Results $VAR1 = { 'location' => 'Bedrock', 'favorite movie' => 'One &lt;i&gt;Million&lt;/i&gt; Years B. +C.', 'name' => '&lt;h1&gt;Fred Flintstone&lt;/h1&gt;', 'favorite book' => 'Danny the &lt;b&gt;Dinosaur&lt;/b&gt;' };

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: how do I edit multiple variables at once?
by merlyn (Sage) on Jul 04, 2009 at 03:23 UTC
    Please.
    map { s/\</\&lt\;/g; s/\>/\&gt\;/g } values %$h_vars;
    No void maps please. This is even shorter:
    s/\</\&lt\;/g, s/\>/\&gt\;/g for values %$h_vars;

    -- Randal L. Schwartz, Perl hacker

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-24 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found