3 ms·
This is copied from Perl. See http://stackoverflow.com/questions/161872/hidden-features-of-perl#163700 http://stackoverflow.com/questions/161872/hidden-features
by edward 14y ago
This is copied from Perl. See http://stackoverflow.com/questions/161872/hidden-features-of-perl#163700 http://stackoverflow.com/questions/161872/hidden-features-of...
my @lines = <DATA>;
for (@lines) {
print if /bad/;
}
__DATA__
some good data
some bad data
more good data
more good data
- caiusdurling 14y agoAs quite a good few things in ruby are. Having never really learned perl, I keep discovering them anew in ruby first :-)
- nmcfarl 14y agoAnd widely used in the perl world. It's a good idea for a lot of simple programs.
- oinksoft 14y agoAgreed, this is not a "hidden feature."
- draegtun 14y agoAnd in Perl there are also: __FILE__ , __LINE__ , __PACKAGE__ , __SUB__ & __END__ These are called Special Literals - http://perldoc.perl.org/perldata.html#Special-Literals http://perldoc.perl.org/perldata.html#Special-Literals
- elektronaut 14y agoRuby also has __FILE__ and __LINE__.
- draegtun 14y agoYep. And in Perl6 these were changed to: __LINE__ $?LINE __FILE__ $?FILE __PACKAGE__ $?PACKAGE __END__ =begin END __DATA__ =begin DATA ref: http://feather.perl6.nl/syn/S02.html#Double-underscore_forms http://feather.perl6.nl/syn/S02.html#Double-underscore_forms
- nimrody 14y agoWhich had copied this (including the "DATA" name) from good old BASIC: 10 DATA 1,2,3,4,5,6,7,8,9 20 FOR I=1 TO 9 30 READ A(I) 40 NEXT I