Stories
Slash Boxes
Comments
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.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Seems to be returning the the last part:

    DB<13> @r = qw(this that these 17)

    DB<14> x {%$r}{@r}
    0  'this'
    1  'that'
    2  'these'
    3  17

    DB<15> x {@r}
    0  'this'
    1  'that'
    2  'these'
    3  17

    DB<16> x @r
    0  'this'
    1  'that'
    2  'these'
    3  17

    • You're right. I'm getting keys, not values. I should pay more attention to detail. :)

      So what about the debugger is making it ignore the first part in braces, I wonder.

      --
      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
  • 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:
    %$hashref;

    Second we do our lookup:

    my @of_interest = qw(a c);

    %$hashref{@of_interest};

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

    @$hashref{@of_interest};

    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 di

  • The expression you're supplying to the debugger is being parsed as a block:

    tony@zeus:~$ perl -MO=Deparse -e '{%$r}{@f}'
    {
            %$r;
    }
    {
            @f;
    }
    -e syntax OK

    eval()ling the same expression gives the result you saw in the debugger:

    tony@zeus:~$ perl -e '$r = { this => "that", these => 17 }; @f = qw(this these); @foo = eval q"{%$r}{@f}"; use Data::Dumper; print Dumper \@foo'
    $VAR1 = [
                        'this',

    • Ah! Thank you for the explanation!

      --
      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers