No, but you can do what you want by other means.

A reference is a reference. It's value is something like ARRAY(0xhhhhhhh) or CGI=HASH(0xhhhhhhhh), i.e. blessings if any, type and an address. All references are scalars. Their value determines what operations can be done on their referent.

To deal correctly with references, dereference them to the referent's type, and apply the methods of that type. Hint: look at the precedence of dereferencing operators alongside the type operations. Also, it matters whether the referent is anonymous.

Here's some code to play with. If you duplicate the error case code you can see what your experiments do.

The listing:
___

#!/usr/bin/perl -w # -*-Perl-*- use strict; use CGI; my $cgi = new CGI(); # Just for the reference my $hrf = { 'a'=>['alpha','start','soup'], 'b'=>['beta','middle','fish'], 'z'=>['omega','finish','nuts'], }; my $n = "\n"; print "Value of my \$cgi:\t",$cgi,$n,$n; print "Successive dereferences of a reference to a\n"; print "hash of references to arrays:\n"; print "\$hrf:\t",$hrf,$n; print "\$hrf->{'a'}:\t",$hrf->{'a'},$n; print "\$hrf->{'a'}->[1]:\t",$hrf->{'a'}->[1],$n; print "\nTry forcing our \$hrf to be to an array:\n"; print "\@{\$hrf}[2]:\t"; print eval{@{$hrf}[2]} || $@, $n; print "Pole to polar phrases:$n"; for my $idx (0..2) { print join(' to ', map {$hrf->{$_}->[$idx]} sort keys %{$hrf} ),$n +; } print $n; print "Our slice of the menu is:$n"; for ((sort keys %{$hrf})[0,-1]) { print @{$hrf->{$_}}[0, -1],"\n"; }

The output:
___

Value of my $cgi: CGI=HASH(0x80cb854) Successive dereferences of a reference to a hash of references to arrays: $hrf: HASH(0x8173438) $hrf->{'a'}: ARRAY(0x80cb824) $hrf->{'a'}->[1]: start Try forcing our $hrf to be to an array: @{$hrf}[2]: Not an ARRAY reference at ./refs line 22. Pole to polar phrases: alpha to beta to omega start to middle to finish soup to fish to nuts Our slice of the menu is: alphasoup omeganuts

After Compline,
Zaxo


In reply to Re: Can you take a slice of an array reference? by Zaxo
in thread Can you take a slice of an array reference? by princepawn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.