Questions about this topic? Sign up to ask in the talk tab.

Perl/Basics/Your First Program/Analyzing Your First Program

From NetSec

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The shebang declares the location of the code's interpreter. I.e. if you're writing bash, you'll need to put:

 #!/bin/bash

at the top of your file. In perl, it's typically:

 #!/usr/bin/perl

This should be the first line in any perl you write. You can also use:

 #!env perl

If you are unsure of the path and you have it in your environment variables. If for some reason `#!env perl' and `#!/usr/bin/perl' do not work, running `which perl' from the bash command line will return the proper path.

This is only required if you want to directly execute your script (i.e. ./script.pl). If you get permissions errors when attempting this, you can execute it via `perl script.pl' or running `chmod +x script.pl' before running `./script.pl'.

With perl in particular, its real easy for ugliness to occur. To counter this, the next lines are:

<syntaxhighlight lang="perl">use strict; use warnings;</syntaxhighlight>

Strict perl forces you to maintain some semblence of syntax. Without the strict usage, you can basically run amok with code, perl will not care.

The print "Hello world!\n" line simply prints "Hello world!" with a newline character on the end. On windows you may need to change "\n" to "\r\n", depending on which interpreter you've installed.

You can also reference the hex code for this via a \x character, "\x0a\x0d".