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

range-based magical autoincrement

by merlyn (Sage)
on Jun 28, 2002 at 03:07 UTC ( [id://177917]=CUFP: print w/replies, xml ) Need Help??

Ever wish the "magical autoincrement" would generate things that start with A-F, then have a digit, then one of P, Q, and R in cycles? Well, write one!
my $generator = sub { scalar glob "{A,B,C,D,E,F}{0,1,2,3,4,5,6,7,8,9}{ +P,Q,R}" }; ... while ($_ = &$generator) { print "$_\n"; # sample usage }

Replies are listed 'Best First'.
Re: range-based magical autoincrement
by educated_foo (Vicar) on Jun 28, 2002 at 04:12 UTC
    Scalar glob is a scary thing, maybe even "considered harmful." For another interesting application, see this golf entry.

    /s

      It's not the scalar glob that scares me. It's the use of glob for non-file things :)

      I'd probably just use a list, or an array if I need it multiple times:

      for ('A'..'F', 0..9, qw/P Q R/) { ... }
      Update - Hmm... I misread the glob, and thought the }{ parts were just commas. Sorry :)

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

Re: •range-based magical autoincrement
by BrowserUk (Patriarch) on Dec 05, 2002 at 10:37 UTC

    Thanks for pointing this obscure but oh-so-potentially useful behaviour out.

    I see the "considered dangerous" phrase. Is it?

    I found the (somewhat breif) description of it in perlop. As I discovered yesterday, writing code to reproduce this behaviour yourself is annoyingly difficult, but in the application of generating test data amongst others, would be very useful.

    Would you use this in production code? Do you have any insight as to whether the behaviour is likely to remain in place or is it deprecated or destined to disappear sometime soon?


    Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
    Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
    Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
    Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (8)
As of 2024-04-24 12:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found