Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

query about perl

by yogesh536 (Initiate)
on Jun 18, 2010 at 13:25 UTC ( #845373=perlquestion: print w/ replies, xml ) Need Help??
yogesh536 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying the following code : print $ARG[0]; and in command perl test.pl hello but I am not getting hello printed on command. Please advise.

Comment on query about perl
Re: query about perl
by linuxer (Deacon) on Jun 18, 2010 at 13:27 UTC

    Try print $ARGV[0].

    Addendum:

    Extracted from perlvar

    @ARGV The array @ARGV contains the command-line arguments intended for the s +cript. $#ARGV is generally the number of arguments minus one, because + $ARGV[0] is the first argument, not the program's command name itsel +f. See $0 for the command name.
Re: query about perl
by Anonymous Monk on Jun 18, 2010 at 14:17 UTC
    Use strict warnings and diagnostics or die
    $ perl -e " use strict; use warnings; print $ARG[0]; " hello Global symbol "@ARG" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors. $ perl -e " use strict; use warnings; use diagnostics; print $ARG[0]; +" hello Global symbol "@ARG" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors (#1) (F) You've said "use strict" or "use strict vars", which indicates that all variables must either be lexically scoped (using "my" or +"state"), declared beforehand using "our", or explicitly qualified to say which package the global variable is in (using "::"). Uncaught exception from user code: Global symbol "@ARG" requires explicit package name at -e line + 1. Execution of -e aborted due to compilation errors. at -e line 1 $
Re: query about perl
by eighty-one (Friar) on Jun 18, 2010 at 17:53 UTC

    So you have a file called test.pl, and somewhere in there is print $ARGV[0]

    On the command line, you type perl test.pl hello but you don't get 'hello' written to the command line as you expected.

    Some more information would be useful. What does test.pl contain - just the text you indicated, or is that just one line of a file with multiple lines? What OS are you using? You state you don't get hello printed - is anything printed? An error message or notification of some kind? Or do you simply get no output whatsoever?

    You might have more luck if you answer some of those questions. Also, take a look at How do I post a question effectively? and the Posting on PerlMonks section of the FAQ (the rest of the FAQ is good, too!); you should be able to get some advice on what you need to include so that you'll be providing enough information so as to make the problem you're having solvable by those who read your node.

      I'd just take him at his word that he used  $ARG[0] , the  use English version of  $_[0] instead of  $ARGV[0] .

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://845373]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2014-11-24 20:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (147 votes), past polls