J
Jorge
Having read the faq's and several articles on this forum, I have a
pretty good feel for why one needs to be careful when quoting
variables and in particular about overusing the quotes and I have
adjusted my coding style accordingly.
For the most part, it all makes sense, particularily some of the
points involving not quoting references and variables when it's not
clear whether the variable is a string or otherwise typed and so on.
That said however -- below I show 4 cases of printing ARRAY, each
being a different scenario of quotes (or lack of).
Of particular question is Case 3 which is ARRAY with strings
concantenated, one appended and one prepended to the ARRAY in which
case it prints the number of elements in ARRAY (scalar(@fields)) where
I had expected it to print the same as Case 2 or Case 4 where ARRAY is
enclosed in quotes.
I'm thinking there is there a level of coercion going on that doesn't
show itself.
Shedding light on this will be greatly appreciated.
Thanks, Jorge
use strict;
my @fields = ("zero", "one", "two", "three", "four");
print "\n\n";
# Case 1
print "This is bare ARRAY ...\n";
print @fields;
print "\n\n";
# Case 2
print "This is quoted ARRAY ...\n";
print "@fields";
print "\n\n";
# Case 3
print "this is ARRAY with concatenated strings ...\n".@fields."\n\n";
# Case 4
print "this is ARRAY enclosed in string ... @fields ... \n\n";
pretty good feel for why one needs to be careful when quoting
variables and in particular about overusing the quotes and I have
adjusted my coding style accordingly.
For the most part, it all makes sense, particularily some of the
points involving not quoting references and variables when it's not
clear whether the variable is a string or otherwise typed and so on.
That said however -- below I show 4 cases of printing ARRAY, each
being a different scenario of quotes (or lack of).
Of particular question is Case 3 which is ARRAY with strings
concantenated, one appended and one prepended to the ARRAY in which
case it prints the number of elements in ARRAY (scalar(@fields)) where
I had expected it to print the same as Case 2 or Case 4 where ARRAY is
enclosed in quotes.
I'm thinking there is there a level of coercion going on that doesn't
show itself.
Shedding light on this will be greatly appreciated.
Thanks, Jorge
use strict;
my @fields = ("zero", "one", "two", "three", "four");
print "\n\n";
# Case 1
print "This is bare ARRAY ...\n";
print @fields;
print "\n\n";
# Case 2
print "This is quoted ARRAY ...\n";
print "@fields";
print "\n\n";
# Case 3
print "this is ARRAY with concatenated strings ...\n".@fields."\n\n";
# Case 4
print "this is ARRAY enclosed in string ... @fields ... \n\n";