Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: What Happened...(perils of porting from c)

by jynx (Priest)
on Jan 06, 2001 at 02:42 UTC ( #50164=note: print w/replies, xml ) Need Help??

in reply to What Happened...(perils of porting from c)

i have to make a disclaimer:
i understand what your code is trying to do according to what the english says it is doing, but some of your pointer derefs i'm not certain i follow. Such as the following:
#oops...pointer arithmetic.. #curlevel = curvals + level; $curlevel = $level; # shouldn't this be more like: $curlevel = @$curvals + $level; # or some such? i'm not entirely certain as to why curvals got dr +opped here...
All i did with your code is a more perl-esque rewrite dropping out variables that aren't needed (or aren't used properly) and streamlining here and there. Also, i took out the infinite for loop since it seemed there are better ways to check for what you're doing. This could be not what you're looking for at all, but it seems to be what you have written already, just simplified.

NOTE: there is no error checking for incoming variables in this version.

#!/usr/bin/perl -w package forFun; use strict; use Exporter; @ISA = qw(Exporter); @EXPORT = qw(&ForFun); sub ForFun { my ($startval, $endval, $workfunc) = @_; my ($level, $curvals) = (0, []); push @$curvals, $_ foreach (@$startval); while ($level > -1) { $level = @$startval - 1; while ($curvals->[$level] <= $endval->[$level]) { &$workfunc($curvals); ($curvals->[$level])++; } $level--; while (++($startval->[$level]) > $endval->[$level]); last if (--$level < 0); } } return; } 1;
i tried to follow the pointer logic and your codes' logic as well as possible. i'd definitely suggest going with tilly's code, as it seems much more adaptable and extensible.

Hope this helps,


ps the code above is untested but should be able to work pretty much as is...

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://50164]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2022-05-24 03:14 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (82 votes). Check out past polls.