LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl-how to print to file (https://www.linuxquestions.org/questions/programming-9/perl-how-to-print-to-file-254220/)

satimis 11-12-2004 09:51 PM

Perl-how to print to file
 
Hi folks,

Perl
====

Instead of using following command printing output to a file;

$ perl AAA.pl > /pathto/name_of_file

is it possible adding "print file function" to the script

1) If YES
Please advise how to make it.

2) Can I add following bash syntax to the script
user=$(whoami);
now=$(date +%Y.%m.%d.%R);
File="/tmp/satimis/comparison_${user}_${now}.txt";

so that the printout file will carry name of creator, date and time, etc.

If possible please shed me some light to re-edit the script.

TIA

B.R.
satimis

j-ray 11-13-2004 10:40 AM

u just have to pass the username to the perl script. open a filehandle in the script, write the output.
i guess u'll find some more info here...
http://webdevelopment.developersnetw...sp?Article=139

satimis 11-17-2004 03:20 AM

Quote:

Originally posted by j-ray
u just have to pass the username to the perl script. open a filehandle in the script, write the output.
i guess u'll find some more info here...
http://webdevelopment.developersnetw...sp?Article=139

Hi j-ray,

Tks for your advice and URL

B.R.
satimis

sirclif 11-17-2004 08:09 PM

your answer to question 2:
user=$(whoami);
now=$(date +%Y.%m.%d.%R);
File="/tmp/satimis/comparison_${user}_${now}.txt";

$user = `whoami`;
$now = `date +%Y.%m.%d.%R`
$File = "/tmp/satmis/comparison_$user_$now.txt"

those aren't regualr single quoats, they the back tics that share a key with ~.
basically $var = `command` will set the $var to whatever the output of the command is

satimis 11-17-2004 10:56 PM

Hi sirclif,

Quote:

your answer to question 2:
user=$(whoami);
now=$(date +%Y.%m.%d.%R);
File="/tmp/satimis/comparison_${user}_${now}.txt";
........................

Tks for your advice.

B.R.
satimis


All times are GMT -5. The time now is 12:14 AM.