At 12:12 PM 1/22/2004, John Baker wrote:
>Greetings.
>
>Is it possible to reference a control operator?
>
>For example, I'd like to take this code:
>
>
> sub getFieldFromAllRecords {
> my ($self, $directive, $keyword, $matchCondition) = @_;
>
> my ($field, $regArr);
>
> # another public method within same pkg:
> my $allRecs = dumpAllAudits($self);
> my %ar = %$allRecs;
>
> push @{$regArr}, qr/$keyword/i;
>
> my %select;
> while( my($key, $value) = each(%ar)) {
> map { next unless ($$value{$directive} =~ /$_/i); } @{$regArr};
> $select{$key} = $$value{$directive};
> }
>
> return \%select;
> }
>
>and change it such that the 'unless' conditional operator is
>referenced conceptually similar to the following:
>
> sub getFieldFromAllRecords {
> my ($self, $directive, $keyword, $matchCondition) = @_;
>
Rather than trying to write code into variables or self-modifying code, I think I
would try defining some constants:
use constant MATCH_IF => 0;
use constant MATCH_UNLESS => 1;
Then assign $mc to MATCH_IF or MATCH_UNLESS any way you like
Then use xor:
map { next if ( ($$value{$directive} =~ /$_/i) xor $mc); } @{$regArr};
This is untested, but you get the idea.
-Mark
> my $mc = $matchCondition; # changed: where $mc can be either
> # 'if' or 'unless'.
> my ($field, $regArr);
>
> # another public method within same pkg:
> my $allRecs = dumpAllAudits($self);
> my %ar = %$allRecs;
>
> push @{$regArr}, qr/$keyword/i;
>
> my %select;
> while( my($key, $value) = each(%ar)) {
> map { next $mc ($$value{$directive} =~ /$_/i); } # changed
> @{$regArr};
> $select{$key} = $$value{$directive};
> }
>
> return \%select;
> }
>
>If it's not possible to reference operators, I'll rework the code.
>
>Thanks in advance.
>jab
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
><http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>