Hacker News new | past | comments | ask | show | jobs | submit login
Perl has built-in temp files (manxome.org)
8 points by kamaal on May 23, 2015 | hide | past | favorite | 1 comment



> When I asked on IRC recently, whether I was missing some reason that it wasn't more common, almost every single response was, "Woah, I never heard of that feature."

They should read the excellent perldocs for 'open' [0][1], it's been available since ~2002 (Perl 5.8) [2][3]

You can change the directory it uses by overriding the defailt $TMPDIR ($ENV{TMP} in Windows 7)

    $ENV{TMP} = '/path/to/my/tmp/dir';

    open my $fh2, '+>', undef or die "$!";
It was introduced along with another useful feature, 'File handles can be opened to "in memory" files held in Perl scalars' [0][2]

    open(my $fh,'>', \my $variable) or die "$!";

    ... do stuff to $variable as if it were a file

[0] http://perldoc.perl.org/functions/open.html

[1] http://perldoc.perl.org/perlopentut.html

[2] http://perldoc.perl.org/perl58delta.html#PerlIO-is-Now-The-D...

[3] https://books.google.com/books?id=IzdJIax6J5oC&lpg=PA1&dq=&p...




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: