Q&A

Q1: If Perl is so easy to learn, why do I need 21 days to learn it?
A1: You probably don't. If you've got 21 days and nothing else to do, you can learn a whole lot of Perl—more Perl than many people who call themselves Perl programmers know. But chances are good that you can pick up just enough Perl to get by in the first week or two, and ignore the harder stuff until you feel more adventurous or need to do more with the language. If you've already got a strong programming background in some other language, you can probably rip through these earlier chapters quite a bit faster than at the rate of a chapter a day. One of Perl's basic tenets is that you should be able to get your job done as quickly as possible with the least amount of work. If you can get your job done after reading only a little bit of this book, by all means go for it.
Q2:I have no programming background, although I've worked with HTML a lot and I know a little JavaScript. Can I learn Perl?
A2: I don't see why not. Although I've written this book for people who already have a small amount of programming background, if you work slowly through the book, do all the examples and exercises and experiment on your own, you shouldn't have too much trouble. Perl's flexibility makes it a great language for learning programming. And because you already know about other Web technologies, Perl fits right in with what you already know.
Q3:Is the code I write called a Perl program or a Perl script?
A3: It depends on how nitpicky you want to get about semantics. One argument goes that compilers compile programs and interpreters interpret scripts. So you have C and Java programs (and C and Java compilers), but JavaScript or AppleScript scripts. Because Perl is essentially an interpreted language, the code you write is a Perl script and not a Perl program. Another argument is that because what you're doing is Perl programming, you're creating a program as part of that process. A third argument is that it really doesn't matter. I like that last argument, but my editor wants me to be consistent, so I'll stick to that first argument and call them scripts.
Q4:I typed in the Hello World one-liner and I can't get it to work! Help!
A4: Are you sure you have Perl installed on your system? Getting Perl installed and working is the major task to do for today. If you flip to the back of the book, to the Appendixes, you'll find instructions on getting Perl installed and working on your system (assuming that you're on Unix, Windows, or a Mac). In addition, the docs that come with your distribution can go a long way toward helping you get everything working.
Q5:I'm on Windows. When I double-click my hello.pl script, a window comes up really quickly and then vanishes. I'm obviously doing something wrong, but what?
A5: You should be running these scripts from a command or DOS prompt, not from an Explorer window. Start a command-prompt window first, CD to the appropriate directory, and then try running your script using the examples earlier in this chapter. For Windows 2000 you'd usually just type the name of your script. For Windows ME type perl -w and the name of your script. Here's a simple example:
C:> cd ..scripts
C:scripts> perl -w hello.pl

Q6:I'm on Windows. You mention that the #! (“shebang”) line at the start of the file is a Unix thing. Why do I have to include it if I'm not on Unix and don't intend to ever be on Unix?
A6: You don't, if you don't expect your Perl scripts to ever need to run on Unix (although watch out, some Web servers might require it for Perl scripting). Because the shebang line starts with a hash, it's actually a Perl comment, so it's ignored by the Windows Perl interpreter. You don't need to include it. But it's a good habit to get into, should you ever need to write Perl scripts on Unix, or worse, convert everything you've ever written on Windows to Unix.
Q7:In your examples, some of your print commands use double-quotes, and others use single quotes. Why?
A7: Good catch! There's a specific reason for that, involving whether or not you use or variable names inside the thing you're printing. You'll learn about the difference tomorrow.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset