Messing w/ print
DEBUGGING AND LEARNING
Sometimes I mess around with Perl like this:
No such class throw_up at app.pl line 11, near "my $throw_up"
syntax error at app.pl line 11, near "my $throw_up ="
Execution of app.pl aborted due to compilation errors.
I was a bit confused, So I looked carefully at the message, and turns out. The error was due to forgetting the dollar sign ($
) in front of my variable haha.. I forget that in Perl, variables need that $
to show they’re scalars. So I fixed my code like this:
That fixed the error, but I still had some questions in my mind, what if:
I got some warnings that made me scratch my head 🙆:
The result is just 5
, I didn’t understand why the + 2
didn’t seem to change anything. I thought maybe printing $throw_up
again would show that the addition somehow affected its value. So I ran this code:
The output still showed 5
, not 7
. It became clear that the addition was ignored, even after printing $throw_up
again. Such a stupidity ଘ( ᐛ ) ଓ
To simplify things, I rewrote the code:
And like this:And also like this:
All of these work.
Remember about context, context, context...
It's made clearer and easier to understand this wierdo language in my opinion ╮ (. ❛ ᴗ ❛.) ╭