-- "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>