Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with stdout.... in perl..

Status
Not open for further replies.

fdezmichael1

Technical User
Nov 12, 2009
1
0
0
CL
Hi... i have this code....

#!/usr/bin/perl -w
use Mail::Internet;
require Mail::Address;
use Mail::Header;
use File::Find;

my $dir = "/var/spool/cyrus/mail/domain/r/domain.tld";

$file en process_an_email

find(\&find_emails => $dir);

sub find_emails {
return unless /\A[0-9]\.\z/;
return unless -f $File::Find::name;
process_an_email($File::Find::name);
return;
# print $File::Find::name, "\n";
}

$fecha =`date +%F--%k:%M`;

sub process_an_email {
my ($file) = @_;
open(FILE, $file);
$mi_obj = new Mail::Internet(\*FILE);
close(FILE);
$mi_obj->add("Procesado-por-script", "Si");
#$mi_obj->add("Fecha-de-Procesamiento", \$fecha);
$mi_obj->head->replace("Subject", "Tengo hambre.....");
@cuerpo = ("\nEsta es una prueba... reemplazando el cuerpo\n");
$mi_obj->body( \@cuerpo);
open(STDOUT, '>', "$file\.new");
$mi_obj->print_header(\*STDOUT);
$mi_obj->print_body(\*STDOUT);
chown(104, 8, "$file\.new");
}

Everything is working as I need, but now i need to add other header with the date... an that is in the variable $fecha, but every time i execute the script in the header:

Fecha-de-Procesamiento: i Got:

Fecha-de-Procesamiento: SCALAR(0x88deda8)

So... How can i show the date in the format that i need???

And other question is Why everything that I print is not going to STDOUT... because i am redirecting to a variable $file?, is there a way to redirect the STDOUT only in the sub process_an_email...? and in the rest it keep working as usual?

Thanks... a lot

Michael.-

 
Hi,

$fecha is returning a date string OK, however you pass this by reference. Simply changing \$fecha to $fecha should fix this issue (although I did notice that this line was commented out in the above example).

One reason I can think why you are receiving messages outside the redirected STDOUT file would be down to "when" you setup the STDOUT redirect ...

Hope this help...

Steven Parker
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top