in reply to On running perl scripts

The #!/usr/bin/perl (often called the shebang line) tells a *NIX shell to load the given interpreter when it tries to execute a file.

The #! part is the ascii representation of a 'magic number' that the unix shell uses to determine file type. This one tells the shell to load up the given interpreter. If you leave this out the file will not exececute with ./filename. If you run perl and give it a filename perl will try to compile and run the contents of the file. To do this it does not need the shebang line and will skip it if it is there, the file will run just fine (assuming it is valid perl code)

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^2: On running perl scripts
by gellyfish (Monsignor) on Feb 07, 2005 at 13:49 UTC

    The #!/usr/bin/perl (often called the shebang line) tells a *NIX shell to load the given interpreter when it tries to execute a file.

    To be pedantic it is not the shell that is doing this - it is the execve(3) system function, which should be available in any POSIX compliant system.

    /J\

      Pedantic is apropriate here.

      So when you flag flag a file executable the shell just chucks it to execve(3) without bothering to look inside. execve(3) then does the magic number, er, magic.

      I do love this Monastery, you really do learn a new thing every day here

      Thanks,
      R.

      Pereant, qui ante nos nostra dixerunt!
A reply falls below the community's threshold of quality. You may see it by logging in.