in reply to Returning a Junction
use strict; package junction; use overload 'eq'=>\&compare; sub new{ my $class = shift; my $self = {}; %{$self} = map{$_,1} @_; bless $self,$class; } sub compare{ my $self = shift; my $string = shift; return exists $self->{$string}; } package main; my $foo = junction->new("Visa Card","Visa","Visa Check Card"); foreach my $test ("Visa","Vasdfasd","Taco","Visa Check Card") { if ($test eq $foo) { print "$test is a Visa!\n"; } else { print "$test is NOT a Visa\n"; } } __OUTPUT__ Visa is a Visa! Vasdfasd is NOT a Visa Taco is NOT a Visa Visa Check Card is a Visa!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Returning a Junction
by hardburn (Abbot) on Sep 04, 2003 at 19:20 UTC | |
by fletcher_the_dog (Friar) on Sep 04, 2003 at 19:40 UTC | |
by dragonchild (Archbishop) on Sep 04, 2003 at 19:53 UTC |