in reply to Regexp and object's methods.
In may script I have some choises:package C; my $consts = { CONST1 => 1, CONST2 => 2, CONST3 => 3, CONST4 => 4, . . . }; use overload '``' => sub { return $const_values{shift} } ; # All constants can be accessed as by using AUTOLOAD sub AUTOLOAD { no strict 'refs', 'subs'; if ($AUTOLOAD =~ /.*::([A-Z]\w+)$/) { my $const_name = $1; *{$AUTOLOAD} = sub {return $const_values{$const_name}}; return $const_values{$const_name}; } return undef; } 1;
I'd like to use my constants intead of numbers:if($status == C->CONST1) { print "1" } elsif($status =~ /(2|3)/ { print "2 or 3" } else { print 'Something' }
but it doesn't work. Of course, I know that I can write like this:if($status == C->CONST1) { print "1" } elsif($status =~ /(C->CONST2|C->CONST3)/ { print "2 or 3" } else { print 'Something' }
But I wouldn't like to do it.$status == C->CONST3 or $status == C->CONST3
--------------------------------
SV* sv_bless(SV* sv, HV* stash);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Regexp and object's methods.
by Tomte (Priest) on May 02, 2003 at 12:47 UTC |