Strange things inside the Perl diamond operator

Please help me with this:

perl -e 'print for <{a,b,c}{1,2,3}>'

I just don’t understand how it works. And it works! Production

a1a2a3b1b2b3c1c2c3

at the exit.

Does anyone know what is going on inside the diamond operator?

+5
source share
1 answer

This is another way to introduce globbing. Basically, curls tell the operator globto take each element separated by commas and combine all the possibilities.

A more understandable way to see this - comma - is to separate individual outputs:

$ perl -e 'print join ",", <{a,b,c}{1,2,3}>;'
a1,a2,a3,b1,b2,b3,c1,c2,c3

From perldoc -f glob:

, glob, , . , , :

@many =  glob "{apple,tomato,cherry}={green,yellow,red}";
+7

All Articles