in reply to Perl data types and references
Since @args = already forces list context, yes, they are equivalent. But note thatis it equivalent with : my @sargs = @_; ? (without bracket)my (@sargs) = @_;
is not equivalent tomy $var = @list;
my ($var) = @list;
Well, $config is a reference to a hash table; a normal hash is initialized with a list: ( key => value ...) while a reference to an anonymous hash is created with { key => value .. }Is it right that $config is a hash table ?my $config = {"delete" => 0, soFiles => []};
is these 2 lines are equivalent ?Yes, keys that only contain alphanumeric characters can be left unquoted before the => operator.my $config = {"delete" => 0, soFiles => }; my $config = {"delete" => 0, "soFiles" => };
You should use an even number of element in a hash, though. (there is NO value for the soFiles key in your example. that isn't possible in a hash)
After that, delete is initialized like this :$config->{ } is used to dereference the reference in $config. the reason that you can't use $config{delete} is because $config{delete} indicates an element in the hash %config, while $config->{delete} indicates an element in the hash pointed to by $config.why not to use :$config->{delete} = 1; # why -> is it a reference ?$config{delete} = 1
You seem to have a reasonable understanding of programming techniques, but a little less sure of Perl itself. You might find the camel book enlightening. Also, putting this at the top of your code will help you spot bugs:
#/usr/bin/perl use strict; use warnings; use diagnostics; # optional; turns on more descriptive warnings
And we don't usually mind questions, so ask away. :-)
|
|---|