Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Invalid argument

by blokhead (Monsignor)
on Dec 01, 2006 at 20:27 UTC ( [id://587294]=note: print w/replies, xml ) Need Help??


in reply to Invalid argument

It looks like you're using a global to pass arguments into handlefix. But the global you decided to use is @_, and Perl's subroutine calling mechanism also uses @_ to pass arguments, so those "global" values are not seen inside the sub. Why not use a normal method of passing arguments to a sub?
my $infile = !@ARGV?<>:shift @ARGV; my $outfile = !@ARGV?<>:shift @ARGV; handlefix($infile, $outfile);
You don't even have to change handlefix.

Might I also suggest to rewrite conditionals to avoid having a negative condition? For example, $infile = @ARGV ? shift @ARGV : <>

blokhead

Replies are listed 'Best First'.
Re^2: Invalid argument
by Andrew_Levenson (Hermit) on Dec 01, 2006 at 20:34 UTC
    Whoops, I didn't re-think the logic of it.
    I have the negative condition in there because I originally started with two commands, and spent maybe half an hour frustrated because I could not figure out why, even with cmd arguments, it asked me for input.

    I eventually figured out that because I was shifting @ARGV, there was nothing left afterwards. ;)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-18 18:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found