Re: ARGV Error

2011-03-16 Thread shawn wilson
On Mar 16, 2011 11:53 AM,  wrote:
>
>
> if(@ARGV != 1){
>

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


Re: ARGV Error

2011-03-16 Thread Olof Johansson
Hi Indra,

On 2011-03-16 22:51 +0700, ind...@students.itb.ac.id wrote:
> if(@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(@ARGV != 1){

to 

 if(@ARGV != 2){

as @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}:  o...@ethup.se
-  irc:  zibri on Freenode/OFTC/IRCnet/...
--


signature.asc
Description: Digital signature


Re: ARGV Error

2011-03-16 Thread Jim Gibson
On 3/16/11 Wed  Mar 16, 2011  8:51 AM, "ind...@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@8^[(Bvolume^[$B%G!<%?$r;HMQ^[(B
> $XDR_NUM = 1; #1=^[$BJRJ}$N$_^[(BCAPPI^[$B$r:n@.^[(B
> 0=^[$BN>J}$N^[(BCAPPI^[$B$r:n@.^[(B
> 
> # work directory #
> $workdir = "..";
> $datadir = "../volume";
> $year= "2011";
> 
> if(@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 @ARGV array. The logical
expression (@ARGV != 1) compares the number of elements in the @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-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: ARGV Error

2011-03-16 Thread Shawn H Corey

On 11-03-16 12:11 PM, shawn wilson wrote:

On Mar 16, 2011 11:53 AM,  wrote:



if(@ARGV != 1){



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



No, that is correct.  In scalar context, @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, ind...@students.itb.ac.id wrote:
> if(@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.0002 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-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: ARGV Error

2011-03-16 Thread Jim Gibson
On 3/16/11 Wed  Mar 16, 2011  9:11 AM, "shawn wilson" 
scribbled:

> On Mar 16, 2011 11:53 AM,  wrote:
>> 
>> 
>> if(@ARGV != 1){
>> 
> 
> I don't think you can look at an array like its a string like that.
> Maybe string( @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 (@ARGV != 1) will return true if the number
of elements in @ARGV is not exactly one.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: ARGV Error

2011-03-16 Thread Olof Johansson
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(@ARGV != 1){
> 
> to 
> 
>  if(@ARGV != 2){
> 
> as @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 == instead of !=. What you know 
check is if @ARGV is not 1. I don't know why you would do this.

-- 
- Olof Johansson
-  www:  http://www.stdlib.se/
-  {mail,xmpp}:  o...@ethup.se
-  irc:  zibri on Freenode/OFTC/IRCnet/...
--


signature.asc
Description: Digital signature


Re: ARGV Error

2011-03-16 Thread Shlomi Fish
Hi Indra,

a few comments on your code.

On Wednesday 16 Mar 2011 17:51:19 ind...@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@8^[(Bvolume^[$B%G!<%?$r;HMQ^[(B $XDR_NUM = 1;
> #1=^[$BJRJ}$N$_^[(BCAPPI^[$B$r:n@.^[(B 0=^[$BN>J}$N^[(BCAPPI^[$B$r:n@.^[(B
> 
> # work directory #
> $workdir = "..";
> $datadir = "../volume";
> $year= "2011";

1. Add my.

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

> 
> if(@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-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: ARGV Error

2011-03-16 Thread John W. Krahn

Olof Johansson wrote:


On 2011-03-16 22:51 +0700, ind...@students.itb.ac.id wrote:

if(@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(@ARGV != 1){

to

  if(@ARGV != 2){

as @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?"


@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-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: ARGV Error

2011-03-16 Thread John W. Krahn

Shlomi Fish wrote:


On Wednesday 16 Mar 2011 17:51:19 ind...@students.itb.ac.id wrote:


if(@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-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/