Solved

Replacing a value in a hash

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

867 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

24 Experts available now in Live!

Get 1:1 Help Now