Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Mystery character in hash key name

by fiddler42 (Beadle)
on Sep 08, 2009 at 19:11 UTC ( #794202=perlquestion: print w/replies, xml ) Need Help??

fiddler42 has asked for the wisdom of the Perl Monks concerning the following question:


I am building a couple of different hash tables like so (notice the 4 separate variables in the key name, starting with $F):-

$TotalMatchesHash{$F,$BBEL,$AR,$VL} = $MatchCount;

I am able to do everything I need to do with the hash tables, like find matching keys, process results, etc. But I running into a problem as I wrap up my routine: when I print the key names, I see this:-

original key is 5<fs>19<fs>56<fs>46

...and I cannot work around the <fs> characters, and it is important that I retrieve those 4 original variable values (all integers).

Any suggestions? The code below reveals what I am trying to do. Notice the split line that references <fs>, which does NOT work...



foreach (keys %NewRFactorAverageHash) { $RScale = $NewRFactorAverageHash{$_}; print ("original key is $_\n"); @LaL = split (/<fs>/, $_); print ("new key is $LaL\n"); $F = $LaL[0]; $BBEL = $LaL[1]; $AR = $LaL[2]; $VL = $LaL[3]; }

Replies are listed 'Best First'.
Re: Mystery character in hash key name
by Roy Johnson (Monsignor) on Sep 08, 2009 at 19:22 UTC
    See the $; variable. You'll want to split on that instead of <fs>. Also, printing $LaL isn't going to be helpful, since you're splitting to @LaL.

    Caution: Contents may have been coded under pressure.

      That was it! This works:-

      foreach (keys %NewRFactorAverageHash) { $RScale = $NewRFactorAverageHash{$_}; $F = 0; $BBEL = 0; $AR = 0; $VL = 0; print ("original key is $_\n"); @LaL = split (/$;/, $_); print ("new key is @LaL\n"); }

      BTW, notice I replaced "new key is $LaL" with "new key is @LaL"...the original post was a typo.

      Thanks again!


      Interestingly enough, the $; variable on my system (Debian GNU/Linux, Perl 5.10.0) is 0x1c, the ASCII FS (file separator) character. Who'da thunkit?

      print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))
Re: Mystery character in hash key name
by SuicideJunkie (Vicar) on Sep 08, 2009 at 19:22 UTC

    Did you forget to use strict; use warnings;?
    You should have been notified that $LaL is not declared or defined.

    You are setting @LaL with the split, but then printing the completely unrelated variable $LaL.

    - SJ

    How to make resizable too!
    The monks can fry your fish, and they can give you some tips and some bait, but you still need to wake up in the morning and climb onto the boat.
Re: Mystery character in hash key name
by moritz (Cardinal) on Sep 08, 2009 at 19:25 UTC
    $TotalMatchesHash{$F,$BBEL,$AR,$VL} = $MatchCount;

    This just concatenates the four variables and uses the result as a hash key. If they are all integers, you can't retrieve the previous values from that hash key unless you happen to know their lengths.

    Update: That was actually wrong; see the other replies.

    I strongly recommend to dump your hash like this:

    use Data::Dumper; $Data::Dumper::Useqq = 1; ... print Dumper \%NewRFactorAverageHash;

    This will escape non-printable characters in a meaningful way.

    Perl 6 - links to (nearly) everything that is Perl 6.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://794202]
Approved by moritz
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2023-06-04 11:26 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (21 votes). Check out past polls.