Comments

: Hi folks,: : 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

It is possible to write to a file inside the script. You can also use bash inside of perl but you have to assign it to a perl variable. Something like this will work:

: : Hi folks,: : : : 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: : It is possible to write to a file inside the script. You can also use bash inside of perl but you have to assign it to a perl variable. Something like this will work:: : [code]: #!/usr/bin/perl: : $user = `whoami`;: $now = `date +%Y.%m.%d.%R`;: $file = "/tmp/satimis/comparison_${user}_${now}.txt";: : open(OUT, ">$file") or die "Can't write to $file: $!";: print OUT "This data will go to the file, I hope";: close(OUT);: [/code]: : For the bash commands above, you have to use the backticks around the commands. Then after you open the file, you write to it using the filehandle, which is the word OUT above.: Hope this helps.: If you want all output to go to a file, you can always use:-

open STDOUT, ">$file";

Then just doing:-

print "stuff";

Prints stuff to the file. Of course, that means you can't write anything else to the console.

: If you want all output to go to a file, you can always use:-: : open STDOUT, ">$file";: : Then just doing:-: : print "stuff";: : Prints stuff to the file. Of course, that means you can't write anything else to the console.: : Jonathan: : ###: for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&: (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;: /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");Would it not be better (and I'd guess faster, but could be wrong) to do a [grey]select FILEHANDLE[/grey], so that if you do need to print to the Terminal you can use [grey]print STDOUT[/grey]? You could also open a new handle with filename "-" I expect - or does that go to STDIN/OUT rather than the console?

: : If you want all output to go to a file, you can always use:-: : : : open STDOUT, ">$file";: : : : Then just doing:-: : : : print "stuff";: : : : Prints stuff to the file. Of course, that means you can't write anything else to the console.: : : : Jonathan: : : : ###: : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&: : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;: : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");: Would it not be better (and I'd guess faster, but could be wrong) to : do a [grey]select FILEHANDLE[/grey], so that if you do need to print : to the Terminal you can use [grey]print STDOUT[/grey]?Well, it means you have an extra file handle floating around, but that's not *really* a big deal. So yeah, that's another way to do it and if you still might want to print stuff to the console later that works too. There's more than one way to do it. :-)

: You could also open a new handle with filename "-" I expect - or does : that go to STDIN/OUT rather than the console?: I think "-" in open is for doing IPC stuff with your own children (well, the children of your process... ;-)). If you do something like:-

$pid = open WRITE_TO_FORK "|-";

Then that's equivalent to forking and getting a file handle to the forked process' STDIN so you can write stuff to it. You treat $pid as you'd treat the return value of fork().

- snip -: : You could also open a new handle with filename "-" I expect - or does : : that go to STDIN/OUT rather than the console?: : : I think "-" in open is for doing IPC stuff with your own children (well, the children of your process... ;-)). If you do something like:-: : $pid = open WRITE_TO_FORK "|-";: : Then that's equivalent to forking and getting a file handle to the forked process' STDIN so you can write stuff to it. You treat $pid as you'd treat the return value of fork().

: Hi Jonathan,: : Tks for your advice.: : - snip -: : : You could also open a new handle with filename "-" I expect - or does : : : that go to STDIN/OUT rather than the console?: : : : : I think "-" in open is for doing IPC stuff with your own children (well, the children of your process... ;-)). If you do something like:-: : : : $pid = open WRITE_TO_FORK "|-";: : : : Then that's equivalent to forking and getting a file handle to the forked process' STDIN so you can write stuff to it. You treat $pid as you'd treat the return value of fork().: : I solved my problem with following lines: : Script:-: ......: ......: open FILE, ">$file" or die "Can't open $file for output: $!";: ......: ......: ......: print "";: open FILE, "<$file" or die "could not open file: $!";;: while (<FILE> ){: print;: }: close FILE;: print "";: print "Filename=$file

";: : - END -: : a file created with its content printed on console simultaneously.: : I expect to learn your way. Please advise in more detail how to change those lines.: : TIA: You can always define a sub called print2 (untested, and I've been doing numerical analysis all evening, nothing seems quite the same now)...

- snip -: You can always define a sub called print2 (untested, and I've been doing numerical analysis all evening, nothing seems quite the same now)...: : [code]sub print2 {: print @_;: print FILE @_;: }[/code]: : Then you can do:-: : open FILE, ">$file" or die "Can't open $file for output: $!";: : Where you'd have put print before, you put:-: : print2 "stuff";: : And it prints to the console and the file. Then at the end you just:-: : close FILE;

- snip -

Test performed but failed. "Print to file" OK but "Print on Console" failed

: Any suggestion to fix the problem? TIA: You probably may as well do it the way you were before (write to file, then read back in and display the file) - I thought you would just be using the "print" statement to write stuff to the file. I don't use formats so completely forgot about that. Sorry.

I guess the other option is to define the format for STDOUT too...then do:-