[TxMt] Improved Perl "Read File" snippet

Michael G Schwern schwern at pobox.com
Mon Jan 21 22:55:46 UTC 2008


Hi.   I happened to notice that the Perl "Read File" snippet was using 
bareword filehandles and doing a lot more work than it has to.  The following 
uses lexical filehandles, 3-argument open (to prevent anything in the filename 
from being misinterpreted as an open sigil) and a do block to simplify the 
assignment.

Finally, a third, blank position is provided so you can tab straight to the 
next line instead of the end of the block.


my \$${1:var} = do { local \$/; open my \$fh, "<", "${2:file}"; <\$fh>; };
$3


PS  It's worth mentioning that this is backwards compatible to 5.6 which 
should be more than plenty these days.

-- 
If at first you don't succeed--you fail.
     -- "Portal" demo





More information about the textmate mailing list