Re: interpoliation within regexp



Derek B. Smith am Donnerstag, 28. September 2006 22:28:
Why not just specify a non-digit for the first
character:

my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');

my $password = join '', $a[ 10 + rand( @a - 10 ) ],
map $a[ rand @a ], 1 .. 5;



John

Ok great, but I do not fully understand this. Will you
explain in English?

Join with '':
a) a randomly selected entry from @a excluding the digits
at positions 0..9 [the part between the 1st and
2nd comma]
b) five randomly selected entries from @a
[the map part]

Note: @a is used in scalar context both times, meaning the number of entries
in @a.

perldoc -f map
perldoc -f join
perldoc -f rand


My tip for cases where you get a working solution you don't understand fully:
a) Try to find out what "belongs together" (imagine '()'s)
b) Try to break the solution apart according to the findings in a)
c) examine the parts: print them out, dump them with Data::Dumper, modify
them, read the man pages
d) put them together again, eventually one by one part, using examination
techniques as in c)


Hope this helps!

Dani

.



Relevant Pages

  • Re: interpoliation within regexp
    ... five randomly selected entries from @a ... [the map part] ... perldoc -f join ... My tip for cases where you get a working solution ...
    (perl.beginners)
  • Re: Is this considered ugly?
    ... > use strict; ... foreach { ... hashes: perldoc perldata ... map: perldoc -f map ...
    (comp.lang.perl.misc)
  • Re: interpoliation within regexp
    ... perldoc -f join ... My tip for cases where you get a working solution ... Do You Yahoo!? ... Mail has the best spam protection around ...
    (perl.beginners)
  • Re: interpoliation within regexp
    ... perldoc -f join ... My tip for cases where you get a working solution ... Do You Yahoo!? ... Mail has the best spam protection around ...
    (perl.beginners)
  • speed of grep{s///} vs ??? or am i asking the wrong question?
    ... now- just curious about speeding it up- pehaps a module would be fine, ... especialy in block form (perldoc -f grep and perldoc -f map) i'm not ...
    (perl.beginners)