Skip to content

Instantly share code, notes, and snippets.

@duelafn
Created March 18, 2010 15:16
Show Gist options
  • Select an option

  • Save duelafn/336458 to your computer and use it in GitHub Desktop.

Select an option

Save duelafn/336458 to your computer and use it in GitHub Desktop.
#!/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;
# 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