The data structure that you create is probably not what you think. A lot goes on behind the scene in your initialization. I have expanded the initialization to more clearly show the same structure. The variable "@arr" is an array with only one element. That element is a reference to an anonymous array with five elements (The first four are undefined). The last element is a reference to an anonymous array with four elements (Your data).

Dumper requires scalar arguments. You have provided an array. Perl expands this to a list with only one element (which is a reference). Dumper displays the object of that reference. The argument to Dumper should be a reference to @arr to force Dumper to parse the entire structure.

I am not going to tell you how to get rid of the message about prototypes (You may be tempted to use them). Remove the prototype "()" from your subroutine definition.

You are passing a single argument to the subroutine. That argument is a reference to an anonymous array. A subroutine finds its arguments in the array @_. You only have one argument so it is in $_[0]. You must dereference this to get your values.

use warnings; use Data::Dumper; my @array; @arr = ( [ undef, undef, undef, undef, ['S', 'M', 'R', 'B'], ] ); print Dumper \@arr; my ($VAR1,$VAR2,$VAR3,$VAR4) = @{$arr[0][4]}; print "Var1: $VAR1\tVar2: $VAR2\tVar3: $VAR3\tVar4: $VAR4\n"; Testing($arr[0][4]); sub Testing { my ($VAR5,$VAR6,$VAR7,$VAR8) = @{$_[0]}; print "Var5: $VAR5\tVar6: $VAR6\tVar7: $VAR7\tVar8: $VAR8\n"; }

OUTPUT:

$VAR1 = [ [ undef, undef, undef, undef, [ 'S', 'M', 'R', 'B' ] ] ]; Var1: S Var2: M Var3: R Var4: B Var5: S Var6: M Var7: R Var8: B
Bill

In reply to Re: Assign valuse of array within array to variables by BillKSmith
in thread Assign valuse of array within array to variables by g_speran

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.