ARGV Error

Hi, I am Indra. I am new in perl.

I start to run my script :
************************************************************ *************************************
#!/usr/bin/perl -w

$UNFOLD = 1; #1=UNFOLD^[$B%G!<%?$r;HMQ^[(B 0=^[$B [at] 8^[(Bvolume^[$B%G!<%?$r;HMQ^[(B
$XDR_NUM = 1; #1=^[$BJRJ}$N$_^[(BCAPPI^[$B$r:n [at] .^[(B 0=^[$BN>J}$N^[(BCAPPI^[$B$r:n [at] .^[(B

# work directory #
$workdir = "..";
$datadir = "../volume";
$year = "2011";

if( [at] ARGV != 1){
print "ARGV error \n";
print "firstradar velx vely \n";
exit(1);
}
.......

************************************************************ *************************************
I got this error message :
ARGV error
firstradar velx vely


please help me, how to overcame this.

regards,
Indra

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
indrag [ Mi, 16 März 2011 16:51 ] [ ID #2056664 ]

Re: ARGV Error

--002215975af2a8b7e4049e9bca0f
Content-Type: text/plain; charset=ISO-8859-1

On Mar 16, 2011 11:53 AM, <indrag [at] students.itb.ac.id> wrote:
>
>
> if( [at] ARGV != 1){
>

I don't think you can look at an array like its a string like that.
Maybe string( [at] ARGV ) != 1 might work. But what you probably want is:
If( defined( $ARGV[ 0 ] ) )

--002215975af2a8b7e4049e9bca0f--
Shawn Wilson [ Mi, 16 März 2011 17:11 ] [ ID #2056666 ]

Re: ARGV Error

--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi Indra,

On 2011-03-16 22:51 +0700, indrag [at] students.itb.ac.id wrote:
> if( [at] ARGV !=3D 1){
> print "ARGV error \n";
> print "firstradar velx vely \n";
> exit(1);
> }

=2E..

> I got this error message :
> ARGV error
> firstradar velx vely

This is your output if the number of arguments isn't what you
expected. Guessing from

print "firstradar velx vely \n";

you probably want to change

if( [at] ARGV !=3D 1){

to

if( [at] ARGV !=3D 2){

as [at] ARGV is a list and lists in scalar context is how many elements it
contains. Makes sense?

--
- Olof Johansson
- www: http://www.stdlib.se/
- {mail,xmpp}: olof [at] ethup.se
- irc: zibri on Freenode/OFTC/IRCnet/...
--

--jRHKVT23PllUwdXP
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk2A4awACgkQCPS7eH/A+7qr3gCgmjZtr94ijWKQr3tu7MHM Q31d
beIAnj9j67kcH0GFTJ64y2e6LwWhDl6n
=FdW4
-----END PGP SIGNATURE-----

--jRHKVT23PllUwdXP--
Olof Johansson [ Mi, 16 März 2011 17:13 ] [ ID #2056667 ]

Re: ARGV Error

On 3/16/11 Wed Mar 16, 2011 8:51 AM, "indrag [at] students.itb.ac.id"
<indrag [at] students.itb.ac.id> scribbled:

>
> Hi, I am Indra. I am new in perl.
>
> I start to run my script :
> ************************************************************ ******************
> *******************
> #!/usr/bin/perl -w
>
> $UNFOLD = 1; #1=UNFOLD^[$B%G!<%?$r;HMQ^[(B
> 0=^[$B [at] 8^[(Bvolume^[$B%G!<%?$r;HMQ^[(B
> $XDR_NUM = 1; #1=^[$BJRJ}$N$_^[(BCAPPI^[$B$r:n [at] .^[(B
> 0=^[$BN>J}$N^[(BCAPPI^[$B$r:n [at] .^[(B
>
> # work directory #
> $workdir = "..";
> $datadir = "../volume";
> $year = "2011";
>
> if( [at] ARGV != 1){
> print "ARGV error \n";
> print "firstradar velx vely \n";
> exit(1);
> }
> ......
>
> ************************************************************ ******************
> *******************
> I got this error message :
> ARGV error
> firstradar velx vely
>
>
> please help me, how to overcame this.

Your script requires that one argument be entered on the command line, like
this:

yourscript.pl arg1

Arguments entered this way are put into the [at] ARGV array. The logical
expression ( [at] ARGV != 1) compares the number of elements in the [at] ARGV array
to 1 and returns true if they are not equal. An array in scalar context like
the above use returns the number of elements in the array.

Therefore, you should enter one argument on the command line when you
execute the script.



--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Jim Gibson [ Mi, 16 März 2011 17:13 ] [ ID #2056668 ]

Re: ARGV Error

On 11-03-16 12:11 PM, shawn wilson wrote:
> On Mar 16, 2011 11:53 AM,<indrag [at] students.itb.ac.id> wrote:
>>
>>
>> if( [at] ARGV != 1){
>>
>
> I don't think you can look at an array like its a string like that.
> Maybe string( [at] ARGV ) != 1 might work. But what you probably want is:
> If( defined( $ARGV[ 0 ] ) )
>

No, that is correct. In scalar context, [at] array is the number of items
in the array. The problem is that the OP is running the script without
any arguments.

On 11-03-16 11:51 AM, indrag [at] students.itb.ac.id wrote:
> if( [at] ARGV != 1){
> print "ARGV error \n";
> print "firstradar velx vely \n";
> exit(1);
> }

This code will print out an error and stop the script if there are no
arguments. Solution: run the script with arguments.


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shawn H Corey [ Mi, 16 März 2011 17:18 ] [ ID #2056669 ]

Re: ARGV Error

On 3/16/11 Wed Mar 16, 2011 9:11 AM, "shawn wilson" <ag4ve.us [at] gmail.com>
scribbled:

> On Mar 16, 2011 11:53 AM, <indrag [at] students.itb.ac.id> wrote:
>>
>>
>> if( [at] ARGV != 1){
>>
>
> I don't think you can look at an array like its a string like that.
> Maybe string( [at] ARGV ) != 1 might work. But what you probably want is:
> If( defined( $ARGV[ 0 ] ) )

Try it!

The logical operator != gives scalar context to both left and right
operands. An array in scalar context returns the number of elements in the
array. Therefore, the expression ( [at] ARGV != 1) will return true if the number
of elements in [at] ARGV is not exactly one.



--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Jim Gibson [ Mi, 16 März 2011 17:21 ] [ ID #2056670 ]

Re: ARGV Error

--4SFOXa2GPu3tIq4H
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2011-03-16 17:13 +0100, Olof Johansson wrote:
> This is your output if the number of arguments isn't what you
> expected. Guessing from
>
> print "firstradar velx vely \n";
>
> you probably want to change
>
> if( [at] ARGV !=3D 1){
>
> to
>
> if( [at] ARGV !=3D 2){
>
> as [at] ARGV is a list and lists in scalar context is how many elements it
> contains. Makes sense?

My brain fooled me into thinking it was a =3D=3D instead of !=3D. What you =
know
check is if [at] ARGV is not 1. I don't know why you would do this.

--
- Olof Johansson
- www: http://www.stdlib.se/
- {mail,xmpp}: olof [at] ethup.se
- irc: zibri on Freenode/OFTC/IRCnet/...
--

--4SFOXa2GPu3tIq4H
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk2A5DwACgkQCPS7eH/A+7oquQCggfFCK2OKmnQ2rmGgImcL FGv0
dJAAn35NW/rrH4VMYLvHz/rxnVUSbQIb
=nl/r
-----END PGP SIGNATURE-----

--4SFOXa2GPu3tIq4H--
Olof Johansson [ Mi, 16 März 2011 17:24 ] [ ID #2056672 ]

Re: ARGV Error

Hi Indra,

a few comments on your code.

On Wednesday 16 Mar 2011 17:51:19 indrag [at] students.itb.ac.id wrote:
> Hi, I am Indra. I am new in perl.
>
> I start to run my script :
> ************************************************************ ***************
> **********************
>
> #!/usr/bin/perl -w
>

1. Don't use "-w".

2. Add "use strict;"

3. Add "use warnings;"

See:

http://perl-begin.org/tutorials/bad-elements/#no-strict-and- warnings

> $UNFOLD = 1; #1=UNFOLD^[$B%G!<%?$r;HMQ^[(B

1. Add my to them.

2. What are all the junk characters after the line? I cannot understand what
they mean.

> 0=^[$B [at] 8^[(Bvolume^[$B%G!<%?$r;HMQ^[(B $XDR_NUM = 1;
> #1=^[$BJRJ}$N$_^[(BCAPPI^[$B$r:n [at] .^[(B 0=^[$BN>J}$N^[(BCAPPI^[$B$r:n [at] .^[(B
>
> # work directory #
> $workdir = "..";
> $datadir = "../volume";
> $year = "2011";

1. Add my.

2. Maybe use http://perldoc.perl.org/File/Spec.html

>
> if( [at] ARGV != 1){

1. There should be a space before the "{".

> print "ARGV error \n";
> print "firstradar velx vely \n";

You should output errors STDERR - not STDOUT. Maybe use perldoc -f die
instead.

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

When Chuck Norris uses Gentoo, "emerge kde" finishes in under a minute. A
computer cannot afford to keep Chuck waiting for too long.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shlomi Fish [ Mi, 16 März 2011 17:33 ] [ ID #2056673 ]

Re: ARGV Error

Olof Johansson wrote:
>
> On 2011-03-16 22:51 +0700, indrag [at] students.itb.ac.id wrote:
>> if( [at] ARGV != 1){
>> print "ARGV error \n";
>> print "firstradar velx vely \n";
>> exit(1);
>> }
>
> ...
>
>> I got this error message :
>> ARGV error
>> firstradar velx vely
>
> This is your output if the number of arguments isn't what you
> expected. Guessing from
>
> print "firstradar velx vely \n";
>
> you probably want to change
>
> if( [at] ARGV != 1){
>
> to
>
> if( [at] ARGV != 2){
>
> as [at] ARGV is a list and lists in scalar context is how many elements it
> contains.

perldoc -q "What is the difference between a list and an array?"


[at] ARGV is an ARRAY and ARRAYs in scalar context ...



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
jwkrahn [ Mi, 16 März 2011 17:36 ] [ ID #2056674 ]

Re: ARGV Error

Shlomi Fish wrote:
>
> On Wednesday 16 Mar 2011 17:51:19 indrag [at] students.itb.ac.id wrote:
>>
>> if( [at] ARGV != 1){
>
> 1. There should be a space before the "{".

There could be, but there doesn't have to be.


>> print "ARGV error \n";
>> print "firstradar velx vely \n";
>
> You should output errors STDERR - not STDOUT. Maybe use perldoc -f die
> instead.

Or perldoc -f warn



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
jwkrahn [ Mi, 16 März 2011 17:43 ] [ ID #2056675 ]
Perl » gmane.comp.lang.perl.beginners » ARGV Error

Vorheriges Thema: Read and change the file
Nächstes Thema: how to handle "up movement key" in perl