Solved

Runtime hash array & text processing

Posted on 2002-05-23
10
146 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:boolee
  • 5
  • 5
10 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 7030685
$hash{$employee_name} = $employee_no;

$string = ucfirst 'abcd.com';
0
 
LVL 1

Author Comment

by:boolee
ID: 7031431
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?
0
 
LVL 1

Author Comment

by:boolee
ID: 7031481
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?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 84

Expert Comment

by:ozo
ID: 7033295
substr($string,5,1) =~ s/(.)/\U$1/;
0
 
LVL 1

Author Comment

by:boolee
ID: 7036527
HI ozo

would u please explain me the the code

"substr($string,5,1) =~ s/(.)/\U$1/; "
0
 
LVL 84

Expert Comment

by:ozo
ID: 7038435
Capitalize the fifth letter in $string
0
 
LVL 1

Author Comment

by:boolee
ID: 7041002
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'...
0
 
LVL 84

Expert Comment

by:ozo
ID: 7041041
'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/;


0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 7041052
($_ = 'aebcdefg') =~ /e[^e]*/g;
print pos;

#or

print index($_,"e",index($_ = 'aebcdefg',"e")+1);


0
 
LVL 1

Author Comment

by:boolee
ID: 7041570
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
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question