You’ll need one more tool in order to begin
working magic with Perl: a text editor
.
Actually, you’ll probably want two of them because you will be writing your Perl scripts in two different places. Sometimes you will write them on your desktop PC (or Mac), then will transfer them to your ISP’s Unix server using an FTP program (like WS_FTP for the PC, or Fetch for the Mac). Other times you will create your scripts right there on the Unix machine using a Unix text editor.
Tip
Because FTP is an unencrypted protocol, it is prone to the same security problems as Telnet is. For that reason, you may wish to investigate using an encrypted protocol for your file transfers. Martin Prikryl’s WinSCP (http://winscp.vse.cz/eng/) offers a nice Windows implementation of the secure scp protocol (which uses ssh for security) to do file transfers. For Mac users, the aforementioned NiftyTelnet (http://andrew2.andrew.cmu.edu/dist/niftytelnet.html) also does scp file transfers. (Mac users running OS X can also use the scp command-line program directly.)
The traditional text editors used in the Unix environment are
emacs
and
vi
(the latter pronounced
“vee-eye”). Both are extremely powerful and
full-featured. Both can also be a bit intimidating for beginners.
Because of that, I’m actually going to focus on a simpler
(albeit less powerful) editor called
pico
for this book’s
text-editing-under-Unix examples. If pico
is not
available on your system, you may need to buckle down and learn
emacs
or vi
whether you want to
or not. In that case, see The Traditional Unix Editors: emacs and vi
later in this chapter.
Whichever tools you end up using, the bottom line is that you’re going to need some way to edit text on both your desktop computer and the Unix server. Editing in each environment will have its pluses and minuses. Writing scripts on your PC will probably feel more familiar to you, at least at first. You can use your mouse for selecting text, and can work on your script when you’re not actually connected to the Internet. The downside is that you’ll have to use an FTP program to move your script to the Unix server every time you make a change to it. Writing your scripts directly on the Unix machine lets you avoid the file-transfer step. You’ll have to gain at least a passing familiarity with a Unix text editor, though, which means learning a bunch of keyboard commands to move around within the file, since you won’t be able to do things with your mouse.
I edit on the Unix server for small scripts and on my local PC for
larger projects. You may have already dealt with this issue when
deciding how to create HTML files for your web site, assuming you are
coding your HTML by hand, rather than using an HTML authoring
program. There’s one important difference, though: if
you’re creating the scripts on your local PC or Mac, then
uploading them to your Unix server via FTP, you must make the FTP transfer in
text
mode
(sometimes called ASCII
mode,
depending on your FTP program). This typically
doesn’t make any real difference when uploading HTML files, but
it matters a lot for Perl scripts: if you upload your Perl scripts in
binary mode,
they probably won’t work.
This is because each type of computer (Unix, PC, and Macintosh) uses
a different sequence of characters to mark the end of a line of text.
Transferring in ASCII mode causes the FTP program to convert the line
endings for you on the fly.
You may be inclined to try to use a word processor program (like Microsoft Word) to create and edit your Perl scripts when you’re working on the local PC, but I would advise against it. Because they have been optimized for the specific task of outputting attractive paper-based documents, modern word processors are a poor choice for editing straight ASCII text. You’ll be much happier with something that doesn’t try to convert all your straight quotes to curly quotes and flag all your Perl syntax as misspelled and ungrammatical. On the Windows side, I’ve been very happy with a freeware program called EditPad (available at http://www.editpadpro.com/editpadclassic.html); a shareware program called UltraEdit (http://www.ultraedit.com/) is also very good. On the Mac side, a program called BBEdit Lite (see http://www.barebones.com/) is very popular.
This chapter has presented only a shallow introduction. If you are anything like me, you will be able to continue to learn more about choosing web hosting vendors, working in the Unix shell, troubleshooting network problems, and using text editors for many years to come. With the information presented here, though, you should be able to take your first steps and begin doing useful work. In particular, you should now be ready for the next chapter, in which you get your first exposure to the Perl programming language.
Get Perl for Web Site Management now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.