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

range-based magical autoincrement

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

Description: 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
}

Comment on range-based magical autoincrement
Download Code
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 (Pope) 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.

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (14)
As of 2014-04-23 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (554 votes), past polls