Solved

Replacing a value in a hash

Posted on 2001-09-18
4
122 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
Comment Utility
> .. [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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

16 Experts available now in Live!

Get 1:1 Help Now