Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Thanks Damian, but I'm afraid this is not solving my problem, just another one. *

From what I see in the sources of Var::Pairs are you binding a cycling iterator to the call place with the help of Devel::Callsite .

This is just a more secure way of using line and file from caller .

But this will only work well if you always finish the loop without exiting in the middle, since you are only initializing once by the first entry and letting the iteration starting new after a full loop.

What I'm looking for is to re-init the iterator when it is re-entered again. Hence to safely use last and return or other loop exits.

Consider this example showing that your iterators are not reset after breaking the loop.

use warnings; use strict; use feature 'say'; use Var::Pairs; my %hash; @hash{"a".."d"} =1..4; sub till { my $goal = shift; while (my $next = each_pair %hash) { say $next->key, ' had the value ', $next->value; last if $next->key eq $goal; } say "-"x10 . "exit"; } till("a"); till("a"); till("a"); till("a");

/usr/bin/perl -w /home/lanx/pm/t_var_pairs.pl a had the value 1 ----------exit d had the value 4 b had the value 2 c had the value 3 ----------exit a had the value 1 ----------exit d had the value 4 b had the value 2 c had the value 3 ----------exit Compilation finished at Sun May 6 21:54:21

update

NB: each has of course the same (and more) limitations.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

*) There are different kinds of iterators, please correct me if I'm missing a way to apply this to my kind of iterators ...


In reply to Re^2: Can I check if a loop's scope is entered for the first time? (Devel::Callsite) by LanX
in thread Can I check if a loop's scope is entered for the first time? by LanX

Title:
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2022-08-12 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?