Presuming you're asking how to specify the name of the file?
To do what you're doing here I would do:
my $userid = "rsennat"; # assume userid is set to a var
my $string = "$str1,$str2";
# NB: using double quotes so that the $userid is interpolated
# Single quotes would protect the literal string like \$userid
my $tmp_file = "/tmp/$userid";
open(TMPFILE, ">> $tmp_file") ||
die "Can't write to '$tmp_file': $!\n";
print TMPFILE $string;
You're better off opening a file and printing to it straight from Perl than relying on shelling out to echo or another command to do the same thing - shelling out (using system
or *cough* backticks) uses another process, is less portable and takes away your script's full control over what you're doing.
The only minus with doing it this way is that you have 3 lines of code instead of 1, but I'd take that hit any day for the improvement it makes to the efficiency, security, reliability and portability of the program!