in reply to Re^2: Hash vs constant vs package vs other for data structure
in thread Hash vs constant vs package vs other for data structure

What are the advantages of the hash method?

Two that I can think of off the top of my head are that you can have sparse property sets (e.g. if one object has {foo=>1,bar=>2} and the other has {quz=>1,baz=>2}, whereas you'd need four array elements to cover that, a bit of a waste), and that textual serializations of the data would be self-documenting. But if neither of those are a concern to you, then at the moment I can't think of major disadvantages to using constants for the array indicies.

Replies are listed 'Best First'.
Re^4: Hash vs constant vs package vs other for data structure
by oldtechaa (Beadle) on Mar 27, 2017 at 19:46 UTC
    I don't really need either of those, but I also would like to assign to slices, which would be difficult with a hash. I think I'll go with the constant method or uppercase variables probably.
      Constants set up with constant are inlined by the compiler (Constant Functions) and should be a little bit faster, and "safer" (no one can accidentally change your variables).
      I also would like to assign to slices, which would be difficult with a hash.

      It works:

      $ perl -MData::Dump -e '@{$x[0][0]}{qw/a b/} = qw/c d/; dd \@x' [[{ a => "c", b => "d" }]]
        Seems almost more complicated than my initial problem.
      When faced with a choice which makes little difference, choose one and use it consistently on all future projects. (This restriction may influence your choice.)
      Bill