Re: interpoliation within regexp




-- "Derek B. Smith" <derekbellnersmith@xxxxxxxxx>
wrote:

--- "Derek B. Smith" <derekbellnersmith@xxxxxxxxx>
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
.



Relevant Pages

  • Re: How to add thousand separators
    ... First, this code is obsolete as written, because char is a dead data type and should not ... Note that both of these should be stored as string resources since they might need to be ... 18 digits for any reason. ... you have made a VERY SERIOUS DESIGN ERROR. ...
    (microsoft.public.vc.mfc)
  • Re: what is the best way of passing floats into a string
    ... I do not null-terminate as snprintf takes care of this (according to ... But the easiest way to determine the size needed to format a number, ... int length_of_representation(double n,const char* format){ ... I get a nice result of -10.000000 in my char * string. ...
    (comp.unix.programmer)
  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... to strcmpwhich expects a pointer to a string. ... And now a question about something else: why do you use floating ... int,float, char, etc. ...
    (comp.lang.c)
  • Re: [OT] My First C# (warning - long post)
    ... cut me some slack - show me a COBOL program with less than 15 working-storage variables! ... Yes, the Trimis probably extra now, but that was my attempt to get it to quit griping at me that I had given it a "String", when it wanted a "char". ... public string IBreturn ...
    (comp.lang.cobol)
  • Re: why I can not write to the file after initialize the MFC in a service program
    ... you don't use char, an obsolete data type ... Why do you need an intermedate buffer to write literal strings anyway? ... For example, if AfxWinInit fails, you copy a 45-character string into a ... So you are going to try to initialize MFC EACH TIME THROUGH THE LOOP? ...
    (microsoft.public.vc.mfc)