Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: put data in dynamic file

by serf (Chaplain)
on Dec 13, 2005 at 09:33 UTC ( #516265=note: print w/replies, xml ) Need Help??

in reply to put data in dynamic file

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; close(TMPFILE);
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!

Replies are listed 'Best First'.
Re^2: put data in dynamic file
by rsennat (Beadle) on Dec 13, 2005 at 09:37 UTC
    yes. "/tmp/$userid" - system command line gives error.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://516265]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2018-05-23 17:37 GMT
Find Nodes?
    Voting Booth?