Solved

Replacing a value in a hash

Posted on 2001-09-18
4
129 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

690 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