Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

Chapter 2. Idiomatic Perl > Item 16. Know Perl’s other default arguments - Pg. 56

56 Chapter 2 Idiomatic Perl # find files ending in .txt and less than 5000 bytes long @small_txt = grep { /\.txt$/ and (-s) < 5000 } @files; # 5 and 6 Some Perl programmers may feel that $_ is more an aid to obfuscation than to elegance. There is even one book 1 that says, "Many Perl programmers write programs that have references to $_ running like an invisible thread through their programs. Programs that overuse $_ are hard to read and are easier to break than programs that explicitly reference scalar variables you have named yourself." However, which of these is easier on the eyes? while ( defined( $line = <STDIN> ) ) { print $line if $line =~ /Perl/; } while (<STDIN>) { print if /Perl/ } There's no obfuscation here. If you learn a little Perl and know how to use the documentation, any confusion should be short-lived.