perlshebangtaint

What is the significance of -T or -w in #!/usr/bin/perl?


I googled about #!/usr/bin/perl, but I could not find any satisfactory answer. I know it’s a pretty basic thing, but still, could explain me what is the significance of #!/usr/bin/perl in Perl? Moreover, what does -w or -T signify in #!/usr/bin/perl? I am a newbie to Perl, so please be patient.


Solution

  • The #! is commonly called a "shebang" and it tells the computer how to run a script. You'll also see lots of shell-scripts with #!/bin/sh or #!/bin/bash.

    So, /usr/bin/perl is your Perl interpreter and it is run and given the file to execute.

    The rest of the line are options for Perl. The "-T" is tainting (it means input is marked as "not trusted" until you check it's format). The "-w" turns warnings on.

    You can find out more by running perldoc perlrun (perldoc is Perl's documentation reader, might be installed, might be in its own package).

    For scripts you write I would recommend starting them with:

    #!/usr/bin/perl
    use warnings;
    use strict;
    

    This turns on lots of warnings and extra checks - especially useful while you are learning (I'm still learning and I've been using Perl for more than 10 years now).