M
Marek
Hello all!
I have several lines where I need to know whether the numbers are the
same or not.
I made an example, and my questions are inserted as comments:
Thank you for your help
marek
#! /usr/local/bin/perl
use warnings;
use strict;
my $line1 = "Mon, 04.08.2008 61126.10 79071.30 3567 2648.00 2864.00";
my $line2 =
"Die, 05.08.2008 7:40-19:40 12:00 61198.70 79103.40 3574 2648.00
2950.70 Name1";
my @array1 = split( /\t\s*/, $line1 );
my @array2 = split( /\t\s*/, $line2 );
my @array3;
for (@array1) { push @array3, $_ if $_ =~ /^\d+(?:\.\d+)?$/ };
# do I really need a different array, to "slice out" my numbers?
# Is there not a more elegant (perlish) way to do this?
my @array4;
for (@array2) { push @array4, $_ if $_ =~ /^\d+(?:\.\d+)?$/ };
my $same = 1;
$same = $same && @array3 == @array4;
# this compares only the number of elements of these arrays.
# how to iterate over each element and compare them?
if ($same) {
print "these numbers are the same!\n";
print join( "\t", @array3 );
print "\n";
print join( "\t", @array4 );
print "\n";
}
else {
print "these numbers are not the same!\n\n";
print join( "\t", @array3 );
print "\n";
print join( "\t", @array4 );
print "\n";
}
I have several lines where I need to know whether the numbers are the
same or not.
I made an example, and my questions are inserted as comments:
Thank you for your help
marek
#! /usr/local/bin/perl
use warnings;
use strict;
my $line1 = "Mon, 04.08.2008 61126.10 79071.30 3567 2648.00 2864.00";
my $line2 =
"Die, 05.08.2008 7:40-19:40 12:00 61198.70 79103.40 3574 2648.00
2950.70 Name1";
my @array1 = split( /\t\s*/, $line1 );
my @array2 = split( /\t\s*/, $line2 );
my @array3;
for (@array1) { push @array3, $_ if $_ =~ /^\d+(?:\.\d+)?$/ };
# do I really need a different array, to "slice out" my numbers?
# Is there not a more elegant (perlish) way to do this?
my @array4;
for (@array2) { push @array4, $_ if $_ =~ /^\d+(?:\.\d+)?$/ };
my $same = 1;
$same = $same && @array3 == @array4;
# this compares only the number of elements of these arrays.
# how to iterate over each element and compare them?
if ($same) {
print "these numbers are the same!\n";
print join( "\t", @array3 );
print "\n";
print join( "\t", @array4 );
print "\n";
}
else {
print "these numbers are not the same!\n\n";
print join( "\t", @array3 );
print "\n";
print join( "\t", @array4 );
print "\n";
}