Array Question

A

amerar

Hey All,

Got a quick issue here. I have a script at work, it throws the
following error:

Argument "" isn't numeric in printf at ./saba.pl line 151, <BFILE> line
1.

Here is line 151:

printf FAN "@work_format\n",@d_ar;

Now, this is where it get crazy. @work_format is a FORMAT that looks
like this:

my @work_format=qw/%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s
%s %s %s %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f/;


My question is, how the hell do I know which element is throwing the
error?? I've dumped the array, which looks like this:

158: +000000000000000.000
159: +000000000000010.000
160: +000000000000000.000
161: +000000000002200.000
162: +000000000000000.000
163:
164: +000000000005000.000
165:
166: +000000000000000.000

Those are elements of the array. It works with all other records in
the file except for this one. How do I know which format is throwing
the error????

Can anyone help? I've been at this for 4 days now.....

Thanks in advance!!
 
J

John W. Krahn

Got a quick issue here. I have a script at work, it throws the
following error:

Argument "" isn't numeric in printf at ./saba.pl line 151, <BFILE> line
1.

Here is line 151:

printf FAN "@work_format\n",@d_ar;

Now, this is where it get crazy. @work_format is a FORMAT that looks
like this:

my @work_format=qw/%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s
%s %s %s %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f

[ snip ]
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f
%.3f %.3f %.3f/;


My question is, how the hell do I know which element is throwing the
error?? I've dumped the array, which looks like this:

158: +000000000000000.000
159: +000000000000010.000
160: +000000000000000.000
161: +000000000002200.000
162: +000000000000000.000
163:
164: +000000000005000.000
165:
166: +000000000000000.000

Those are elements of the array. It works with all other records in
the file except for this one. How do I know which format is throwing
the error????

Can anyone help? I've been at this for 4 days now.....

If you want to check the array for non-numbers:

use Scalar::Util 'looks_like_number';

print "Checking values in \@d_ar.\n";
for my $index ( 0 .. $#d_ar ) {
unless ( looks_like_number $d_ar[ $index ] ) {
print "Index at $index is not a number.\n";
}
}


If you want to get the printf format correct without the huge array:

my $work_format = join ' ', ( '%s' ) x 20, ( '%.3f' ) x ( @d_ar - 20 );

printf FAN "$work_format\n", @d_ar;





John
 
T

Tad McClellan

following error:


It is a warning message, not an error message.

Argument "" isn't numeric in printf at ./saba.pl line 151, <BFILE> line
^^
^^

Looks like you have an empty string somewhere.

Here is line 151:

printf FAN "@work_format\n",@d_ar;

Now, this is where it get crazy. @work_format is a FORMAT that looks
like this:

my @work_format=qw/%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s
%s %s %s %.3f %.3f %.3f %.3f
%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f

[ snip a whole bunch more ]

My question is, how the hell do I know which element is throwing the
error??


By dumping the array.

I've dumped the array,


Good idea.

which looks like this:

158: +000000000000000.000
159: +000000000000010.000
160: +000000000000000.000
161: +000000000002200.000
162: +000000000000000.000
163:
164: +000000000005000.000
165:
166: +000000000000000.000

Those are elements of the array. It works with all other records in
the file except for this one. How do I know which format is throwing
the error????


Then ones that correspond to the empty strings.

Can anyone help?


With what?

You already know how to tell which format is causing the warning...

I've been at this for 4 days now.....


.... so by now you should have moved on to answering the next question:

Why does this record contain empty strings?

We cannot help you with that because we don't know how @d_ar
is being populated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top