Why is this supposed interpolation interpreted as a Perl unit?

G'day

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

The argument "www4.mh.xxxx.co.uk.logstatsto20090610.gz" is not numeric in division (/) on line 56

The argument "/logs/xxxx/200906/mcs0.telhc/borg2" is not numeric in division (/) on line 56

The $ dir and $ log variables are both strings, and the concatenation of two strings along with a slash in the middle is also wrapped in 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 an if statement. However, Paul, you are correct, surrounding the division of the line 57 with quotes, fixes the problem. Thanks.

Edit: Line 56 of Perl version reports

 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: Although using the interpolated string method in Perl, given that the variables themselves are strings, and I'm trying to combine them with a slash, is not a concatenation of the result string.

amuses

+4
source share
4 answers

Line 56 is probably the line after it where you are trying to split the two lines. What you probably planned was

  foreach my $dir (@log_dirs) { foreach my $log (@log_list) { if ( -s "$dir/$log" ) { push(@logs, "$dir/$log"); } } } 
+12
source

You do not cast the string to push . Instead of creating paths yourself, try getting used to portable paths with File :: Spec :

 use File::Spec::Functions; my $path = catfile( $dir, $file ); 

Then you use $path whenever you want this line so that you don't have a repetition by redoing the line again (and possibly doing it wrong the next time;).

+9
source

This is caused by the following line:

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

You have a unit.

+5
source

I am curious to know which version of perl you are using? All that I can easily try, correctly report the line number of the click.

+2
source

Source: https://habr.com/ru/post/1286066/


All Articles