I've been searching through Perl resources, and I could not see where I am going wrong. I am pretty sure I'm missing something obvious, because when I assign
my $gArgc = $#ARGV;
but call my program perl pkTkPtBdTkNo.pl test.txt
$#ARGV
is equal to 0, and I can't figure out why.
#! /usr/bin/perl -w
use strict;
my $gArgc = $#ARGV;
my $input_line;
my $bad_input;
print($gArgc);
die ("Usage pkTkPtBdTkNo.pl input-line")
if(0 == $gArgc);
$input_line = $ARGV[0];
$bad_input = ($input_line =~ /\"\d+\D+\d*\",/);
print($bad_input);
The Short Answer: Sunlight reaches Earth's atmosphere and is scattered in all directions by all the gases and particles in the air. Blue light is scattered more than the other colors because it travels as shorter, smaller waves. This is why we see a blue sky most of the time.
The sunlight reaching our eyes has a high ratio of short, bluish wavelengths compared to medium and long wavelengths, so we perceive the sky as being blue. Without an atmosphere the sky appears black, as evidenced by the lunar sky in pictures taken from the moon. But even a black sky has some lightness.
The sky during the day During the day the sky looks blue because it's the blue light that gets scattered the most. It's redirected into many different directions all over the sky, whereas the other wavelengths aren't scattered as much.
Since there is virtually nothing in space to scatter or re-radiate the light to our eye, we see no part of the light and the sky appears to be black.
From man perlintro
:
The special variable $#array tells you the index of the last element of an array: ... You might be tempted to use $#array + 1 to tell you how many items there are in an array. Don't bother. As it happens, using @array where Perl expects to find a scalar value ("in scalar context") will give you the number of elements in the array:
So, if you pass 0 arguments, $#ARGV will be -1, since there are no elements in the array. If you pass 1 argument (as in your example), $#ARGV will be 0.
This should be always true, $#ARGV+1 == @ARGV
as $#ARGV
is last index of @ARGV
array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With