Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-24 17:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found