Intro to
Programming
with Perl

Fall 2007
course
navigation

questions

Got a question?
Ask it here, and someone (probably Jim, but anyone's two cents is welcome) will answer it.

Your question

Type away ...

Sep 15 : Global symbol "..." requires explicit package name at ...

So I get the honor of asking the first question...go figure. I'm currently working on my homework that's due on Monday (9/17) and I've run into a weird problem. I have, three times in the course of the program asked the user for an input and then expected the program to take those inputs and use them later on. If you are have trouble visualizing this, I've attached the alpha build, which is what I've got so far.
Now the trouble I'm having is when I go to run the program it doesn't give me a chance to even input numbers for the variables and citing that the addition and multiplication symbols are uninitialized. So, I guess my question here would be whether or not I'm trying to do something too incredibly complex and why won't the program stop and give me a chance to define the variables before trying to add and multiply them. Any input is appreciated (is it an id10t error?). Thanks a lot, Martin C.

Hmm, I just tried your program and it seems to run just fine. Are you using windows and running into some weird compatibility issues? John B.

Okay, turns out this was a human error. I had been trying to run the program in Text Wrangler alone, when I should've been testing it simultaneously in terminal. It runs fine in terminal, but in Text Wrangler it treats it as if the scalar variables are 0, so I now know that I need to have both programs open (I was just using one because I thought it was more efficient, turns out, I'm an idiot.) Thanks for the help guys, especially Cedar, who pointed it out to me. Also, I modified this under his logon not mine, so sorry if that causes confusion (I don't think it should, but there you go.)

This is all part of the "use strict" issue that we talked about it class (which is partly my fault for insisting on it from the beginning even though the text doesn't emphasize it). Sounds like when you run it in TextWrangler, it is not being running as "strict", while from the command line it is being run "strict". "strict" requires that you declare your variables, usually with "my". - Jim M

Sept 24 : Increment

I found that in my programs ++ didn't work to incrementally increase my variables. I typed it into the debugger and when I type "while ($v < 30) {print $v, ", "; $v = $v++" I get an infinite loop which prints "1, 1, 1, 1, 1, 1, 1,..." However, when I type "while ($v < 30) {print $v, ", "; $v = $v + 1" I get the expected response of "1, 2, 3, 4, ..." up to 29. Is this a windows thing? Has anyone else had this problem? Willson

The $x++ = ($x = $x + 1). So if you plug it into $x = $x++ you get $x = ($x = $x + 1) which might be the reason you are getting an error. Technically, without the paren's it should work, but thats my reason why it doesn't work. ++$x; $x++; $x = $x + 1 all work. Bob
http://cs.marlboro.edu/ courses/ fall2007/perl/ wiki/ questions
last modified Wednesday October 31 2007 3:42 pm EDT