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

Re: Faking Script Names

by shemp (Deacon)
on Jul 22, 2005 at 22:29 UTC ( [id://477370]=note: print w/replies, xml ) Need Help??


in reply to Faking Script Names

Your problem hinges on the idea that $0 in perl is like $ARGV[0] in C. The perl variable $0 is actually the name of the program that is running. The command line args are stored in @ARGV. So you really want $ARGV[0] (like in c). Try running this code:
use strict; use warnings; { print "\$0 = $0\n"; print "\$ARGV[0] = $ARGV[0]\n"; }
Assume that the name of this script is arg_test.pl, run the command:

>perl -w arg_test.pl foo

which yields this output:

$0 = arg_test.pl $ARGV[0] = foo
The rest of your scripts behaviour should become clear.

Replies are listed 'Best First'.
Re^2: Faking Script Names
by ikegami (Patriarch) on Jul 23, 2005 at 00:13 UTC
    I'm not sure what point is. For starters, $ARGV[0] corresponds to argv[1], not argv[0].
      As yes, my mistake, havent coded any C for many years.
      I use the most powerful debugger available: print!

Log In?
Username:
Password:

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

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

    No recent polls found