Simple and sweet

merlyn on 2006-05-26T13:04:54

Q: "How do I get my pid into a file, simply?"

A: print { open my $out, ">", "pidfile"; $out or die } $$, "\n";

Yes, I like Perl.


Odd construction

Aristotle on 2006-05-27T02:17:05

Why not a more traditional form?

print { open my $out, ">", "pidfile" or die "$!"; $out } $$, "\n";

But yeah, that is nifty.

Simpler and Sweeter

uri on 2006-05-30T04:26:26

# this is simpler and clearer IMO

use File::Slurp ;

write_file( 'pid_file', "$$\n" ) ;