in reply to assign an array into hash
qw(@con) is an error. Perl would have told you about it if you used strictures (use strict; use warnings;). Always use strictures. qw quotes 'words' where in this case a 'word' is any sequence of non-white space characters. @con is taken to be a word by qw so you are trying to assign a single element list to a hash - that doesn't do what you want.
Consider instead:
use strict; use warnings; my %con; while (<DATA>) { chomp($_); next unless /^(.*?)=>(.*)/; $con{$1} = $2; } print "Key: $_, Value: $con{$_}\n" for sort keys %con; __DATA__ article=>art chapter=>chap section=>sec
Prints:
Key: article, Value: art Key: chapter, Value: chap Key: section, Value: sec
|
|---|