Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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

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.


      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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://177917]
[Corion]: Meh. I have a very simple mechanism to scrape+track prices, and even to send me mail if something changes (via cron), but SQLite doesn't support window functions, so my simple SQL to determine a price change won't work :-( Maybe I should store the DB ...
[Corion]: ... in Pg, but that would mean that I'd have to deal with credentials and stuff :)
[Corion]: In fact, the whole thing is just four simple programs, one App::scrape, another being DBIx::RunSQL, and one some glue to convert a JSON object into an SQL INSERT statement (+DBI connect/execute), so it would be an incredibly simple solution...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2018-02-23 15:02 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (302 votes). Check out past polls.