Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have set up a hash:
my %results; my $results; my $interventions = $worksheet->Range("Y10:Y49")->{'Value'}; .... $results{$file}{$month}{fullTimeEducation} = @$interventions[0];
but I cannot get the data out. e.g.

.... print "$results{$value}{August}{fullTimeEducation}";


produces

ARRAY(0x1be4260)

Replies are listed 'Best First'.
Re: Getting data out of hash
by !1 (Hermit) on Nov 17, 2003 at 15:16 UTC

    It appears that $interventions->[0] is an arrayref. You can double check by using the Dumper subroutine of Data::Dumper. However, you should be able to fix this with:

    print "@{$results{$value}{August}{fullTimeEducation}}";

    I hope this helps you with your problem.

Re: Getting data out of hash
by hardburn (Abbot) on Nov 17, 2003 at 15:25 UTC

    @$interventions[0] isn't really what you want. Try $interventions->[0] instead.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

Re: Getting data out of hash
by Anonymous Monk on Nov 17, 2003 at 15:22 UTC
    Thank you.
Re: Getting data out of hash
by ptkdb (Monk) on Nov 17, 2003 at 15:14 UTC
    Try:

    print @{$results{$value}{August}{fullTimeEducation}};
    Not familiar with the particular module that you're using, but I'm pretty sure that you're trying to output something that's an array-ref. Putting that result in @{} will force it back into a list context, so that when it's 'stringified' it will print out each element.

    If the elements of this array are further refs, you'll see more "ARRAY(0xDEADBEEF)" "HASH(0xDEADBEEF)" outputs, so you'll have to think about writting some kind of formatting routine.

      Putting that result in @{} will force it back into a list context

      The @{} dereferences the reference to an array regardless of context. Also, if it was list context then shouldn't @{} return the last element of the array in scalar context? Observe:

      #!/usr/bin/perl -wl use strict; sub list { return qw(a b c); # real list } my $a_ref = [qw(a b c)]; $, = $"; print "list", @{$a_ref}; print "list", list(); print "scalar " . @{$a_ref}; print "scalar " . list(); __END__ list a b c list a b c scalar 3 scalar c

      An arrayref dereferences to an array, not a list. Sure, they're similar but they don't behave the same.