views:

299

answers:

4

G'day,

Why am I getting the following two errors from the script fragment below?

Argument "www4.mh.xxxx.co.uk.logstatsto20090610.gz" isn't numeric in division (/) at line 56

Argument "/logs/xxxx/200906/mcs0.telhc/borg2" isn't numeric in division (/) at line 56

The variables $dir and $log are both strings and the concatenation of the two strings, along with the slash in the middle, is also wrapped with quotation marks.

        foreach my $dir (@log_dirs) {
            foreach my $log (@log_list) {
line 56:        if ( -s "$dir/$log" ) {
                    push(@logs, $dir/$log);
                }
            }
        }

Edit: Line 56 is definitely the if statement. However, Paul, you're right, surrounding the division on line 57 with quotation marks fixes the problem. Thanks.

Edit: The Perl version reporting Line 56 is

stats@fs1:/var/tmp/robertw> /usr/local/perl/bin/perl -v      

This is perl, v5.6.1 built for sun4-solaris

Copyright 1987-2001, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

stats@fs1:/var/tmp/robertw>

Edit: Though using the method of interpolated strings in Perl, given that the variables are themselves strings and I am attempting to join them together with a slash character isn't the net result string concatenation?

cheers,

+12  A: 

Line 56 is probably the line after it, where you do try to divide two strings. What your probably intended was

   foreach my $dir (@log_dirs) {
        foreach my $log (@log_list) {
            if ( -s "$dir/$log" ) {
                push(@logs, "$dir/$log");
            }
        }
    }
Paul Dixon
All three of you (Paul Dixon, brian d foy, and 1800 INFORMATION) beat me by seconds... +1
AllenG
+9  A: 

You don't quote the string in your push. Instead of creating paths yourself, try to get into the habit of making portable paths with File::Spec:

use File::Spec::Functions;

my $path = catfile( $dir, $file );

Then you use $path whenever you want that string so you don't have the repeat yourself by remaking the string again (and perhaps doing it wrong the next time ;).

brian d foy
+4  A: 

It's caused by the following line:

push(@logs, $dir/$log);

You have a division there.

1800 INFORMATION
+2  A: 

I'm curious to know what version of perl you are using? All the ones I can easily try are correctly reporting the line number of the push.

ysth
G'day, I've added a note about the Perl version.
Rob Wells
Forgot to say thatnks for your interest. (-:
Rob Wells
Maybe, there's a #line comment somewhere. I've done that to myself more than once. But then again, I did do it because 5.6 misreported the line of our error--but it's messy if you move those things.
Axeman