Minichan

Topic: More Perl assistance?

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.)

This is the code I had written so far.
http://pastebin.com/vc2SSM79
(Expires in 1 Day)

When I tested it in cmd it gives me these errors.

> Use of uninitialized value $seminar in hash element at c05ex5.cgi line 32.

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.

http://pastebin.com/EDrnPkNZ
(Expires in 1 Day)

Anonymous B joined in and replied with this 12 years ago, 20 minutes later, 27 minutes after the original post[^] [v] #471,020

> seminar
> Seminar

Anonymous A (OP) replied with this 12 years ago, 38 minutes later, 1 hour after the original post[^] [v] #471,022

@previous (B)
I have corrected that since making this post.

Anonymous B replied with this 12 years ago, 1 minute later, 1 hour after the original post[^] [v] #471,023

@previous (A)
eh? So what happened? I thought PERL was case sensitive about that shit

(Edited 1 minute later.)

Anonymous C joined in and replied with this 12 years ago, 3 minutes later, 1 hour after the original post[^] [v] #471,024

Homework thread?

Anonymous A (OP) replied with this 12 years ago, 1 minute later, 1 hour after the original post[^] [v] #471,025

@471,023 (B)
That must not be the issue. I still get the message. I e-mailed my instructor.

Anonymous C replied with this 12 years ago, 2 minutes later, 1 hour after the original post[^] [v] #471,026

Homework thread.

Anonymous B replied with this 12 years ago, 23 seconds later, 1 hour after the original post[^] [v] #471,027

@471,025 (A)
And why are there double quotes around one but not the other?

Anonymous B double-posted this 12 years ago, 2 minutes later, 1 hour after the original post[^] [v] #471,028

@471,026 (C)
Yep.

beckyderp !8ElfFaoFao joined in and replied with this 12 years ago, 57 minutes later, 2 hours after the original post[^] [v] #471,029

Dude, don't copy/paste instructions while asking for homework help on a googlable site.

Anonymous B replied with this 12 years ago, 3 minutes later, 2 hours after the original post[^] [v] #471,030

@previous (beckyderp !8ElfFaoFao)
But... moar bots?

EDIT: Oh, yeah. I get it. It's bad for him.

(Edited 2 minutes later.)

beckyderp !8ElfFaoFao replied with this 12 years ago, 6 minutes later, 2 hours after the original post[^] [v] #471,031

@previous (B)
Yes. But more bots, too. (Obese beagles) (I just got fucked in the ass for the first time)

(Edited 1 minute later.)

Anonymous C replied with this 12 years ago, 4 minutes later, 2 hours after the original post[^] [v] #471,032

@previous (beckyderp !8ElfFaoFao)
Was he a gentle lover?

beckyderp !8ElfFaoFao replied with this 12 years ago, 1 minute later, 2 hours after the original post[^] [v] #471,033

Externally hosted image@previous (C)

Anonymous B replied with this 12 years ago, 2 minutes later, 2 hours after the original post[^] [v] #471,034

@471,031 (beckyderp !8ElfFaoFao)
FUCKING OBEAGLE CUNTBOTS!!!!

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

Externally hosted image@previous (C)

Anonymous C replied with this 12 years ago, 2 minutes later, 2 hours after the original post[^] [v] #471,037

@previous (beckyderp !8ElfFaoFao)
Your're right, there's no such thing as too much lube. I'm glad you enjoyed it, but did you climax?

beckyderp !8ElfFaoFao replied with this 12 years ago, 1 minute later, 2 hours after the original post[^] [v] #471,038

@previous (C)
There is such a thing as too much lube. Let's be reasonable here.

Anonymous C replied with this 12 years ago, 2 minutes later, 2 hours after the original post[^] [v] #471,039

@previous (beckyderp !8ElfFaoFao)
I think once you have filled a bathtub with lube, it's probably enough and time to jump in

Anonymous B replied with this 12 years ago, 9 minutes later, 2 hours after the original post[^] [v] #471,040

@Becky
Dearest Becky,

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

@471,040 (B)
Okay, kook.

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

@previous (B)
> haunt my dreams

Lube tub nightmares, or day terrors?

Anonymous B replied with this 12 years ago, 31 minutes later, 4 hours after the original post[^] [v] #471,066

@previous (C)
Both.

Anonymous F joined in and replied with this 12 years ago, 6 hours later, 11 hours after the original post[^] [v] #471,087

@OP
Does one of the input lines not have a tab character, or is empty perhaps? That would cause your split to fail.

TTEH !JXsxEkDBLs joined in and replied with this 12 years ago, 1 hour later, 12 hours after the original post[^] [v] #471,094

@471,020 (B)
First thing I noticed too lol, I pointed it out in irc but it didn't fix it.

Anonymous A (OP) replied with this 12 years ago, 2 hours later, 15 hours after the original post[^] [v] #471,135

@471,087 (F)
I made sure to type thee tab character correctly.

Anonymous F replied with this 12 years ago, 2 minutes later, 15 hours after the original post[^] [v] #471,136

@previous (A)
Upload the file. Show me.

Anonymous A (OP) replied with this 12 years ago, 5 hours later, 20 hours after the original post[^] [v] #471,180

@previous (F)
Here is my most recently code featuring both the html and cgi used.
(Expires in 1 Day)

