#!/usr/bin/perl -w use File::Basename; use strict; use warnings; use diagnostics; my $pid=$$; my $name=basename($0); my $pidfile="/var/tmp/" . $name . "." . $pid; printf "I'm going to use: %s\n",$pidfile; #### --$ perl procpid.pl I'm going to use: /var/tmp/procpid.pl.1974 #### use FileHandle; # Add this with the rest of the uses : : # do the filename calculation steps shown above : my $fh=new FileHandle("> $pidfile") or die $!; print $fh "$$"; # Or whatever you want to write undef $fh; #automatically closes the file #### $pidfile =~ s/\.pl//;