Computing.Net > Forums > Programming > Perl - how to print to file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Perl - how to print to file

Reply to Message Icon

Name: satimis
Date: November 12, 2004 at 20:06:22 Pacific
OS: FC2
CPU/Ram: Athlon/512M
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: November 13, 2004 at 13:23:53 Pacific
Reply:

#!/usr/bin/perl -w

use strict;
use POSIX;

my $user = `whoami`;

my $now = strftime("%Y.%m.%d.%R", localtime(time));

my $file = "/tmp/satimis/comparison_${user}_${now}.txt";

open FILE, ">$file" or die "unable to open $file $!";

print FILE "this line sent/prints to your $file output file";


0

Response Number 2
Name: satimis
Date: November 15, 2004 at 00:29:31 Pacific
Reply:

Hi FishMonger,

Tks for your advice.

I have tried severl hours on similar syntax without a breakthrough. I can only be allowed to print the "perl" output to a file OR to print it on terminal, but not both. Besides the username was missing on the file created only showing date and time.

Any further advice which I have to observe. TIA

B.R.
satimis


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Perl - how to print to file

HELP ! how to print to printer(parallel www.computing.net/answers/programming/help-how-to-print-to-printerparallel-/2019.html

Perl system command output to files www.computing.net/answers/programming/perl-system-command-output-to-files/19794.html

How to write html code in perl? www.computing.net/answers/programming/how-to-write-html-code-in-perl/12668.html