http://pastebin.com/cCnuYr8c

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

@previous (A)

Anonymous F replied with this 12 years ago, 40 minutes later, 21 hours after the original post[^] [v] #471,185

@471,183 (A)
You can, you just need to use it both when reading and writing. When writing you use | when reading you use \t.

Anonymous A (OP) replied with this 12 years ago, 7 minutes later, 22 hours after the original post[^] [v] #471,188

@previous (F)
Lines 27-31 of my code.

> foreach my $rec (@records) {
> chomp($rec);
> ($name, $seminar) = split(/\t/, $rec);
> $seminar_count[$seminar] = $seminar_count[$seminar] + 1;
> }

Use of uninitialized value $seminar in array element at c05ex5.cgi line 30.

Anonymous F replied with this 12 years ago, 2 minutes later, 22 hours after the original post[^] [v] #471,189

@previous (A)
...Yes?

> split(/\t/, $rec)
> \t

> print OUTFILE "$name|$seminar\n";
> |

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

@previous (A)
And what is in c05ex2.txt?

Anonymous A (OP) replied with this 12 years ago, 15 minutes later, 22 hours after the original post[^] [v] #471,198

@previous (F)

It just contains...


Janice Alto,3
Nancy Perez,1
James Houza,2
Beth Jimminez,2
Michael Hiller,4
Inez Smith,4
Paul Eniudo,3
Tess Bacza,2
Robert Hau,1
Opal Jones,2

Anonymous F replied with this 12 years ago, 1 minute later, 22 hours after the original post[^] [v] #471,199

@previous (A)
I'm assuming you fucked up the copy&paste since those aint tab characters.

Anonymous A (OP) replied with this 12 years ago, 5 minutes later, 22 hours after the original post[^] [v] #471,200

@previous (F)
I was wondering if this forced me to use a comma.

Anonymous F replied with this 12 years ago, 26 seconds later, 22 hours after the original post[^] [v] #471,201

@previous (A)
what

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

@471,188 (A)
> foreach my $rec (@records) {
> chomp($rec);
> ($name, $seminar) = split(/\t/, $rec);
> $seminar_count[$seminar] = $seminar_count[$seminar] + 1;
> } catch( JAXBException je ) {
> je.printStackTrace();
> } catch( IOException ioe ) {
> ioe.printStackTrace();
> }
> System.out.println( "\t" + address.getName() );
> System.out.println( "\t" + address.getStreet() );
> System.out.println( "\t" + address.getCity() +
> ", " + address.getState() +
> " " + address.getZip() );
> System.out.println( "squeegee was here" + address.getCountry() + "\n");
> }

fix'd that right up for you

Anonymous F replied with this 12 years ago, 2 minutes later, 23 hours after the original post[^] [v] #471,204

@previous (squeegee !first/o5zA)
someone likes java

Anonymous A (OP) replied with this 12 years ago, 40 seconds later, 23 hours after the original post[^] [v] #471,205

@471,203 (squeegee !first/o5zA)
This looks advanced.

Anonymous B replied with this 12 years ago, 33 minutes later, 1 day after the original post[^] [v] #471,206

@471,203 (squeegee !first/o5zA)
> System.out.println( "squeegee was here" + address.getCountry() + "\n");
LOL'd

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

@previous (A)
And this should be the html.

"
<!c05ex5.html>
<HTML>
<HEAD><TITLE>Seminar Workshop</TITLE></HEAD>
<BODY>
<H1>Seminar Workshop Registration Information</H1>
<A HREF="../../cgi-bin/chap05/c05ex5.cgi">View Registration Information
"

Anonymous F replied with this 12 years ago, 47 minutes later, 1 day after the original post[^] [v] #471,255

@471,247 (A)
Spoilers: http://pastebin.com/VpwDvhty

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.

Did I do it right?

My code: http://pastebin.com/eXTm1CKZ
(Expires in 1 Day)

I am unsure if I need to assign variables or not.

(Edited 39 seconds later.)

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

@471,343 (A)
grade

dw !jdTkvovFCQ double-posted this 12 years ago, 17 seconds later, 2 days after the original post[^] [v] #471,346

@471,344 (A)
grade

Anonymous A (OP) replied with this 12 years ago, 10 minutes later, 2 days after the original post[^] [v] #471,349

@471,345 (dw !jdTkvovFCQ)
100.00% (A)

Anonymous A (OP) double-posted this 12 years ago, 56 seconds later, 2 days after the original post[^] [v] #471,350

@471,346 (dw !jdTkvovFCQ)
100.00% (A)

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.

Here's my code: http://pastebin.com/J0MSAVdY
(Expires in 1 Day)

Here's my html: http://pastebin.com/HHpX0as9
(Expires in 1 Day)

(Edited 3 minutes later.)

beckyderp !8ElfFaoFao replied with this 12 years ago, 4 hours later, 1 week after the original post[^] [v] #471,978

Externally hosted image@previous (A)

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.

http://www.tutorialspoint.com/perl/perl_regular_expression.htm
http://affy.blogspot.co.uk/p5be/ch10.htm
http://www.misc-perl-info.com/perl-tr.html

How many people on MC are familiar with Perl, anyway?
:

Please familiarise yourself with the rules and markup syntax before posting.