Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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!

Comment on Re: put data in dynamic file
Download Code
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2015-11-29 16:18 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (751 votes), past polls