Arnaldo Guzman wrote:
Brian Volk wrote:
Hello~
I'm trying to assign STDIN to a hash ref... I think? :-) I have a
working program (w/o references) but I think it will easily get out of
control if I don't learn to use references. Here is what I would like to
do: User selects vendor and then selects the type of image (regular or
thumbnail). I'm not sure how to access a hash ref when the user selects
option 1 and so on.
I think option 1 hash ref should look like this:
My %baywest_info = (
ftp_reg_dir => "bayw",
ftp_thumb_dir => "bayw/th",
local_reg_dir => 'c:/brian/jmt/baywest',
local_thumb_dir => 'c:/brian/jmt/baywest/thumbs',
)
My %baywest_ref =\%baywest_info;
Thank You!
Brian
When you want to create a reference to a hash, you want to assign it
to a scalar variable:
my $hashref = \%hash;
Using your example above:
my %baywest_info = (
ftp_reg_dir => "bayw",
ftp_thumb_dir => "bayw/th",
local_reg_dir => 'c:/brian/jmt/baywest',
local_thumb_dir => 'c:/brian/jmt/baywest/thumbs',
);
my $hashref = %baywest_info;
To access the value of the "local_reg_dir" you'd do this:
print $hashref->{"local_reg_dir"};
Of course if you're reading Intermediate Perl, you should have known
this by now. :)
- Hope that helps
Excuse my mistake above:
my $hashref = %baywest_info;
Should be:
my $hashref = \%baywest_info;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>