in reply to Re: setting values in anonymous hash
in thread setting values in anonymous hash

I had no intention of calling you guilty -- I was honestly wondering about the whole hash-in-list-context thing. I have used this "feature" myself before but long ago, before I started using -w and strict. Since then I've always felt oddly guilty using hashes like that -- that I was obfuscating, which isn't usually a good idea when you are using code for "real" purposes.

  • Comment on Re: Re: setting values in anonymous hash

Replies are listed 'Best First'.
Re: setting values in anonymous hash
by Dominus (Parson) on Nov 28, 2000 at 23:26 UTC
    Says snax:
    > I had no intention of calling you guilty
    Oh, I didn't mean that. I meant that you were calling the code guilty.

    Anyway, I agree with you that the use of the hash as an argument to map is a little weird, and possibly obfuscated, because it's not clear what is going to happen to the keys.

      Well, between your snippet and merlyn's, and a CB comment by tye, I've come to a much greater understanding of what's going on. I think :)

      If I'm understanding properly, you could do anything to the keys in this setting, because they're just strings and you can't get references to them to allow their modification, which is how the values get modified.

      That's what my test code suggests, anyway:

      #!/usr/local/bin/perl -w use strict; my $ref={ a => 'aa', b => 'bb'}; print "The hash, before:$/"; print %$ref; print qq($/The hash "during":$/); for (%$ref) { /[A-Z]/ or $_ = 'x'; print; } print "$/The hash, after:$/"; print %$ref; print $/; __END__ The hash, before: aaabbb The hash "during": xxxx The hash, after: axbx
      This is perl, v5.6.0, BTW.