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

My perl has become rusty and i'm struggling with this.

how do i get at the data in my variable $info i've provided the result Dumper output?

for instance how would i get at the username key?

print Dumper($info); $VAR1 = { 'table' => [ [ 'CredSMB.168', '168', '1', 'Customer.1', '', 'BNS-NA-CA-SMB-SCGLOBAL', '3', 'SCGLOBAL', 'ip360scglobal' ] ], 'columns' => [ 'REFERENCE', 'id', 'type', 'customer', 'notes', 'name', 'authAlgorithm', 'domain', 'userName' ] };

Replies are listed 'Best First'.
Re: help me interpret Dumper output.
by toolic (Bishop) on Oct 08, 2009 at 15:15 UTC
Re: help me interpret Dumper output.
by SuicideJunkie (Vicar) on Oct 08, 2009 at 15:28 UTC
    $VAR1 = { #Variable is a hashRef 'table' => [ #One key is "table", # which gives an arrayref. [ #The first element in that array #is another arrayref 'CredSMB.168', #Element 0 # AKA $VAR1->{table}[0][0]; '168', '1', 'Customer.1', #Element 3 '', 'BNS-NA-CA-SMB-SCGLOBAL', '3', 'SCGLOBAL', 'ip360scglobal' ] ], 'columns' => [ #Another key is "columns", #which gives an arrayref. 'REFERENCE', # array element [0] 'id', 'type', 'customer', 'notes', 'name', 'authAlgorithm', 'domain', 'userName' ] };

    You might want to consider a simpler rearrangement:
    Have a hash where the keys are what is currently in 'columns' and the values are what is currently in 'table'.
    $rowHash->{id} = 168; for example.
    Depending on how you want to use them, you could make an array of such hashes, or a hash of those hashes (with the keys being some unique combination of data, such as the ID).

    By having just a hash of hashes, you can manipulate the "table rows" much easier.

    $rowHash = {id=>168, name=>'Jack'}; # create row $tableHash->{$rowHash->{id}} = $rowHash; # add row to table delete $tableHash->{$rowHash->{id}}; # delete row from table $tableHash->{168}{name} = 'Jill'; #update single value

      Thank you, actually i have no control over the data structure it's being returned from a call i simply need to get at what is there. re arrangement isn't an option. but thanks # AKA $VAR1->{table}[0][0]; is exactly what i needed. And to everyone else, thanks, i haven't been to this site in a number of years, but my memory was that the memebers were always extremely helpful and you still are!
Re: help me interpret Dumper output.
by kennethk (Abbot) on Oct 08, 2009 at 15:23 UTC
    userName is an array value, not a key. Assuming you mean the element in the table array that has the same index as the element in columns with the value 'userName', you'd need something like:

    #!/usr/bin/perl use strict; use warnings; my $VAR1 = { 'table' => [ [ 'CredSMB.168', '168', '1', 'Customer.1', '', 'BNS-NA-CA-SMB-SCGLOBAL', '3', 'SCGLOBAL', 'ip360scglobal' ] ], 'columns' => [ 'REFERENCE', 'id', 'type', 'customer', 'notes', 'name', 'authAlgorithm', 'domain', 'userName' ] }; foreach my $i (0 .. $#{$VAR1->{columns}}) { if ($VAR1->{columns}[$i] =~ /^userName$/) { print "$VAR1->{table}[0][$i]\n"; } }

    See perlref, perlreftut, perllol and/or perldsc for some refreshers.

Re: help me interpret Dumper output.
by planetscape (Chancellor) on Oct 08, 2009 at 21:14 UTC
Re: help me interpret Dumper output.
by jethro (Monsignor) on Oct 08, 2009 at 15:24 UTC
    ... and to handle the whole sub-array you would use:

    @columns= @{$info->{columns}};