boolee
asked on
Runtime hash array & text processing
Hi
Please tell me how to fill contents into a hash array dynamically. The hash array is empty initially and it is to be filled with key value pairs (say employee no-employee name from database )so that I can process it later.
My another problem is I would like to get the index of a particular particular character in a string. For example I want to capitalise the first letter in 'abcd.com'. Here I want to capitalise 'a' but I would like to know the way of getting character/text indexes in a string .
Thanks in advance
Please tell me how to fill contents into a hash array dynamically. The hash array is empty initially and it is to be filled with key value pairs (say employee no-employee name from database )so that I can process it later.
My another problem is I would like to get the index of a particular particular character in a string. For example I want to capitalise the first letter in 'abcd.com'. Here I want to capitalise 'a' but I would like to know the way of getting character/text indexes in a string .
Thanks in advance
ASKER
HI ozo
Thanks. The hash array worked fine and I could capitalise the first letter also. But I would like to know the way of getting character/substring indexes in strings in perl. I know the perl regular expressions are very powerful and it can do all kinds test processing. But still I am looking for this because I was doing my works in java and C where I could replace the character or string at a particular index. Am i asking something that is not relevant in perl?
Thanks. The hash array worked fine and I could capitalise the first letter also. But I would like to know the way of getting character/substring indexes in strings in perl. I know the perl regular expressions are very powerful and it can do all kinds test processing. But still I am looking for this because I was doing my works in java and C where I could replace the character or string at a particular index. Am i asking something that is not relevant in perl?
ASKER
HI ozo
Thanks. The hash array worked fine and I could capitalise the first letter also. But I would like to know the way of getting character/substring indexes in strings in perl. I know the perl regular expressions are very powerful and it can do all kinds test processing. But still I am looking for this because I was doing my works in java and C where I could replace the character or string at a particular index. Am i asking something that is not relevant in perl?
Thanks. The hash array worked fine and I could capitalise the first letter also. But I would like to know the way of getting character/substring indexes in strings in perl. I know the perl regular expressions are very powerful and it can do all kinds test processing. But still I am looking for this because I was doing my works in java and C where I could replace the character or string at a particular index. Am i asking something that is not relevant in perl?
substr($string,5,1) =~ s/(.)/\U$1/;
ASKER
HI ozo
would u please explain me the the code
"substr($string,5,1) =~ s/(.)/\U$1/; "
would u please explain me the the code
"substr($string,5,1) =~ s/(.)/\U$1/; "
Capitalize the fifth letter in $string
ASKER
Ozo
u did it in reverse... How do I know it is the fifth character? any buit in function? For example I want to know the index of second 'e' in 'aebcdefg'...
u did it in reverse... How do I know it is the fifth character? any buit in function? For example I want to know the index of second 'e' in 'aebcdefg'...
'aebcdefg' =~ /e[^e]*(e)/;
print $-[1];
# or
($_ = 'aebcdefg') =~ /e[^e]*e/g;
print ((pos)-1);
# to capitalize the second e
($_ = 'aebcdefg') =~ s/(e[^e]*)(e)/$1\u$2/;
print $-[1];
# or
($_ = 'aebcdefg') =~ /e[^e]*e/g;
print ((pos)-1);
# to capitalize the second e
($_ = 'aebcdefg') =~ s/(e[^e]*)(e)/$1\u$2/;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK ozo...Its working.......Tell u something... pls add some explanatory comments when u post ur answers... it will be of great help... Thanks.
boolee
boolee
$string = ucfirst 'abcd.com';