Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Testing <> for undefined

by TrekNoid (Pilgrim)
on Jul 07, 2004 at 16:46 UTC ( [id://372457]=note: print w/replies, xml ) Need Help??


in reply to Testing <> for undefined

Here's something that I use in most of my scripts:

Assuming the scriptname is called file_parse.pl, and you're trying to pass it single file only:

if ($#ARGV != 0) { print "Usage: file_parse.pl [filename] \n"; exit(1); }
Trek

Replies are listed 'Best First'.
•Re^2: Testing <> for undefined
by merlyn (Sage) on Jul 07, 2004 at 16:52 UTC
    This code scares me. If you want to see if there is one argument, use @ARGV in a scalar context, comparing it to one. I could easily imagine people reading this code and not remembering that $#ARGV is one less than the number of arguments, and being very confused.

    My rule is, use @ARGV when you want to talk about the number of elements, and reserve $#ARGV for getting the ending index for ranges.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      My rule is, use @ARGV when you want to talk about the number of elements, and reserve $#ARGV for getting the ending index for ranges.

      Thanks, merlyn... It's one of those things I learned to do one way when I was first learning Perl, and have never gone back and revisted it...

      There's just so few things I can help people with in Perl, that I get excited when I see one I *can* answer :) Guess I'm destined to remain an acolyte for the foreseeable future :)

      I'll make a note for future development

      Trek

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://372457]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found