On 04/24/2014 11:40 PM, Harry Putnam wrote:
Some simple code that is similar to other code I've written and used
is returning something I don't understand.
I've used the notation below for shifting off elements of AR many times
but don't recall seeing this output. I think I know what is happening
but I don't understand why.
Is the second 'shift' line, when the value of $dir2sr is printed it just
shows '1'. I guess it is showing the boolean value of that variable
instead of its content.... But why is that?
Is it related to that being the last element?
------- ------- ---=--- ------- -------
use strict;
use warnings;
@ARGV==2 or die "ARGV not equal 2 <ARGV !~ 2>: $!";
why did you put $! in there? there was no system call or possible error
so $! is just random and useless.
my $re= qr/@{[shift]}/;
the @{[]} technique works but it is considered poor coding style.
if (! -d $ARGV[0]) {
print "Sorry... <$ARGV[0]> not found .. aborting ..\n";
why not say the directory wasn't found?
exit 1;
}
print "hpdb @ARGV\n";
my $dir2sr = @{[shift]};
why would you expect anything but 1 as the value? shift will return 1
value or undef. that anon array will be dereferenced to an array with 1
entry. the array is in scalar context which returns its size. elementary!
uri
--
Uri Guttman - The Perl Hunter
The Best Perl Jobs, The Best Perl Hackers
http://PerlHunter.com
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/