Sorry about all these silly questions, I've been thrust into Perl programming and I'm finding it really hard to think like a Perl programmer.
Silly question for today:
I load a pipe delimited file into a hash using the id field as the key, like so
#open file
my %hash;
while (<MY_FILE>) {
chomp;
my ($id, $path, $date) = split ...
In Perl, is it possible to create a global variable based on a string?
E.g., if I had a function like:
sub create_glob_var {
my ($glob_var_str) = @_;
# something like this ( but not a hash access).
our ${$glob_var_str};
};
and I called it like:
create_glob_var( "bar" );
How could I modify create_glob_var to actually cr...
Why does the following snippet work at all? And what evil might be possible using this? But seriously, is there any reason, the code in ${} gets evaluated at all and then used as scalar reference?
use strict;
no strict 'refs';
our $message = "Hello world!";
print "${ lc 'MESSAGE' }\n";
...
I know I could easily do something like
sub sin {
sin($_[0]);
}
and symbolically reference that for every function I need to symb ref, but I'd just like to know if there's a way to do something like
{$foo}(123);
vs.
&{$foo}(123);
which works, but not for core functions.
Thanks.
...