Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Replacing a value in a hash

Posted on 2001-09-18
4
Medium Priority
?
144 Views
Last Modified: 2010-03-05
Gentlepeople:

I'm horribly frustrated with a web form ...

I've got a form that contains fields "Type" and "Catno".
I've got a cgi script that, using cgi-lib.pl (and written in Perl 4) grabs all the many fields and puts them into a hash (I think), called FORMSTUFF.

As originally conceived, the form allows users to make entries that are inconsistent between Type and Catno, but I've now realized  I can derive Type from Catno, in all cases.

What I've got going now (it works, but it makes the user do the work), is a comparison of two variables containing the initial letters of both fields, and an elaborate if statement that, on disagreement, presents them with an intermediate form in which they can change either value to  agree with the other.

All I want to do is to edit Type to be a predictable text ("ART", "ONL", or "PUB") depending on the first letter of Catno.

I don't understand the syntax, but  the code that works to print the Type field is:
print FILE "$FORMSTUFF{('Type')}\t";              [all single quotes are right quotes]
and the code that works to regenerate it to a summary form on a new screen is:
<B> $FORMSTUFF{('Type')} </B>
But trying to assign with the same syntax, e.g.
if ($vcat eq "A") {
  $FORMSTUFF{('Type')} = "ART"        [do I need a ";" here?]
}
doesn't seem to work.

What would?

It would be inelegant but no problem to me to add an altogether new item to the hash to contain the value, and report that one out INSTEAD of the captured content ... if the fact the form is still open makes replacement impossible.

Many thanks for all ideas!

Marilyn Justman
0
Comment
Question by:mjustman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 400 total points
ID: 6491855
> .. [do I need a ";" here?]
YES.

> .. to add an altogether new item to the hash ..
$FORMSTUFF{'new alltogether item'} = 'put your value here';
0
 

Author Comment

by:mjustman
ID: 6491887
ok.  If it's as simple as adding the ";", I'll give the old code a new try.

When I tried to add the alltogethernew item, I put double quotes on the right of the "=".  Was that wrong?

Don't anybody else answer till I've tested this and probably given the points to a hoffman!  Thanks.

mj
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6491899
single quotes quote a string as is, as literal string, while double quotes sunstitute perl variables within the quoted string (see perldoc).
So, in your case it doesn't matter.
0
 

Author Comment

by:mjustman
ID: 6494947
Thanks.  A thousand capitalization and punctuation errors later, you were right...it should have worked the first time, with one extra ";".  Now my test stuff seems to be all right.

Also turns out my ISP was having problems the day I was doing this, so just maybe part of my problems weren't caused by me at all...

Marilyn Justman
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

618 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