|
Posted by Peter J. Holzer on March 18, 2008, 7:34 pm
Please log in for more thread options > Jednom davno, ne znam vise kad, xhoster@gmail.com duboko zamisljen/a
> rece:
>
>> > Jednom davno, ne znam vise kad, John W. Krahn duboko zamisljen/a rece:
>> > > Couldn't you just write that as:
>> > >
>> > > $found = 1 if exists $cb;
>> >
>> > Well, I have to thank you for putting me on the right track!
>> >
>> > There was a problem with some numeric data having prefixed zeroes while
>> > some of the hash keys did not so there could be no match ( 0567 != 567).
Try to canonicalize the data.
>> > But I'm still confused why the LAST was triggered before a match was
>> > $found?
>>
>> I rather doubt that it was doing that. If you want to pursue the matter,
>> post a complete, runnable script to illustrate this. Otherwise I'll assume
>> you are misinterpreting something.
>
> Well, I'm most certanly misundrestanding something, but I'd like to know
> what, so I don't make the same mistake twice :/
>
> The following subrutine works correctly (and slowly) if the lines with
> LAST are commented out.
How does it not work correctly if these lines are not commented out?
Please post an example which demonstrates the problem.
> Code:
> sub checkCB{
> my $cbName=$_[0];
> my $data=$_[1];
> my ($k,$v);
> my $found;
> my $g=0;
> my $checked;
> my $test='text';
>
> print "looking for [$data] in [$cbName] control: ";
>
> #----numbers exception
> if ($data=~/^\d$/){
> $data=int($data);
> $test='numbers';
> }
>
> CODECHECK: while ( ($k,$v) = each %}) {
> #print $g++."\n";
> switch ($test){
Don't use switch. It is rather buggy and introduces problems which are
hard to find.
> case 'numbers' {
> if ($data==$k){
> $found=1;
> #last CODECHECK if ($found==1);
$found is always 1 here (you just set it to one), so this is equivalent
to "last CODECHECK;". However, that seems to be what you want.
> }
> }
> case 'text' {
> if ($data eq $k){
> $found=1;
> #last CODECHECK if ($found==1);
Same here.
> }
> }
> }
> }
>
> return $found;
> }
> ---------
>
|