Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Perl Programming Language

How do I get the data out of this array?

In the Perl Debugger a variable $vc looks like this:

  DB<1> p $vc
  DB<2> x $vc
0  ARRAY(0x19d1f9c)
   0  ARRAY(0x19e0694)
      0  2.0
      1  3.0
   1  ARRAY(0x19e064c)
      0  7.0
      1  6.0
   2  ARRAY(0x19e067c)
      0  8.0
      1  12.0

How to I get :
2 3
7 6
8 12


At a command prompt run
    perldoc perlref
and learn all about references. That should give you the knowledge you
need to understand your data structure above.

To give you a clue:
   print $vc->[0][0]

On Jun 4, 11:11 pm, "gimme_this_gimme_t@yahoo.com"

This tells you that $vc is a reference to an array.  The array that
$vc references contains three elements.  Each of those elements are
also references to arrays.  The arrays that *those* references
reference contain two elements each, all numbers.

Please see:
perldoc perlreftut

> How to I get :
> 2 3
> 7 6
> 8 12

Step by step:
$vc is a reference to an array
@{$vc} is the array that $vc references
${$vc}[0] is the first element of @{$vc}
The arrow rule lets us write that as $vc->[0]
$vc->[0] is also a reference to an array.
@{$vc->[0]} is the array that $vc->[0] references.  This array
contains (2, 3);

So you could do a loop like the following:
foreach my $ref (@{$vc}) {
  #here, $ref is one of the "inner" references
  foreach my $elem (@{$ref}) {
     print "$elem ";
  print "\n";


Once you understand the above, you can make it much more concise:

foreach my $ref (@$vc) {
  print "@{$ref}\n";


Hope this helps,
Paul Lalli

P.S.  The final example presumes you've not mucked with the $"

Thanks Paul.

You're a pro.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc