[TxMt] Improved Perl "Read File" snippet
Michael G Schwern
schwern at pobox.com
Tue Jan 22 08:18:11 UTC 2008
Michael Sheets wrote:
> 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'.
I see. Just have to make sure to have a newline at the end of the snippet. I
must have been missing it before.
--
Stabbing you in the face for your own good.
More information about the textmate
mailing list