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
Solved

Replacing a value in a hash

Posted on 2001-09-18
4
126 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
  • 2
  • 2
4 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 100 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

792 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