in reply to add/replace map result into existing hash

G'day fredo2906,

I created some test input, before seeing your updated OP, as follows:

$ cat > pm_1075438_1.txt qw<er ty> a>sd <fgh $ gzip pm_1075438_1.txt $ cat > pm_1075438_2.txt <zxc vbn> 123> <456 $ gzip pm_1075438_2.txt

This script removes the need for the intermediary @o and @l:

#!/usr/bin/env perl use strict; use warnings; my %h; ++$h{$_} for map { chomp; $_ } `zcat @{[glob '*.gz']} | sed 's/[<> ]// +g'`; use Data::Dump; dd \%h;

Output:

{ 123456 => 1, asdfgh => 1, qwerty => 1, zxcvbn => 1 }

FWIW, this line:

++$h{$_} for map { chomp; s/[<> ]//g; $_ } `zcat @{[glob '*.gz']}`;

produces identical output. I'll leave you to benchmark (if you want).

-- Ken

Replies are listed 'Best First'.
Re^2: add/replace map result into existing hash
by fredo2906 (Acolyte) on Feb 20, 2014 at 00:10 UTC
    Thank you. Exactly what i needed.