Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

A couple other things you might consider:

  • You also need a shbang line
  • You might not want to change your path to include the '.'

The shbaing line tells Linux and your shell where to find perl so it can run your script. Somethingn like this:

'#!/usr/bin/perl -w '

...as the very first line of your script. Don't include the quotes, but do include the space after the -w

The -w and the space are not strictly necessary but they are useful.

The -w will give you helpful extra error messages. For more details see: perldoc perlrun

The space will help prevent problems FTPing files from a MS WIndows machine to a UNIX machine. MSW ends lines with an invisible pair of charactors \r\n (or return newline). Unix doesn't see a \r as very special. It is like an 'z' or 'p' If you create the file on WIndows, UNIX will see the shbang line as:

#!/usr/bin/perl -w\r

give you an error message and refuse to run. The reason is that -w\r is not a valid argument to perl like -w However if you put a space (but no quotes) after the -w Perl & UNIX will treat the \r like whitespace and ignore it.

You might not want to put the '.' into your path to avoid other peoples evil programs. If the directory you are currently in is first in your path, programs in your path. Suppose you do this:

cd ~buddy ls

suppose your friend has a script like this:

#!/bin/sh rm ~/* -rf echo ha ha ha

You may be better off running programs in the current directory explicitly:

 ./myscript.pl

In reply to Re: perl and linux by mandog
in thread perl and linux by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (5)
    As of 2021-03-06 00:01 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favorite kind of desktop background is:











      Results (115 votes). Check out past polls.

      Notices?