Looks OK, after it's been through the syntax check (perl -c scriptname), we run it and all we get is a blank line again! Hmmmm. Ok, but how about when you want to really see your data, what's in that dynamic variable, just before using it? #!/usr/bin/perl Just getting this script to compile has exposed the '$varl' (with the letter 'l') variable, and simply changing $varl to $var1 solves the problem. We then do (always a good idea) a syntax check before we try to run it again: > perl -c helloĪnd now when we run it, we get "\n" still, but at least we know why. Luvverly! and to fix this we declare all variables explicitly and now our script looks like this: #!/usr/bin/perl hello aborted due to compilation errors. Global symbol "$var2" requires explicit package name at. Global symbol "$varl" requires explicit package name at. Now when you run it, perl complains about the 3 undeclared variables and we get four error messages because one variable is referenced twice: Global symbol "$var1" requires explicit package name at. To catch this kind of problem, we can force each variable to be declared before use by pulling in the strict module, by putting 'use strict ' after the first line of the script. It looks like there's 2 variables when (because of the typo) there's really 3: $var1 = 'Hello World' That is, it will print out a newline character, and you'll get what looks like a blank line. While this compiles and runs happily, it probably won't do what's expected, namely it doesn't print "Hello World\n" at all It will on the other hand do exactly what it was told to do, computers being a bit that way inclined. $var1 = 'Hello World' # always wanted to do that :-) To demonstrate, here's a simple script, named "hello", with a problem: #!/usr/bin/perl # use strictįirst of all, there's a few things you can do to make your life a lot more straightforward when it comes to debugging perl programs, without using the debugger at all. There's an extraordinary number of people out there who don't appear to know anything about using the perl debugger, though they use the language every day. Perldebtut - Perl debugging tutorial #DESCRIPTIONĪ (very) lightweight introduction in the use of the perl debugger, and a pointer to existing, deeper sources of information on the subject of debugging perl programs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |