Marek <> wrote:
>for (@array1) { push @array3, $_ if $_ =~ /^\d+(?:\.\d+)?$/ };
The match operator defaults to $_. No need to explicitely bind $_.
> # do I really need a different array, to "slice out" my numbers?
> # Is there not a more elegant (perlish) way to do this?
It appears to me as if you may be looking for grep():
@array3 = grep(/^\d+(?:\.\d+)?$/, @array1);
>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?
I am not sure I understand. Do you want to know if _all_ numbers are
equal (i.e. the arrays have the same content) or do you want to sort the
numbers into two groups based on equal/non equal?
If the former then just loop over them, either with a C-style loop or
with a foreach loop (assuming they are equal length):
for ($i = 0; $i < @array3, $i++) {
$same = $same && $array3[$i] == $array4[$i];
}
or
for (@array3){
$same = $same && $_ == shift @array4;
}
Or you can use map() in scalar context:
$diff= map( $array3[$_]==$array4[$_] ? ()

1), (0..$#array3));
print "All numbers are the same\n" unless $diff;
You can also use map() to get a list of indices for which the numbers
are equal or different although IMO grep() is the better candidate for
that:
grep($array3[$_]==$array4[$_], 0..$#array3);
If you rather want the values instead of the indices then just return
those from map():
@same = map( $array3[$_]==$array4[$_]? ($array3[$_]) : (),
0..$#array3);
jue