Thread eq Operator überlagern (24 answers)
Opened by rosti at 2024-08-22 14:48

GwenDragon
 2024-08-24 13:09
#196660 #196660
User since
2005-01-17
14741 Artikel
Admin1
[Homepage]
user image
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use 5.020; use strict; use warnings;

use overload '==' => \&my_compare;
sub my_compare {
  my ($left, $right) = @_;
  my $result = ($left cmp $right) ? 0 : 1;
  warn $left, "|", $right;
  $result;
}

# -----------------------------------------------
my $name = 'Rara';

say (1 == 22);
say ("1" == 1);
say ( $name == "Rara" );

__END__

Nörgelt gleich los:
Argument "Rara" isn't numeric in numeric eq (==) at T:\a.pl line 18.
Argument "Rara" isn't numeric in numeric eq (==) at T:\a.pl line 18.

1
1

Seltsam. == wird gar nicht überladen sonst würde es ja my_compare() die Inhalte von $eleft und $right warnen.

Getestet mit 5.36.3.1 | Strawberry Perl | Windows 11

Ich kapiere overload halt doch nicht.
Muss mich wohl durch meine Perl-Bücher im regal wühlen.
Last edited: 2024-08-24 13:18:26 +0200 (CEST)

View full thread eq Operator überlagern