in reply to can't use string as an array ref

Most likely this means you've inserted an array into a hash like this:

my $somearray = qw ( servername ); $server_list_hash{$server} = @somearray;

Which hasn't done what you thought, because it's done an assignment in a scalar context, which means it's assigned the number of elements in @somearray.

What you would actually need to do would be:

$server_list_hash{$server} = [@somearray];

Be careful with something like:

$server_list_hash{$server} = \@somearray;

Because this will break if you reuse @somearray (e.g. it's not lexically scoped) because you'll be using the same reference each time

Replies are listed 'Best First'.
Re^2: can't use string as an array ref
by fionbarr (Friar) on Mar 26, 2015 at 17:18 UTC
    $server_list_hash{$server}[ $server_count{$server}++ ] = "$role|$cto|$ +app_manager|$location";
    there are duplicate servers and I'm trying to put them in an array
      Are you sure that's the only write access happening to your hash? This sounds like a good time for peppering your script with print statements to see when the corruption happens. print "$server_list_hash{$server}\n";

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.