in reply to Re^2: Selecting Ranges of 2-Dimensional Data
in thread Selecting Ranges of 2-Dimensional Data

Honestly I wouldn't have implemented it your way in order to have a higher degree of reusability and readability.

For instance

OTOH I tend to get lost in abstraction. .. ;)

> Of course, @_!

It's a hack I once learned from Ikegami++, but it seems to be reliable.

Though not many people know if it depends on an implementation detail.

And unfortunately I don't think it can be used to alias hashes (i.e. values) too.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

  • Comment on Re^3: Selecting Ranges of 2-Dimensional Data

Replies are listed 'Best First'.
Re^4: Selecting Ranges of 2-Dimensional Data
by haukex (Archbishop) on Oct 28, 2018 at 09:16 UTC
    Honestly I wouldn't have implemented it your way in order to have a higher degree of reusability and readability.

    Yeah, I wrote it to be kind of compact - I want to hide it away in a pm and not worry about it anymore (hence all the the tests). My application has limited scope, definitely only 2D data (fiddling with CSV), and I'm probably going to hide it away in a class so that the implementation can be upgraded later if necessary, or maybe replaced with an existing module (hence this thread).

    Though not many people know if it depends on an implementation detail.

    Hm, well I found this thread by tye where it sounds like it's probably reliable, and a whole bunch of other threads where it's a suggested technique. I just tested on Perl 5.6 up to 5.28, it works fine on all of them.

    And unfortunately I don't think it can be used to alias hashes (i.e. values) too.

    It can :-) Also:

    $ perl -wMstrict -MData::Dump -le 'my %h=("a".."j"); my $x=sub{\@_}->(@h{"c","e","g"}); $_=uc for @$x; dd \%h' { a => "b", c => "D", e => "F", g => "H", i => "j" }
      > It can :-)

      Unfortunately not, $x is an array ref not a hash ref.

      ( I got that far already :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        Unfortunately not, $x is an array ref not a hash ref.

        Ah, I see what you mean. If I had to work with a subset of a hash, I'd probably just work with that hash directly and only operate on a subset of the keys (various ways to do that)... arrays are a little different in that respect. Anyways, refaliasing works:

        $ perl -wMstrict -Mexperimental=refaliasing -MData::Dump -le ' my %h=("a".."f"); my %x; \$x{c}=\$h{c}; $x{c}="X"; dd \%h' { a => "b", c => "X", e => "f" }