Berkeley CSUA MOTD:Entry 48942
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/28 [General] UID:1000 Activity:popular
5/28    

2008/1/14-18 [Computer/SW/Languages/Perl] UID:48942 Activity:nil
1/14    My perl foo is weak. What's a simple elegant way to write the content of
        $result to the file $filename? Thanks!
        \_ open(FILE,">$filename");print FILE $result;close FILE;  -tom
           \_ Added a $ in the right spot
        \_ Depending on what you're doing: perl's print default to STDOUT, so
           you can also just print $result; and then run your script from the
           command line as: foo.pl > file.  When doing the open() you also
           probably want to test that the open succeeded.  You may not have
           perms on the file, you may have typod the path, etc.
        \_ Dependin on how complex $result is you can also do shell escapes
           in perl.  I.e.   system "echo $result >> $filename";
           \_ Not exactly elegant when the real solution fits in about 1/2
              again as many characters.