M
Marek
Hello all,
as a beginner, I am not sure, why I get this message "Useless use of
array element in void context". To illustrate I made a concentrated
excerpt of my larger perl project.
I need to compare two strings, which start with a different date, than
are coming numbers, which may or may not be different, and one line
finishes with a name. Whether the numbers are different in the string,
I made a split on white space, to compare them. Is there probably a
better way to compare two strings? In any case perl syntax check is
complaining about line 41 but is running fine. Really no idea why?
Thank you in advance
marek
#! /usr/bin/perl/
use warnings;
use strict;
my @out_lines = split(
/\n/,
'Mit, 16.05.2007 992.50 44284.40 2688 69.50
10110.90 Name1
Don, 17.05.2007 1148.90 44364.80 2707 69.50
10307.60 Name2
Fre, 18.05.2007 1408.50 44496.50 2714 69.50
10512.90 Name1
Sam, 19.05.2007 1736.60 44665.00 2738 69.50
10864.50 Name2
Son, 20.05.2007 2003.41 44769.00 2746 69.50
11037.70 Name1
Mon, 21.05.2007 2294.10 44907.40 2754 70.50
11256.30 Name1
Die, 22.05.2007 2683.10 45151.10 2762 70.50
11607.90 Name1
Mit, 23.05.2007 2994.30 45284.10 2765 70.50
11808.00 Name1
Don, 24.05.2007 3092.10 45336.50 2777 70.50
11953.40 Name1
Fre, 25.05.2007 3092.10 45336.50 2777 70.50
11953.40 Name2
Sam, 26.05.2007 3092.10 45336.50 2777 70.50
11953.40 Name2
Son, 27.05.2007 3092.10 45336.50 2777 70.50
11953.40 Name2
Mon, 28.05.2007 3494.70 45498.30 2816 70.50
12358.30 Name2
Die, 29.05.2007 3896.20 45617.80 2821 70.50
12535.40 Name1
Mit, 30.05.2007 4226.30 45851.00 2829 70.50
12875.60 Name1
Don, 31.05.2007 4465.80 45920.90 2834 70.50
12974.20 Name1'
);
my $old_line;
foreach my $out_line (@out_lines) {
if ($old_line) {
$old_line =~ s/\s+[-a-z\d]+$//i;
my @old_line = split( /\s+/, $old_line );
my @out_line = split( /\s+/, $out_line );
if (
(
$old_line[2], $old_line[3], $old_line[4],
$old_line[5], $old_line[6]
) == (
$out_line[2], $out_line[3], $out_line[4],
$out_line[5], $out_line[6]
)
)
{
print "same numbers:\n";
print join("\t",@old_line) . "\n";
print join("\t",@out_line) . "\n";
print "TOTAL\t\t0.00\t0.00\t0.00\t0.00\t0.00\n";
}
else {
my $result2 = $out_line[2] - $old_line[2];
my $result3 = $out_line[3] - $old_line[3];
my $result4 = $out_line[4] - $old_line[4];
my $result5 = $out_line[5] - $old_line[5];
my $result6 = $out_line[6] - $old_line[6];
print "different numbers\n";
print join("\t",@old_line) . "\n";
print join("\t",@out_line) . "\n";
printf( "TOTAL\t\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",
$result2, $result3, $result4, $result5, $result6 );
}
$old_line = $out_line;
}
else {
$old_line = $out_line;
}
}
as a beginner, I am not sure, why I get this message "Useless use of
array element in void context". To illustrate I made a concentrated
excerpt of my larger perl project.
I need to compare two strings, which start with a different date, than
are coming numbers, which may or may not be different, and one line
finishes with a name. Whether the numbers are different in the string,
I made a split on white space, to compare them. Is there probably a
better way to compare two strings? In any case perl syntax check is
complaining about line 41 but is running fine. Really no idea why?
Thank you in advance
marek
#! /usr/bin/perl/
use warnings;
use strict;
my @out_lines = split(
/\n/,
'Mit, 16.05.2007 992.50 44284.40 2688 69.50
10110.90 Name1
Don, 17.05.2007 1148.90 44364.80 2707 69.50
10307.60 Name2
Fre, 18.05.2007 1408.50 44496.50 2714 69.50
10512.90 Name1
Sam, 19.05.2007 1736.60 44665.00 2738 69.50
10864.50 Name2
Son, 20.05.2007 2003.41 44769.00 2746 69.50
11037.70 Name1
Mon, 21.05.2007 2294.10 44907.40 2754 70.50
11256.30 Name1
Die, 22.05.2007 2683.10 45151.10 2762 70.50
11607.90 Name1
Mit, 23.05.2007 2994.30 45284.10 2765 70.50
11808.00 Name1
Don, 24.05.2007 3092.10 45336.50 2777 70.50
11953.40 Name1
Fre, 25.05.2007 3092.10 45336.50 2777 70.50
11953.40 Name2
Sam, 26.05.2007 3092.10 45336.50 2777 70.50
11953.40 Name2
Son, 27.05.2007 3092.10 45336.50 2777 70.50
11953.40 Name2
Mon, 28.05.2007 3494.70 45498.30 2816 70.50
12358.30 Name2
Die, 29.05.2007 3896.20 45617.80 2821 70.50
12535.40 Name1
Mit, 30.05.2007 4226.30 45851.00 2829 70.50
12875.60 Name1
Don, 31.05.2007 4465.80 45920.90 2834 70.50
12974.20 Name1'
);
my $old_line;
foreach my $out_line (@out_lines) {
if ($old_line) {
$old_line =~ s/\s+[-a-z\d]+$//i;
my @old_line = split( /\s+/, $old_line );
my @out_line = split( /\s+/, $out_line );
if (
(
$old_line[2], $old_line[3], $old_line[4],
$old_line[5], $old_line[6]
) == (
$out_line[2], $out_line[3], $out_line[4],
$out_line[5], $out_line[6]
)
)
{
print "same numbers:\n";
print join("\t",@old_line) . "\n";
print join("\t",@out_line) . "\n";
print "TOTAL\t\t0.00\t0.00\t0.00\t0.00\t0.00\n";
}
else {
my $result2 = $out_line[2] - $old_line[2];
my $result3 = $out_line[3] - $old_line[3];
my $result4 = $out_line[4] - $old_line[4];
my $result5 = $out_line[5] - $old_line[5];
my $result6 = $out_line[6] - $old_line[6];
print "different numbers\n";
print join("\t",@old_line) . "\n";
print join("\t",@out_line) . "\n";
printf( "TOTAL\t\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",
$result2, $result3, $result4, $result5, $result6 );
}
$old_line = $out_line;
}
else {
$old_line = $out_line;
}
}