Hello, I'm relatively new to perl but not programming, and I'm learning this wonderful language now :) but I'm trying to do something, and I'm a little stuck. I have the O'Reilly's stuff but maybe I'm just not searching it right.

Anyways, here's the question.

In C/C++ there's the ARGC and ARGV variables, which I understand that @ARGV is like ARGV in C. However, ARGV[0] is the first argument given in Perl, whereas it's the executable name in C. Is there a way to get the name of the perl script I'm running, so I can generate some sort of message instructing the user on usage? For example...
#!/usr/local/bin/perl use strict; if (@ARGV != 2) { print "Usage: (program name) arg1 arg2\n"; exit; }
I tried ARGV[0] by instinct from C and, of course, got the first argument I called the function with - blew my mind till I did for (@ARGV) {print "$_\n}; and saw that it didn't have the script name.

Any help? Thanks.

Brian, relatively new perlmonk

In reply to Anything comparable to argv0 from C in Perl? by brianarn

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, details, 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, summary, 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.