Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • This might not help, but I remember hash slices as follows. First really it's just a hash:

    my $hashref = {a => 1, b => 2, c=> 3};

    # it's just a hash:

    Second we do our lookup:

    my @of_interest = qw(a c);


    Slices return lists, so we need an @ sign instead of the %:


    Which gives us:

    use strict;
    use warnings;

    my $hashref = {a => 1, b => 2, c=> 3};
    my @of_interest = qw(a c);

    print "@$hashref{@of_interest}\n";

    You can go the other direction too. If it were just a regular hash (no reference) you'd write:

    print "@hash{@of_interest}\n";

    Because there's that reference there, you need to add in that $. But this way seems to confuse people more.