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.