in reply to Re^2: how to save data to new array after retrieving from sql server
in thread how to save data to new array after retrieving from sql server
$#{$table} should be either $#${table} or just $#$table
$table is an arrayref so these
should bemy $location = $table[i]->[0]; # missing $ on i my $room = $table[i]->[1];
my $location = $table->[$i][0]; my $room = $table->[$i][1];
and push is for building an array not a hash, so this
push $hdata{$location}=$room;should be
$hdata{$location} = $room;or alternatively
poj#!/usr/bin/perl use strict; use Data::Dump 'pp'; my $table = [ ['Wellbeing Office', 'Pending'], ['Library','Pending'], ['Y219','InProgress'], ['B201','InProgress'], ['B108','InProgress'], ['LAB1','InProgress'], ['C303','InProgress'], ]; my $last_index = $#${table}; my $count = scalar @$table; print " records = $count last index = $last_index\n"; #my %hdata = (); #for my $i (0..$last_index){ # my $location = $table->[$i][0]; # my $room = $table->[$i][1]; # $hdata{$location} = $room; #} #pp \%hdata; my %hdata = (); for my $row (@$table){ my $location = $row->[0]; my $status = $row->[1]; $hdata{$location} = $status; } pp \%hdata;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: how to save data to new array after retrieving from sql server
by mhoang (Acolyte) on Aug 02, 2017 at 02:50 UTC | |
by poj (Abbot) on Aug 02, 2017 at 06:04 UTC | |
by mhoang (Acolyte) on Aug 02, 2017 at 23:35 UTC |