Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How to use getopts?

by ssandv (Hermit)
on Mar 09, 2010 at 19:03 UTC ( [id://827608]=note: print w/replies, xml ) Need Help??


in reply to How to use getopts?

A couple quick housekeeping things first: There are instructions on formatting your posts immediately below the posting box, and it helps us a lot to help you if you follow them. In particular, <code></code> tags around your code fragment make it easier to read, prevent brackets from being treated as markup, and give us a "download" button which pops the code up in a new page without any inconvenient line wrapping. Also, you'll want to get in the habit of useing strict as well as warnings (you're already using warnings, since you have the -w option in your shebang line, so that's good!).

You ask if you are on the right track, but it's far more effective if you tell us what you've seen happen so far. Have you run the code? If not, why not? If so, what did you see? One thing that seems odd to me is that you allow the user to enter the file on the command line, but then still prompt them for a filename even if they give one on the command line. Another problem is that you're using the wrong version of or to do your open ... or die (you want or which has the lowest precedence, not ||, which has a higher one). I also don't see where you ever construct the tcl command itself, so it's hard to know if you're "on the right track"

There are a number of other technical quibbles with your Perl style which you may or may not be interested in (it looks like you're using some style elements that were once standard or even necessary, but are now deprecated). Unless you're stuck using a very old version of Perl, you can use scalar variables for your filehandles instead of barewords (e.g. USERINPUT), and this has a lot of advantages. Also, the 3-argument form of open is better than the 2-argument form (among other things, it helps in the case where the filename includes strange characters). There's other stuff too, but that's a good start for now.

In short, don't post a really short problem statement with a bunch of code and ask how you're doing. Post code (in appropriate tags), post the results you got from running it, or a clear statement of where you're stuck, and describe in detail what you thought it should do or don't understand why it did.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found