Hello Monks,

May be I am not phrasing this question properly. In a nutshell, I expect one argument to be pased to the script. However, I am doing the checking for it in a sub, which eventually receives this argument.

So, I blatently pass $ARGV[0] to the sub regardless of whether any arguement was passed to the script or not. I do the checking of # of arguments in the sub (May be not the right place to do so). I actually exected @_ to contain no entries. Yet, it contains 1. But the retrieved value using shift is undefined.

#! /usr/bin/perl use strict; use warnings; sub p1 { my $n1; $n1=@_; print "1. Parameters to the sub p1 $n1\n"; my $p1=shift; print "2. p1=$p1\n"; } p1 $ARGV[0];
So, here is my academic curiosity question:

Arguments is Perl are passed by reference. Argument $ARGV[0] never existed in memory (If I did not pass anything argument to the script), so there is no address for it. So shouldn't @_ say 0? How else would you (recommend) check for passed arguments to be present if this does not work?

Thanks.

Ash


In reply to Question: Is undef a valid argument? by jujiro_eb

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.