[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Howto import modules ... (or, fun with arrays)



At 14.44 97/4/26, Bart Lateur wrote:
>> open(inFile, @ARGV[0]) or die "No file dropped!";
>...
>> $resFileName= @ARGV[0].".rsrc";
>
>Are you sure this works al right? It looks like you're using an array
>(@ARGV[0]) where you should use a scalar ($ARGV[0]).
>
>Doesn't your code try to open file "1" and "1.rsrc" instead?
>
>
>And, if it *does* work... why?

Yes, it should be $, not @.  But @ is acceptable, and using the -w switch
will only give a warning, not an error.

If you run the script below, you will get four warnings, but they all
"work."  :-)

NOTE: the "useless concatenation" is not usesless at all; actually, the
concatenation forces @ARGV into a scalar context, and prints "2" instead of
"hi hi2".

#======================================================
#!perl -w

$ARGV[0] = 'hi';
$ARGV[1] = 'hi2';

print "@ARGV[0]\n$ARGV[0]\n";
print "@ARGV[1]\n$ARGV[1]\n";
print "@ARGV\n";
print (@ARGV + 0) . "\n";
__END__
# Scalar value @ARGV[0] better written as $ARGV[0].
File 'Untitled'; Line 6
# Scalar value @ARGV[1] better written as $ARGV[1].
File 'Untitled'; Line 7
# print (...) interpreted as function.
File 'Untitled'; Line 9
# Useless use of concatenation in void context.
File 'Untitled'; Line 9
hi
hi
hi2
hi2
hi hi2
2

#================================================================
Chris Nandor                                      pudge@pobox.com
PGP Key 1024/B76E72AD                           http://pudge.net/
Keyfingerprint = 08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch