#!/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"; 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) However if i change: this line: $mi_obj->add("Fecha-de-Procesamiento", \$fecha); By: $mi_obj->add("Fecha-de-Procesamiento", $fecha); when i execute the script i got: Use of uninitialized value $line in substitution (s///) at /usr/share/perl5/Mail/Header.pm line 175. Use of uninitialized value $line in substitution (s///) at /usr/share/perl5/Mail/Header.pm line 175. Use of uninitialized value $line in substitution (s///) at /usr/share/perl5/Mail/Header.pm line 175. Use of uninitialized value $line in substitution (s///) at /usr/share/perl5/Mail/Header.pm line 175. 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 keep it working as usual? Thanks... a lot Michael.-
In reply to Help with stdout.... in perl.. by fdezmichael
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |