Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I think the want context is something screwy in this case:
package LuckyDeck; use Tie::Array; use overload '<>' => sub { use Want; my $self = shift; foreach (qw(BOOL SCALAR LIST ASSIGN REF)) { print STDERR "want $_\n" if want $_; } if (want ('BOOL') or want ('SCALAR')) { return splice( @$self, rand @$self, 1) unless wantarray; } my @deck; push @deck, splice( @$self, rand @$self, 1) while @$self; @deck; }; sub new { my $class = shift; bless [@_], $class; } package main; my $quux = LuckyDeck->new(1..9); print 'List Context',$/; print for <$quux>; print $/;
Which, when run with 5.6.1, yields:


perl/Language-FP% perl -l ../bar.pl
List Context

zsh: 7739 segmentation fault (core dumped)  perl -l ../bar.pl
In


#0  0xfd7b77c in parent_op ()
   from #1  0xfd7bf28 in XS_Want_parent_op_name ()
   from #2  0x10076ddc in Perl_pp_entersub ()
#3  0x1006fb80 in Perl_runops_standard ()
#4  0x1001fa3c in Perl_amagic_call ()
#5  0x100701e8 in Perl_pp_readline ()
#6  0x1006fb80 in Perl_runops_standard ()
#7  0x10014644 in S_run_body ()
#8  0x10014288 in perl_run ()
#9  0x10010f58 in main ()
#10 0xfe2e69c in __libc_start_main ()
    at ../sysdeps/powerpc/elf/libc-start.c:106
#11 0x0 in ?? ()
So it's evidently giving Want something it can't handle. The "amagic_call()" makes me think it's trying to access $quux as a tied array, but I'm hardly Mr. Internals. In any case, it doesn't seem to be called in array context in the for. Which leads me back to my previous conclusion, that overloading '<>' isn't meant for prime-time.

/s


In reply to Re: Overloading for List Context by educated_foo
in thread Overloading for List Context by Zaxo

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 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?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-03-29 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found