One of the modules I have recently released to CPAN reads JSON data from STDIN on a webserver. To write the tests I have had to simulate this.
Using code I found in an answer on SO, I have written code similar to this test:
But I don't understand how or why it works...use strict; use warnings; *STDIN = *DATA; while (my $test = <STDIN>) { print "$test\n"; } __DATA__ one two three four
I've read the documentation and still don't understand it.
My understanding of a typeglob is that it is a legacy left over from the days before Perl had references. It manipulates the scalar, array and hash of the same name simultaneously. Still, it shouldn't be used in modern Perl because it is generally bad practice to call arrays, hashes and scalars by the same name and references have replaced its necessity. References, thanks to my time in The Monastery, I understand reasonably well.
Is there a better way to do what the above code does?
Can you help me understand this use of a typeglob and typeglobs more generally?
Am I able to 'reset' the __DATA__ input so that I can use the same input for testing again or should I put multiple tests in different test files?
In reply to STDIN typeglob by Bod
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |