in reply to Checking for data entry

Well .. that'd work. I'd normally use something like this, though:
my $StartDir = shift @ARGV or die "Usage: $0 <startdir>\n";
That way, it's immediately obvious to the user that you expect a single parameter, which is a directory to start in, and it's obvious to someone maintaining your code exactly what you expect and where it comes from. $0 simply echos the command used to run the script.

One small bug: shift shifts from @_ by default, not @ARGV - you'll need to explictly specify @ARGV to read command line parameters.

You won't need to chomp a parameter normally, no - the newline isn't passed into the script by the shell.

Hope that helps.

-- Foxcub
#include www.liquidfusion.org.uk

Update: Struck out an (obvious) mistake, now I think about it and it's been pointed out :) (thanks, fletcher_the_dog)

Replies are listed 'Best First'.
Re: Re: Checking for data entry
by fletcher_the_dog (Friar) on Jul 08, 2003 at 19:21 UTC
    One small bug: shift shifts from @_ by default, not @ARGV - you'll nee +d to explictly specify @ARGV to read command line parameters.
    This is not true, "shift" shifts from @ARGV unless you are inside a subroutine.
Re: Re: Checking for data entry
by Anonymous Monk on Jul 08, 2003 at 15:42 UTC
    I am kind of lost here. I only want one parameter entry not several so I would just need this?
    my $StartDir = shift || die "Usage: $0 <startdir>\n";
    and this is if I ever wanted several parameters in another script in the future I would use this?
    my $StartDir = shift @ARGV || die "Usage: $0 <startdir>\n";
      Shift just gets you the first element of the array and removes it from the array so a subsequent shift will get the next element and so on. With no array specified it uses @ARGV (or @_ in a subroutine), so the versions you give are equivalent in this case, each checking just one argument.

      Similar but NOT equivalent would be:

      my $StartDir = $ARGV[0] || die "Usage: $0 <startdir>\n";
      That checks the first command line argument but does not remove it from the argument list.

      --
      I'd like to be able to assign to an luser

        thanks for the info. So this doesnt have a bug?
        my $StartDir = shift || die "Usage: $0 <startdir>\n";
      You could just evaluate the @ARGV array in scalar context and compare the result to the number of parameters you are expecting:

      @ARGV == $numExpected or die "Usage: ...\n";

      Note the use of lower priority "or" and not "||"