I'm trying to use /usr/lib/kbd/ keymaps to create svgalib keymap. I'm trying to process keymap_file1 and all included keymaps and collect data into single hash, then fully load keymap_file2 and produce mapping table from keymap_file1 to keymap_file2. How can I use the same hash to collect all the values? Now only the values from the last file processed are on hash.
#!/usr/bin/perl use warnings; use strict; sub load_keymap { my $file_name = shift; my %keymap = %{$_[0]}; my $line; local *IN; $file_name ="gzip -dc $file_name |" if $file_name =~ /\.gz$/; print "Loading $file_name...\n"; open (IN, $file_name) or die "Could not open $file_name: $!"; while (defined($line = <IN>)) { if ($line =~ /include "(.+)"/) { load_keymap("$1.inc.gz", \%keymap); } next if $line !~ /keycode\s+(\d+)\s*=\s*(\S+)/; $keymap{$2} = $1; #print "$2 = $1\n"; } close(IN); return \%keymap; } my (%map_from, %map_to) = (); my $key = 0; $key = load_keymap("de.kmap.gz", \%map_from); %map_from = %$key; foreach $key (keys %map_from) { print "$key = $map_from{$key}\n"; }

In reply to Recursion + hash by karmas

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.