I have a MySQL table with following structure.
alid bigint(20),
ndip varchar(20),
ndregion varchar(20),
occ_num int(3),
Delta_Flag int(1)
After selecting data from the table, I am getting all the data quoted and as a string value.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use FindBin;
use lib $FindBin::Bin;
use Database;
my $pwd = $FindBin::Bin;
my $db = Database->new( 'mysql', "$pwd/config.ini" );
my $db1 = Database->new( 'mysql', "$pwd/config2.ini" );
my @tables = qw( AutoTT_AlarmStatus_Major1 );
for my $table ( @tables ) {
my $query_select = "SELECT alid, ndip, ndregion, occ_num, Delta_Flag FROM $table LIMIT 1";
my $result = $db->db_get_results( $query_select );
print Dumper( $result );
for my $item ( @{$result} ) {
# Here I want to prepare, bind and insert this data
# into other table with same structure
}
}
Database.pm
sub db_get_results {
my $self = shift;
my $qry = shift;
my $sth = $self->{dbh}->prepare( $qry );
$sth->execute();
my @return = ();
while ( my @line = $sth->fetchrow_array ) {
push @return, \@line;
}
return \@return;
}
Output:
$VAR1 = [
[
'1788353',
'10.34.38.12',
'North Central',
'1',
'1'
]
];
Why is DBI
implicitly converting all integers to strings?
Data::Dumper
to view the data then you would have found it very difficult to discover whether you had strings or integers. Why don't you just try it?