Solved

Runtime hash array & text processing

Posted on 2002-05-23
10
147 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
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.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

829 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