CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
String variable passed to subroutine is a hash ref

 



anotherperlnoob
Novice

May 24, 2015, 1:36 PM

Post #1 of 2 (1309 views)
String variable passed to subroutine is a hash ref Can't Post

Hi,
In the following code, a variable is passed to sub unzip_files().
Just before passing, it's a string.
Inside the subroutine, it's a hash ref.
I don't understand how this is possible. I want it to be passed as a string. What am I doing wrong? Could somebody explain please?
Thank you very much.


Code
#!/usr/bin/perl  

use strict;
use warnings;
use diagnostics;
use Data::Dumper;

my @config = (
{
provider => "xxx",
zip => "no"
},
{
provider => "yyy",
zip => "yes"
});

sub unzip_files{
my $provider = $_;
print Dumper(\%$_);
print "inside unzip_files, provider = \"$provider\" \n";
}

foreach (@config) {
my $provider = $_->{'provider'};
my $zip = $_->{'zip'};

if($_->{'zip'} eq 'yes') {
print "$_->{'provider'} supports zip file downloads\n";
print "before calling unzip_files, provider = \"$provider\" \n";
unzip_files($provider);
} else {
print "$_->{'provider'} does not support zip file downloads\n";
}
}

Output:


Code
xxx does not support zip file downloads 
yyy supports zip file downloads
before calling unzip_files, provider = "yyy"
$VAR1 = {
'provider' => 'yyy',
'zip' => 'yes'
};
inside unzip_files, provider = "HASH(0x8006c028)"



anotherperlnoob
Novice

May 24, 2015, 3:19 PM

Post #2 of 2 (1307 views)
Re: [anotherperlnoob] String variable passed to subroutine is a hash ref [In reply to] Can't Post

It's OK I figured it out already.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives