Created
March 18, 2010 15:16
-
-
Save duelafn/336458 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use strict; use warnings; use 5.010; | |
| use IHeartFortran;# Allow "$foo .EQV. $bar" constructs | |
| say 1 .EQV. 1; | |
| say 1 .EQV. 2; | |
| say 1 .NEQV. 1; | |
| say 1 .NEQV. 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # IHeartFortran.pm: Allow "$foo .EQV. $bar" constructs in Perl | |
| package IHeartFortran; | |
| use strict; use warnings; | |
| require Exporter; | |
| our @ISA = qw( Exporter ); | |
| our @EXPORT = qw/ EQV NEQV /; | |
| use overload '.' => \&_do_op; | |
| sub _do_op { | |
| my ($self, $y, $reverse) = @_; | |
| $$self{ $reverse ? 'left' : 'right' } = $y; | |
| if (exists($$self{left}) and exists($$self{right})) { | |
| return $$self{op}->(@$self{qw/ left right /}); | |
| } | |
| return $self; | |
| } | |
| sub new { | |
| my ($class, $op) = @_; | |
| bless { op => $op }, $class; | |
| } | |
| sub EQV() { __PACKAGE__->new( sub { $_[0] == $_[1] ? 1 : 0 } ) } | |
| sub NEQV() { __PACKAGE__->new( sub { $_[0] != $_[1] ? 1 : 0 } ) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment