Difference between revisions of "Perl/Basics/Your First Program/Analyzing Your First Program"
AlizaLorenzo (Talk | contribs) (Created page with "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: ...") |
Chantal21I (Talk | contribs) m (moved Perl/Basics/Analyzing Your First Program to Perl/Basics/Your First Program/Analyzing Your First Program) |
(No difference)
|
Latest revision as of 00:06, 19 July 2012
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".