bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
I'm reading in a tab delimited text file exported from Excel. The 12th "position" contains a simple 3 or 4 digit number. For some reason that number is coming in as a string, or something I'm not familiar with, and unusable as a number. This is from Dumper:
$VAR1 = [ '1130',
My database query was returning zip so I tested for the veracity of the uniq_id in line 78. The error is:
Argument "\01\01\03\00\0" isn't numeric in multiplication (*) at ./map +tobuildforums.pl line 78.
I did a hex dump and the number looks fine:
1130 = 31 31 33 30
Here's the code:
... use List::MoreUtils qw(uniq); open($fh, '<', 'filetoparse.txt') or die "error $!"; chomp(my @lines = <$fh>); close $fh; my @old_ids; foreach my $line (@lines) { @data = split(/\t/, $line); push @old_ids, $data[12]; } my @uniq_ids = uniq (@old_ids); #get unique ids #step through unique ids for new id using old ids for my $i (0..$#uniq_ids) { print $uniq_ids[$i] * 1; #line 78 of my code to test for a number my $stmt = "SELECT * FROM temp_topics WHERE old_id = ?"; my $topic = $dbh->selectrow_hashref($stmt, undef, $uniq_id[$i]); etc. }
Thoughts on how to handle this?
—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Turning a questionable string into a number
by choroba (Cardinal) on Jun 29, 2017 at 19:15 UTC | |
Re: Turning a questionable string into a number
by tybalt89 (Monsignor) on Jun 29, 2017 at 19:12 UTC | |
Re: Turning a questionable string into a number
by haukex (Archbishop) on Jun 29, 2017 at 19:23 UTC | |
by bradcathey (Prior) on Jun 29, 2017 at 19:40 UTC | |
by haukex (Archbishop) on Jun 29, 2017 at 19:53 UTC | |
by choroba (Cardinal) on Jun 29, 2017 at 20:00 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Back to
Seekers of Perl Wisdom