Why does my Perl print show HASH (0x100a2d018)?

Here, I think I know how to use lists in Perl when this happens. If I do this (debug code, not included):

#! /usr/bin/perl -w
use strict;

my $temp1 = "FOOBAR";
my $temp2 = "BARFOO!";

my @list = { $temp1, $temp2 };

print $temp1; #this works fine
print $list[0]; #this prints out HASH(0x100a2d018)

Looks like I'm printing out the address of the second line. How to get the actual string stored in a list? I guess this has something to do with links, but I don't know.

+3
source share
2 answers

You have already received the answer to your question, do not use {}, because it creates an anonymous hash link.

However, the question still remains that you did not know what you asked.

What is the difference between array and list in Perl?

"", , . , .

- . . .

, , .

?

, my $foo = (1,2,3). $foo , (1,2,3) .

(1,2,3) , . .

, . , ((1 ,2),3), ((2),3) , , 3.

my @foo = (1,2,3) . , (1,2,3) . . , ((1,2),3), (list_of(1,2),3), list_of(list_of(1,2),3), Perl , list_of(1,2,3). @foo. , Perl list_of, , . Perl, .

, , Perl? :

  • .
  • , , .
  • , .
  • DWIM , - , .

, :

+8
my @list = { $temp1, $temp2 };

my @list = ( $temp1, $temp2 ); # Parentheses instead of curly braces.

{$temp1 => $temp2} @list ($list[0]). ( ), , .

+10

Source: https://habr.com/ru/post/1718620/


All Articles