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"; 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.