Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://516265]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-12-28 23:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls