Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Surprised by join

by Abigail-II (Bishop)
on Jun 08, 2004 at 15:20 UTC ( [id://362380]=note: print w/replies, xml ) Need Help??


in reply to Surprised by join

You could tie $":
#!/usr/bin/perl use strict; use warnings; sub TIESCALAR { my $class = shift; bless [-1 => [@_]] => $class; } sub STORE {die} sub FETCH { ${$_ [0]} [1] [${$_ [0]} [0] ++ % @{${$_ [0]} [1]}]; } tie $" => main => ":", "-"; my @a = qw /0 1 0 1 0 1 0 1 0 1 0 1/; print "@a\n"; __END__ 0:1-0:1-0:1-0:1-0:1-0:1
Unfortunally, there are a couple of bugs in perl related to this. First is that it will do a bogus call to FETCH before interpolating (FETCH is called once too often). Second is that perl gets mighty confused if FETCH returns an empty string. (Which is unfortunally just what you want).

Abigail

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-28 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found