According to Beginning Perl book published by Tsinghua Pub., the list context appears when you were trying to Assi GN Some value to a list variable.
1 my @copy @source;
This was a very simple instance of shallow copy, which usually means you just copied the reference of the source array, non E new elements is created and no other memories'll be occupied.
When we assign an array with a hash table, the Key-value elements'll be converted to a plain list, which is called Plana Rization.
For example, the following Perl codes would print the result below:
1 my %hashtable = (2 tom=>,3 jerry=>,4 sam=> 5); 6 my @flattened %hashtable ; 7 Print @flattened;
Tom12jerry13sam17
*another thing I want to stress are, if we want to seperate these flattened elements by a blank space charactor, we NE Ed to modify the print statement to this: (Attention to the quatation marks)
1 Print " @flattened ";
Thus, the result in console would become:
Tom, Jerry, Sam 17.
The book has noted one important feature-the advantage of list context:
You can force to obtain it with a pair of brackets.
if we want to assign the first element to a scalar variable, we can simply surround it with Brackets, like this:
1 my @array = ('element0','element1'); 2 my ($scalar@array; 3 Print $scalar;
The result is displayed:
Element0
But there are more than that! We can add more scalars to the brackets (as long as the array has enough elements), and the scalars would be assigned by the Elements one by one. Code it as follow:
1 my @array= ('element0','element1');2 my($scalar 0,$scalar 1);3 Print "$scalar 0\t$scalar1";
The result is:
Element0 element1
Have you found the advantage of list context? If you haven ' t, see the Followint statement:
($leftScalar$rightScalar) = ($rightScalar$leftScalar);
Isn ' t it beautiful? Usually, especially in some other languages, we had to use a third variable to store one of the one of the both elements and that CER Tainly takes more than this in Perl.
Ok! It ' s What we get this afternoon!
Several Ideas on Perl List Context