in reply to map and each?

my $gah = join ('<br>', map {"$_ = $somehash{$_}"} keys %somehash);
Does that do what you want? I don't know why the quotes around the entire expression are necessary, though, or if they're a Bad Idea for any reason. (For that matter, *why* is quoting a scalar a Bad Idea? Or is it just "useless?")

--

There are 10 kinds of people -- those that understand binary, and those that don't.

Replies are listed 'Best First'.
(jeffa) 2Re: map and each?
by jeffa (Bishop) on May 27, 2002 at 14:48 UTC
    The quotes are necessary here for variable interpolation which, according to The Camel(sec. ed.), is "really just a handy form of string concatenation". Try this instead:
    my $gah = join ("<br>", map {'$_ = $somehash{$_}'} keys %somehash);
    Big difference. Generally, double quoting scalars is a Bad Idea only if it is "useless". I see a lot of newbies trying silly things like:
    my $first = "Hello World\n"; my $second = "$first"; print "$second";
    Only the first set of double quotes are necessary for the special character "\n". So ,what harm is done with that example? None, but this behaviour usually stems from Cargo Cult Programming, and that's why it's a Bad Idea. Double quotes are good when used responsibly. Irresponsible use will lead to mistakes like thinking that an object ref is a scalar:
    use strict; use CGI; my $q = CGI->new(); print "$q->param('foo')\n"; # wrong print $q->param('foo'),"\n"; # right print $q->param('foo')."\n"; # right print "@{[$q->param('foo')]}\n" # right, but twisted ;)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)