where am i wrong?
...
print $#{$table}; ### why cant find the length of array here
Your syntax for "highest array index" by reference is correct (as are the more common variations given by poj here), but be aware of the fact (pointed out by poj) that the highest array index is not the same as the array length (i.e., number of elements) for the default value of $[ (see perlvar). (BTW: Don't ever touch $[ :)
c:\@Work\Perl\monks>perl -wMstrict -le "my $ar = [ qw(a b c d e) ]; ;; print $#{ $ar }; print $#${ ar }; print $#$ar; " 4 4 4
For readability and maintainability, I tend to prefer the for-loop approach used by poj for populating a hash from an array or array reference, but here's a variation that's a bit more terse:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $table = [ ['Wellbeing Office', 'Pending'], ['Library','Pending'], ['Y219','InProgress'], ['B201','InProgress'], ['B108','InProgress'], ['LAB1','InProgress'], ['C303','InProgress'], ]; ;; my %hdata = map @{ $_ }[0, 1], @$table ; ;; dd \%hdata; " { B108 => "InProgress", B201 => "InProgress", C303 => "InProgress", LAB1 => "InProgress", Library => "Pending", "Wellbeing Office" => "Pending", Y219 => "InProgress", }
Give a man a fish: <%-{-{-{-<
In reply to Re^3: how to save data to new array after retrieving from sql server
by AnomalousMonk
in thread how to save data to new array after retrieving from sql server
by mhoang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |