This is not the hardest thing in the world to write, but I just couldn't get over how clean and English-like it was. So here it is.
#!/usr/local/bin/perl use strict; sub usage { die "USAGE: $0 \$raw_file \$cooked_dir"; } scalar @ARGV == 2 and my ($raw_file,$cooked_dir) = @ARGV or usage; warn "$raw_file, $cooked_dir";
  • Comment on Ensuring the correct number of arguments, assigning them or printing usage
  • Download Code

Replies are listed 'Best First'.
Re: Ensuring the correct number of arguments, assigning them or printnig usage
by japhy (Canon) on Nov 27, 2000 at 20:04 UTC
    I feel golfy. Not overly so, but a bit.
    (my ($x,$y,$z) = @ARGV) == 3 or usage(); # and trim it just a bit more... (my($x,$y,$z)=@ARGV)-3&&usage();


    japhy -- Perl and Regex Hacker
(Ovid - OT) Re: Ensuring the correct number of arguments, assigning them or printnig usage
by Ovid (Cardinal) on Nov 27, 2000 at 20:07 UTC
    Despite the recent brouhaha, I'd just like to say that I, for one, am glad you haven't left :)

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Ensuring the correct number of arguments, assigning them or printnig usage
by extremely (Priest) on Nov 28, 2000 at 03:40 UTC
    posted this on the wrong one at first. oops

    If I were you, I wouldn't confuse my lusers with the dollar signs in front of the fields in usage. They don't need to see perl to use your program. My mom (mom test is one of the more powerful tools I have) would be typing a dollar sign in front of the arguments.

    Also, you don't need the scalar() in there, perl knows the left side of a == is scalar. Also, die puts extra junk on the print that might confuse people, try this:

    sub usage { die "USAGE: $0 filename directory\nHalting execution"; } ## that produces: # USAGE: prog.pl filename directory # Halting execution at prog.pl line 4

    ...which I always felt was a little friendlier.

    --
    $you = new YOU;
    honk() if $you->love(perl)