Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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...

In reply to Re: What Happened...(perils of porting from c) by jynx
in thread What Happened...(perils of porting from c) by Madams

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2022-05-20 09:58 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (73 votes). Check out past polls.