Showing posts with label Perl. Show all posts
Showing posts with label Perl. Show all posts

Friday, March 16, 2012

The weired Indexing in Perl

I am learning Perl. I am doing it with a lot of a resentment, but I am slowly learning it.
Normal people count from 1. Computer Scientist count from 0. Perl developers count from -1?

WTF?

oz@server ~ $ test.pl test
num of args 0 
oz@server ~ $ test.pl test test
num of args 1 
0
test
1
test
oz@server ~ $ test.pl          
num of args -1 
No arguments!
oz@server ~ $ 
My Code, just in case I am totally wrong about this here, :
$ cat test.pl 
#!/usr/local/bin/perl -w


print "num of args $#ARGV \n";
if ( $#ARGV > 0   ){

   for ( my $i = 0 ; $i <= $#ARGV  ; ++$i  ) {

   print "$i\n";
   print "$ARGV[$i]\n";
   }
}
if ( @ARGV > 0 )
{
  print "Number of arguments: " . scalar @ARGV . "\n";
}
else
{
print "No arguments!\n";
}