Re: interpoliation within regexp
Mumia W. wrote: On 09/29/2006 01:44 PM, Rob Dixon wrote: Derek B. Smith wrote: --- Mumia W. [EMAIL PROTECTED] wrote: What is the purpose of this program? To generate a random 6 character string. If the first character starts with a # then I just ignore the new string and tell it to goto LABLE, b/c for 0-32 on the ASCII table cannot be used as a 1st character in a user password. ## generate random 8 char password. PASSWD: my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z'); my $password = join '', map { $a[int rand @a] } 0 .. 5; #if first char is a-z then print it else warn #chop string into individual characters my @chars = unpack (A1 x length($password), $password); if ($chars[0] =~ /^\D/) { print Your new password is:\t,@chars,\n; } else { #print string starts with number:\t,@chars, \trestarting\n; #substr($chars[0],0,1) =~ s/$chars[0]/chr ($1)/e); ## execute with regexp substitute ?/? goto PASSWD; } This will do what you want. It shuffles all of the possible characters and joins them into a string, and then finds the first substring of six characters that starts with a non-numeric character. The only proviso is that a password can never have the same character twice, which isn't true of the general solution. use List::Util qw/shuffle/; my $chars = join '', shuffle (0..9, 'a'..'z', 'A'..'Z'); my ($password) = $a =~ /(\D.)/; HTH, Rob Aren't you concerned that this is random in a completely wrong way? Only one of each character can appear in the password, and that's kind of weak. No. I mentioned it in my post, but since it's meant for password generation and not for creating data that's 'random' in the mathematical sense I think it's plenty good enough. Even if you take truly random samples of six characters out of a 62-character set, about three-quarters of them will be six distinct characters. It's also a /very/ minor issue that you assign to $chars but then use $a after; the main problem is that this password generating algorithm is that it is, to steal a phrase from Lo Wang, weaker than a baby's [passing gas]. I fixed that in a later post. I wrote a working version and then posted an earlier incarnation. Call me an old [passing gas] if you will. :( Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
Derek B. Smith wrote: --- Rob Dixon [EMAIL PROTECTED] wrote: Rob Dixon wrote: This will do what you want. It shuffles all of the possible characters and joins them into a string, and then finds the first substring of six characters that starts with a non-numeric character. The only proviso is that a password can never have the same character twice, which isn't true of the general solution. [snip faulty code] use List::Util qw/shuffle/; my $chars = join '', shuffle (0..9, 'a'..'z', 'A'..'Z'); my ($password) = $chars =~ /(\D.)/; so this solution DOES NOT allow two of the same characters twice? cool thanks! derek Yes. And it doesn't allow even one of the same character twice either! :) Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
Rob Dixon schreef: [6 random characters from 0-9A-Za-z] it's meant for password generation and not for creating data that's 'random' in the mathematical sense I think it's plenty good enough. Even if you take truly random samples of six characters out of a 62-character set, about three-quarters of them will be six distinct characters. Yes: (X * 61 * 60 * 59 * 58 * 57) / (X * 62 ** 5) = 78% -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
I reread the docs and I am still unclear with the code: $a[ 10 + rand( @a - 10 ) I do understand everything but $a[ 10 + rand( @a - 10 ) b/c you say subtract 10 from each element occurrance = @a - 10 then add 10 to the result of rand (@a - 10) To me this is offsets itself which is why I am confused. Will you explain again? I think you missed an explanation step between a and b? Reagardless it work so thank you. --- D. Bolliger [EMAIL PROTECTED] wrote: 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 __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
On 09/29/2006 12:15 PM, Derek B. Smith wrote: --- D. Bolliger [EMAIL PROTECTED] wrote: 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 I reread the docs and I am still unclear with the code: $a[ 10 + rand( @a - 10 ) I do understand everything but $a[ 10 + rand( @a - 10 ) b/c you say subtract 10 from each element occurrance = @a - 10 then add 10 to the result of rand (@a - 10) To me this is offsets itself which is why I am confused. Will you explain again? I think you missed an explanation step between a and b? Reagardless it work so thank you. Does this slice help demonstrate it? my @a = (0..9,'a'..'z','A'..'Z'); my @b = @[EMAIL PROTECTED]; print @a, \n; print @b, \n; # OUTPUT: #0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ #abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ # BTW, placing print statements in the right places is a great way to learn how someone's program works. Anyway, I hope this is easier to digest: my @a = (0..9,'a'..'z','A'..'Z'); my @b = @[EMAIL PROTECTED]; my $password = $b[int rand (@b)]; $password .= join '', map $a[int rand (@a)], (1..5); print $password, \n; __HTH__ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
Derek B. Smith wrote: --- Mumia W. [EMAIL PROTECTED] wrote: What is the purpose of this program? To generate a random 6 character string. If the first character starts with a # then I just ignore the new string and tell it to goto LABLE, b/c for 0-32 on the ASCII table cannot be used as a 1st character in a user password. ## generate random 8 char password. PASSWD: my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z'); my $password = join '', map { $a[int rand @a] } 0 .. 5; #if first char is a-z then print it else warn #chop string into individual characters my @chars = unpack (A1 x length($password), $password); if ($chars[0] =~ /^\D/) { print Your new password is:\t,@chars,\n; } else { #print string starts with number:\t,@chars, \trestarting\n; #substr($chars[0],0,1) =~ s/$chars[0]/chr ($1)/e); ## execute with regexp substitute ?/? goto PASSWD; } This will do what you want. It shuffles all of the possible characters and joins them into a string, and then finds the first substring of six characters that starts with a non-numeric character. The only proviso is that a password can never have the same character twice, which isn't true of the general solution. use List::Util qw/shuffle/; my $chars = join '', shuffle (0..9, 'a'..'z', 'A'..'Z'); my ($password) = $a =~ /(\D.)/; HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
Rob Dixon wrote: This will do what you want. It shuffles all of the possible characters and joins them into a string, and then finds the first substring of six characters that starts with a non-numeric character. The only proviso is that a password can never have the same character twice, which isn't true of the general solution. use List::Util qw/shuffle/; my $chars = join '', shuffle (0..9, 'a'..'z', 'A'..'Z'); my ($password) = $a =~ /(\D.)/; My apologies: I posted an early version of that. Here is the working one: use List::Util qw/shuffle/; my $chars = join '', shuffle (0..9, 'a'..'z', 'A'..'Z'); my ($password) = $chars =~ /(\D.)/; Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
-- Mumia W. [EMAIL PROTECTED] wrote: On 09/29/2006 12:15 PM, Derek B. Smith wrote: --- D. Bolliger [EMAIL PROTECTED] wrote: 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 I reread the docs and I am still unclear with the code: $a[ 10 + rand( @a - 10 ) I do understand everything but $a[ 10 + rand( @a - 10 ) b/c you say subtract 10 from each element occurrance = @a - 10 then add 10 to the result of rand (@a - 10) To me this is offsets itself which is why I am confused. Will you explain again? I think you missed an explanation step between a and b? Reagardless it work so thank you. Does this slice help demonstrate it? my @a = (0..9,'a'..'z','A'..'Z'); my @b = @[EMAIL PROTECTED]; print @a, \n; print @b, \n; # OUTPUT: #0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ #abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ # BTW, placing print statements in the right places is a great way to learn how someone's program works. Anyway, I hope this is easier to digest: my @a = (0..9,'a'..'z','A'..'Z'); my @b = @[EMAIL PROTECTED]; my $password = $b[int rand (@b)]; $password .= join '', map $a[int rand (@a)], (1..5); print $password, \n; __HTH__ yes this explains it... thank you. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
On 09/29/2006 01:44 PM, Rob Dixon wrote: Derek B. Smith wrote: --- Mumia W. [EMAIL PROTECTED] wrote: What is the purpose of this program? To generate a random 6 character string. If the first character starts with a # then I just ignore the new string and tell it to goto LABLE, b/c for 0-32 on the ASCII table cannot be used as a 1st character in a user password. ## generate random 8 char password. PASSWD: my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z'); my $password = join '', map { $a[int rand @a] } 0 .. 5; #if first char is a-z then print it else warn #chop string into individual characters my @chars = unpack (A1 x length($password), $password); if ($chars[0] =~ /^\D/) { print Your new password is:\t,@chars,\n; } else { #print string starts with number:\t,@chars, \trestarting\n; #substr($chars[0],0,1) =~ s/$chars[0]/chr ($1)/e); ## execute with regexp substitute ?/? goto PASSWD; } This will do what you want. It shuffles all of the possible characters and joins them into a string, and then finds the first substring of six characters that starts with a non-numeric character. The only proviso is that a password can never have the same character twice, which isn't true of the general solution. use List::Util qw/shuffle/; my $chars = join '', shuffle (0..9, 'a'..'z', 'A'..'Z'); my ($password) = $a =~ /(\D.)/; HTH, Rob Aren't you concerned that this is random in a completely wrong way? Only one of each character can appear in the password, and that's kind of weak. It's also a /very/ minor issue that you assign to $chars but then use $a after; the main problem is that this password generating algorithm is that it is, to steal a phrase from Lo Wang, weaker than a baby's [passing gas]. :-) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
--- Derek B. Smith [EMAIL PROTECTED] wrote: I need to substitute a conversion using chr, but have failed on multiple attempts. Basically if the first element contains a # then convert it. Will anyone advise? thank you derek #if first char is a-z then print it else warn #chop string into individual characters my @chars = unpack (A1 x length($password),$password); if ($chars[0] =~ /^\D/) { print Your new string is:\t,@chars,\n; } else { print string starts with number, now converting\n, @chars, \n; substr($chars[0],0,1) =~ s/\Q{$chars[0]}/{chr($chars[0]}\E/; print @chars; } I will try to use the /e modifier as such: s/(\$\w+)/$1/e; An explanation is below: /e Righthand side of a s/// is code to eval /ee Righthand side of a s/// is a string to eval, then run as code, and its return value eval'led again. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
On 09/28/2006 08:16 AM, Derek B. Smith wrote: --- Derek B. Smith [EMAIL PROTECTED] wrote: I need to substitute a conversion using chr, but have failed on multiple attempts. Basically if the first element contains a # then convert it. Will anyone advise? thank you derek #if first char is a-z then print it else warn #chop string into individual characters my @chars = unpack (A1 x length($password),$password); if ($chars[0] =~ /^\D/) { print Your new string is:\t,@chars,\n; } else { print string starts with number, now converting\n, @chars, \n; substr($chars[0],0,1) =~ s/\Q{$chars[0]}/{chr($chars[0]}\E/; print @chars; } I will try to use the /e modifier as such: s/(\$\w+)/$1/e; An explanation is below: /e Righthand side of a s/// is code to eval /ee Righthand side of a s/// is a string to eval, then run as code, and its return value eval'led again. What does your input data look like, and what do you want the output to look like? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
-- Derek B. Smith [EMAIL PROTECTED] wrote: --- Derek B. Smith [EMAIL PROTECTED] wrote: I need to substitute a conversion using chr, but have failed on multiple attempts. Basically if the first element contains a # then convert it. Will anyone advise? thank you derek #if first char is a-z then print it else warn #chop string into individual characters my @chars = unpack (A1 x length($password),$password); if ($chars[0] =~ /^\D/) { print Your new string is:\t,@chars,\n; } else { print string starts with number, now converting\n, @chars, \n; substr($chars[0],0,1) =~ s/\Q{$chars[0]}/{chr($chars[0]}\E/; print @chars; } I will try to use the /e modifier as such: s/(\$\w+)/$1/e; An explanation is below: /e Righthand side of a s/// is code to eval /ee Righthand side of a s/// is a string to eval, then run as code, and its return value eval'led again. * The results I am getting when using data::dumper is: string starts with number, now converting 6FhJ9Z DUMP: $VAR1 = 1; DUMP2: $VAR1 = ' '; $VAR2 = 'F'; $VAR3 = 'h'; $VAR4 = 'J'; $VAR5 = '9'; $VAR6 = 'Z'; $VAR7 = ' '; from code: ## generate random 8 char string. my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z'); my $password = join '', map { $a[int rand @a] } 0 .. 5; #if first char is a-z then print it else warn #chop string into individual characters my @chars = unpack (A1 x length($password), $password); if ($chars[0] =~ /^\D/) { print Your new string is:\t,@chars,\n; } else { print string starts with number, now converting\n, @chars, \n; print DUMP:\t, Dumper(substr($chars[0],0,1) =~ s/$chars[0]/chr ($1)/e); print DUMP2:\t, Dumper @chars,\n; } Any help please on as to why chr is not working? thx derek __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
--- Mumia W. [EMAIL PROTECTED] wrote: On 09/28/2006 08:16 AM, Derek B. Smith wrote: --- Derek B. Smith [EMAIL PROTECTED] wrote: I need to substitute a conversion using chr, but have failed on multiple attempts. Basically if the first element contains a # then convert it. Will anyone advise? thank you derek #if first char is a-z then print it else warn #chop string into individual characters my @chars = unpack (A1 x length($password),$password); if ($chars[0] =~ /^\D/) { print Your new string is:\t,@chars,\n; } else { print string starts with number, now converting\n, @chars, \n; substr($chars[0],0,1) =~ s/\Q{$chars[0]}/{chr($chars[0]}\E/; print @chars; } I will try to use the /e modifier as such: s/(\$\w+)/$1/e; An explanation is below: /e Righthand side of a s/// is code to eval /ee Righthand side of a s/// is a string to eval, then run as code, and its return value eval'led again. What does your input data look like, and what do you want the output to look like? ** The input data is a 6 character randomized string that could start with a # such as 6FhJ9Z. If it does start with a number then I need to convert this character into its cooresponding alpha char, [a-z,A-Z]. The output data from the string 6FhJ9Z should be [a-z,A-Z]FhJ9Z I guess what I am asking for is not plausible after looking at the ASCII table b/c there is no cooresponding letter for number 6. Silly me, ok then maybe grab any [a-z,A-Z] character. my $foo = pack(C*, 6); print $foo; or chr ('6'); __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
On 09/28/2006 12:04 PM, Derek B. Smith wrote: ** The input data is a 6 character randomized string that could start with a # such as 6FhJ9Z. If it does start with a number then I need to convert this character into its cooresponding alpha char, [a-z,A-Z]. The output data from the string 6FhJ9Z should be [a-z,A-Z]FhJ9Z I guess what I am asking for is not plausible after looking at the ASCII table b/c there is no cooresponding letter for number 6. Silly me, ok then maybe grab any [a-z,A-Z] character. my $foo = pack(C*, 6); print $foo; or chr ('6'); What is the purpose of this program? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
--- Mumia W. [EMAIL PROTECTED] wrote: On 09/28/2006 12:04 PM, Derek B. Smith wrote: ** The input data is a 6 character randomized string that could start with a # such as 6FhJ9Z. If it does start with a number then I need to convert this character into its cooresponding alpha char, [a-z,A-Z]. The output data from the string 6FhJ9Z should be [a-z,A-Z]FhJ9Z I guess what I am asking for is not plausible after looking at the ASCII table b/c there is no cooresponding letter for number 6. Silly me, ok then maybe grab any [a-z,A-Z] character. my $foo = pack(C*, 6); print $foo; or chr ('6'); What is the purpose of this program? To generate a random 6 character string. If the first character starts with a # then I just ignore the new string and tell it to goto LABLE, b/c for 0-32 on the ASCII table cannot be used as a 1st character in a user password. ## generate random 8 char password. PASSWD: my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z'); my $password = join '', map { $a[int rand @a] } 0 .. 5; #if first char is a-z then print it else warn #chop string into individual characters my @chars = unpack (A1 x length($password), $password); if ($chars[0] =~ /^\D/) { print Your new password is:\t,@chars,\n; } else { #print string starts with number:\t,@chars, \trestarting\n; #substr($chars[0],0,1) =~ s/$chars[0]/chr ($1)/e); ## execute with regexp substitute ?/? goto PASSWD; } __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
Derek B. Smith wrote: --- Mumia W. [EMAIL PROTECTED] wrote: What is the purpose of this program? To generate a random 6 character string. If the first character starts with a # then I just ignore the new string and tell it to goto LABLE, b/c for 0-32 on the ASCII table cannot be used as a 1st character in a user password. ## generate random 8 char password. PASSWD: my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z'); my $password = join '', map { $a[int rand @a] } 0 .. 5; 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 -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
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? thx __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: interpoliation within regexp
Derek B. Smith wrote: 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; Ok great, but I do not fully understand this. Will you explain in English? The first ten elements of @a are the digits 0-9 so the first list item picks a random element that ignores the first ten elements of @a and the next five list items pick a random element from the entire array. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response