Solved

Runtime hash array & text processing

Posted on 2002-05-23
10
143 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now