[TxMt] Improved Perl "Read File" snippet

Michael Sheets mummer at whitefalls.org
Tue Jan 22 06:15:46 UTC 2008


On Jan 21, 2008, at 4:55 PM, Michael G Schwern wrote:

> 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

The $3 here is actually bad in this case, once you tab to it your  
still inside the snippet. There is always an implicit $0 at the end of  
a snippet (unless it is defined elsewhere) that will be the last tab  
and remove you from the snippet 'mode'.



More information about the textmate mailing list