Anonymous A started this discussion 12 years ago#34,105
In my class we have to...
create a script for Seminar Workshop. The script displays, on a Web page, the number of people registering for each of four different seminars. The script also displays the total number of registrants. The registration data is stored in a file named c05ex5.txt.
Open the c05ex5.txt file, which is contained in the cgi-bin/chap05 directory, in a text editor. The file contains 10 records. Each record consists of two fields: the registrant's name and a seminar number. (Seminar 1 is the Computer Maintenance seminar, 2 is the Microsoft Office seminar, 3 is the Unix Essentials seminar, and 4 is the CGI/Perl seminar.
Create a script named c05ex5.cgi that displays a Web page similar to the one shown in Figure 5-22. The Web page displays the number of people registered for each seminar, and the total number of registrants. (Hint: Use an array of counters to calculate the number of people registering for each seminar.)
Anonymous A (OP) double-posted this 12 years ago, 6 minutes later[^][v]#471,017
Here is my HTML code. I've used my other projects from this chapter as a source to look upon, but I have no idea how to apply this to a name field. I used a name field as it seemed appropriate for this assignment.
Anonymous C replied with this 12 years ago, 57 seconds later, 2 hours after the original post[^][v]#471,035
@471,033 (beckyderp !8ElfFaoFao)
He looks like the type of guy that would press his cock against your butthole, waiting patiently for your anus to accept him.
Did you use enough lube?
beckyderp !8ElfFaoFao replied with this 12 years ago, 2 minutes later, 2 hours after the original post[^][v]#471,036
I have a bathtub full of lube and would like to invite you over for a quaint dinner-for-two by candlelight. I am not sure if I have bought enough lube. Please advise.
Thans, Thanx, T.hanx
Anon B
(Edited 1 minute later.)
beckyderp !8ElfFaoFao replied with this 12 years ago, 5 minutes later, 2 hours after the original post[^][v]#471,041
@previous (B)
You have bought enough lube. Thanks.
Anonymous E joined in and replied with this 12 years ago, 47 seconds later, 2 hours after the original post[^][v]#471,042
Anonymous B replied with this 12 years ago, 1 minute later, 3 hours after the original post[^][v]#471,043
@471,041 (beckyderp !8ElfFaoFao)
Super. When can I expect you? I need to know when to start cooking.
Anonymous C replied with this 12 years ago, 11 seconds later, 3 hours after the original post[^][v]#471,044
@471,041 (beckyderp !8ElfFaoFao) > but did you climax?
Anonymous B replied with this 12 years ago, 39 minutes later, 3 hours after the original post[^][v]#471,050
@471,042 (E)
Sorry, not Kook. BP is probably busy wondering what sorts of things could be done in a bathtub full of lube. (It's gonna haunt my dreams for a while, too.)
Anonymous C replied with this 12 years ago, 28 minutes later, 4 hours after the original post[^][v]#471,055
Anonymous F replied with this 12 years ago, 4 minutes later, 20 hours after the original post[^][v]#471,182
@previous (A)
Ok so the problem is that on line 57 in that pastebin it's not splitting correctly on \t? It seems to me that:
1) On line 46 you're writing a | and not a \t
2) That the file will always have a final, empty, line which thus will never contain a \t, or a |, this it will not be splittable when iterated over
Anonymous A (OP) replied with this 12 years ago, 13 minutes later, 21 hours after the original post[^][v]#471,183
@previous (F)
So can you not use a \t character to separate the two variables?
I noticed there is another problem. When I test the script in cmd. It doesn't tally up the total number of selections for each seminar.
It's suppose to show a page that shows how many signed up for what seminar and then show the total of all registered participants.
I'm also including an image of how the finished product should look.
Anonymous A (OP) double-posted this 12 years ago, 5 minutes later, 21 hours after the original post[^][v]#471,184
Anonymous A (OP) replied with this 12 years ago, 7 minutes later, 22 hours after the original post[^][v]#471,190
@previous (F)
I changed the | to \t so it's print OUTFILE "$name\t$seminar\n"; now.
Anonymous F replied with this 12 years ago, 4 minutes later, 22 hours after the original post[^][v]#471,193
@previous (A)
Ok. And that runs? I would assume it to crash when processing the latest line now. Add some print statements to figure out what's going on.
Anonymous A (OP) replied with this 12 years ago, 8 minutes later, 22 hours after the original post[^][v]#471,195
@previous (F)
The script runs, but I still get the error message as above and the numbers can't tallying up.
(Edited 17 seconds later.)
Anonymous F replied with this 12 years ago, 1 minute later, 22 hours after the original post[^][v]#471,196
Anonymous F double-posted this 12 years ago, 6 minutes later, 22 hours after the original post[^][v]#471,202
@471,198 (A)
I have to go, but a few observations...
The @ is used for arrays, and % is used for hashmaps if I recall correctly. Your seminar_count is an array, so it cannot have strings as keys. You want a hashmap, probably.
You use the seminar variable twice... Once for "$seminar = param('Seminar');" and once for "($name, $seminar) = split(/\t/, $rec);". The second one is not scoped with my, so that might be bleeding out. http://pastebin.com/M2K5B9gr kind of works, but not with strict mode enabled. Not sure why it's complaining there.
squeegee !first/o5zA joined in and replied with this 12 years ago, 35 minutes later, 23 hours after the original post[^][v]#471,203
Anonymous A (OP) replied with this 12 years ago, 1 hour later, 1 day after the original post[^][v]#471,207
This pisses me off. I get the feeling it should be simpler than this and I'm overcomplicating things. The instructor is on Caribbean cruise so his time is limited, but at least he promises he won't be able to grade until next week.
Anonymous B replied with this 12 years ago, 35 minutes later, 1 day after the original post[^][v]#471,210
@previous (A) > I get the feeling it should be simpler than this and I'm overcomplicating things.
You probably are. Just trace through the code and evaluate each instruction. Write it down on paper if you need to. Someone who has been doing this for 20 years could probably just tap out a few lines and be done. That's not you yet. PERL is fucking nuts and is regarded, even by old C programmers who don't wash or shave and use emacs as if it were an operating system, as crazy new-fangled skullduggery. PERL is hard. It's complex.
People who write code for a living have written code, and then revised it, and then revised it, and then realized they were making run-on sentences, and then they realized that they were going about the entire task in completely the wrong way; then they revised the code some more. And then then realized the whole idea was silly and the "brilliant" function they wrote to do $X can be accomplished in nine lines of code posted by some neckbeard on a UNIX forum in 2005. Ho-hum. Welcome to programming.
Anonymous E replied with this 12 years ago, 2 hours later, 1 day after the original post[^][v]#471,218
@op
This course is clearly above you. Have you tried finger painting?
Anonymous F replied with this 12 years ago, 2 hours later, 1 day after the original post[^][v]#471,222
@471,210 (B)
Heh, I've been writing code for like 10 years now, and perl still annoys me. Never put much time into learning it, but seriously who thinks it's a good idea to have different prefixes for variables that define what type they are.
Syntax joined in and replied with this 12 years ago, 4 hours later, 1 day after the original post[^][v]#471,240
@previous (F) > it's a good idea to have different prefixes for variables that define what type they are.
Its more better to give member variables a prefix so that they can easily be distinguished from normal variables.
AND I see pgms C++ that use m_ and other programs that use more better mul_ & s_ for static and g_ for global, yet many fail to make programs readable in as English.
Anonymous F replied with this 12 years ago, 2 minutes later, 1 day after the original post[^][v]#471,241
@previous (Syntax)
What. I mean % for hashmaps and @ for arrays and $ for regular variables, which appears to be mandated by perl. Besides that I am not entirely sure what you are trying to communicate. Can someone translate this from syntax to english?
Anonymous J joined in and replied with this 12 years ago, 7 minutes later, 1 day after the original post[^][v]#471,242
@previous (F)
He's just rambling on about his usual inane bullshit about his life experience. He actually typed out a paragraph about wining and dining a young Richard Stallman but deleted it.
Syntax replied with this 12 years ago, 9 minutes later, 1 day after the original post[^][v]#471,243
@471,241 (F)
I R not a code riter. I R a Hardware Engineer that uses a mass of code to run Hardware. Run in2 code with blanks in the text of array keys. AND I wood much rather see integer values for i and j rather than characters. Coding in say 4GLTE systems use a mass of multi-dimensional arrays. Then someone comes along with "$i,$j" parsed into a string that is more better then "$i, $j"
ah n remember I am burdened with dyslexia so make ur coding read as simple English. PERL is usually close nuff for me. C++ not so much.
Anonymous A (OP) replied with this 12 years ago, 1 hour later, 1 day after the original post[^][v]#471,247
I asked on the discussion boards for the course. Someone said...
"You should look at your split function again. You also don't need to save anything in this script.
You should also delete the three extra records from your c05ex5.txt file."
I assume he spotted the same thing with the split function as you all did, but I'm confused about the last 2 sentences.
Anonymous A (OP) double-posted this 12 years ago, 19 minutes later, 1 day after the original post[^][v]#471,249
Basically what I have been saying all along... Dunno what was meant with the "three extra records"
Anonymous A (OP) replied with this 12 years ago, 9 hours later, 2 days after the original post[^][v]#471,286
Can someone here check my code?
> Instruction > Create a script named c05ex4b.cgi. The script should display the contents of the c05ex4.txt file on a Web page. Display each record (name, serial number, model number, and operating system letter) on a separate line, with a tab separating each field in the record.You will need to use the pattern /\|/ in the split function. As you learned in Chapter 3, the backslash alerts Perl to ignore the special meaning of a character and simply treat the character—in this case, the pipe symbol—verbatim.
Anonymous B replied with this 12 years ago, 45 minutes later, 2 days after the original post[^][v]#471,287
@previous (A) > Can someone here check my code?
I really would like to, but St. Patrick's Day and some douche-waffle thinks he can drink more Guinness than I can. I feel bad for him.
Anonymous A (OP) replied with this 12 years ago, 1 hour later, 2 days after the original post[^][v]#471,294
@previous (B)
I may have figured it out on my own with the help of a classmate, so don't feel bad.
Anonymous B replied with this 12 years ago, 11 minutes later, 2 days after the original post[^][v]#471,296
@previous (A)
I don't feel bad. I'm a little amazed I'm still awake. Please let us know how it works out. I feel like we're all learning PERL along with you.
Anonymous A (OP) replied with this 12 years ago, 12 hours later, 2 days after the original post[^][v]#471,343
I just learned that variables do not need to be declared if you remove use strict.
Anonymous A (OP) double-posted this 12 years ago, 15 seconds later, 2 days after the original post[^][v]#471,344
I just learned that variables do not need to be declared if you remove use strict.
dw !jdTkvovFCQ joined in and replied with this 12 years ago, 19 minutes later, 2 days after the original post[^][v]#471,345
Anonymous A (OP) triple-posted this 12 years ago, 4 days later, 1 week after the original post[^][v]#471,968
I need some more help, but I think I almost got it.
I need to make the names appear until their specific job. It currently displays one name, but not both. I assume there is something wrong with my for loop.
Anonymous L joined in and replied with this 12 years ago, 3 weeks later, 4 weeks after the original post[^][v]#474,487
@previous (beckyderp !8ElfFaoFao) > needs more lube
Catherine !TGirlYJKXM (OP) replied with this 12 years ago, 6 days later, 1 month after the original post[^][v]#475,322
What are these instructions asking exactly? Does it call for a sub function?
> g. Modify the script so that it removes any leading and trailing spaces from the input data. > h. Modify the script so that it can handle a sales amount entered with a dollar sign and/or comma. (Hint: Use the tr/// operator to remove these characters from the number.) > i. Modify the script so that it can handle a bonus rate entered as a whole number, a floating-point number, and a number with a percent sign—for example, 5, .05, 5.0, 5.0%, and 5%.
If anyone has any understanding of how the tr///, m//, or s/// operators work, please help me out here. I can understand the jist of it just fine though.
Killer Lettuce !!iNo3FkiZx joined in and replied with this 12 years ago, 13 minutes later, 1 month after the original post[^][v]#475,323
@previous (Catherine !TGirlYJKXM)
Have you tried reversing the polarity? It's probably a long shot, but it might make things clearer.
Hope that helps.
Anonymous N joined in and replied with this 12 years ago, 6 minutes later, 1 month after the original post[^][v]#475,324
@475,322 (Catherine !TGirlYJKXM)
This is stuff you could really easily Google.