Iam a perl newbie and you need help understanding the code below.
I have perl hash defined as
1 my %myFavourite = ("Apple"=>"Apple"); 2 my @fruits = ("Apple", "Orange", "Grape"); 3 @myFavourite{@fruits}; # This returns Apple. But how?
It would be great if the perl gurus could explain what is happening in Line-3 of the above code. MyFavourite declaration is declared hash, but is used as an array? And the operator simply takes the hash key, inserts it into the array and returns the hash values corresponding to the found key. Is it so that we insert hash keys into an array?
Apple. -, , @fruits. , , 2 . , myFavourite Orange Grape. "-" perldata.
@fruits
myFavourite
Orange
Grape
, @myFavourite{@fruits} ($myFavourite{Apple}, $myFavourite{Orange}, $myFavourite{Grape}), ($myFavourite{Apple},undef,undef). , , , Apple.
@myFavourite{@fruits}
($myFavourite{Apple}, $myFavourite{Orange}, $myFavourite{Grape})
($myFavourite{Apple},undef,undef)
Apple
myFavourite has hash, ?
, . -. .: http://perldoc.perl.org/perldata.html
@fruits -. @hash {@keys} - .
:
($myFavourite{'Apple'},$myFavourite{'Orange'},$myFavourite{'Grape'})
, (, )
my @slice_values = @myFavourite{@fruits} # @slice_values now contains ('Apple',undef,undef) # which is functionally equivalent to: my @slice_values = map { $myFavourite{$_} } @fruits;
- , :
my @favourite_fruits = @myFavourite{ grep { exists $myFavourite{$_} } @fruits }; # @favourite_fruits now contains ('Apple')
use warnings;
, undef.
Source: https://habr.com/ru/post/1724913/More articles:Change the column values in R - rCassandra on Amazon EC2 with resilient IPs - cassandraДолжен ли я помещать выходные файлы в исходный элемент управления? - version-controlDownload a file without html using HtmlUnit - javaТолько увеличить номер сборки для официального выпуска? - build-processANTLR3 Syntax Reference? - antlr3Преобразование проекта Makefile (make) без GUI в KDevelop - cPHPExcel style problem - phpIs there a list of reserved words in ANTLR grammars? - antlrC ++ Duplicate Symbol error when defining a static class variable in Xcode - c ++All Articles