Hi list.
Hello,
I tapeworm a disordered file which I repair it and produces this exit to me in my shell:
I am not sure what you mean by "tapeworm"?
UNIDAD | TOTAL ----------------------------------------------------------------------------------------------------|---------- UNIDAD PARA LA PROMOCION Y DEFENSA DE LOS DERECHOS HUMANOS | 1 UNIDAD PARA LA ATENCION DE LAS ORGANIZACIONES SOCIALES | 1 UNIDAD DE ENLACE LEGISLATIVO | 2 UNIDAD DE CONTRALORIA INTERNA | 1 SUBSECRETARIA DE POBLACION,MIGRACION Y ASUNTOS RELIGIOSOS | 1 SUBSECRETARIA DE NORMATIVIDAD DE MEDIOS | 3 SUBSECRETARIA DE ENLACE LEGISLATIVO | 1 SECRETARIA | 4 DIRECCIÓN GENERAL DE DESARROLLO POLÍTICO | 1 DIRECCION GENERAL DE TECNOLOGIAS DE LA INFORMACION | 3 DIRECCION GENERAL DE MEDIOS IMPRESOS | 1 DIRECCION GENERAL DE COMUNICACION SOCIAL | 1 COORDINACION GENERAL DE LA COMISION MEXICANA DE AYUDA A REFUGIADOS | 4 -- UNIDAD SIN DEFINICION -- | 1
14 rows selected.
But when I send it by email the exit is disordered. How could I send this file and receive it ordered in the inbox ????
I am not sure what you mean by "disordered" and "ordered" here as you are not modifying the order of anything in your example below.
This my code:
#!/usr/bin/perl use strict;
my $rmorales = "[EMAIL PROTECTED]"; #- Correo de Rafael Morales
You could use single quotes instead of double quotes there to avoid having to escape special characters.
my $rmorales = '[EMAIL PROTECTED]'; #- Correo de Rafael Morales
my $alertas = "alertaMail.log"; #- Archivo que contiene la informacion de alertas
open MAIL,"|mail $rmorales" || warn "No se ha encontrado la direccion de correo\n$!";
You have a precedence error because the '||' operator has higher precedence then the 'open' operator. Either use the open() function like your other open()s below:
open( MAIL,"|mail $rmorales" ) || warn "No se ha encontrado la direccion de correo\n$!";
Or use the lower precedence 'or' operator:
open MAIL,"|mail $rmorales" or warn "No se ha encontrado la direccion de correo\n$!";
You are using 'warn' instead of 'die' to report an error if open() fails which means that even if open() fails you are still printing to an invalid filehandle. Also opening pipes requires more error checking then normal files:
perldoc -f close [snip] If the file handle came from a piped open "close" will additionally return false if one of the other system calls involved fails or if the program exits with non-zero status. (If the only problem was that the program exited non-zero $! will be set to 0.) Closing a pipe also waits for the process executing on the pipe to complete, in case you want to look at the output of the pipe afterwards, and implicitly puts the exit status value of that command into $?.
Prematurely closing the read end of a pipe (i.e. before the process writing to it at the other end has closed it) will result in a SIGPIPE being delivered to the writer. If the other end can't handle that, be sure to read all the data before closing the pipe.
Example:
open(OUTPUT, '|sort >foo') # pipe to sort or die "Can't start sort: $!"; #... # print stuff to output close OUTPUT # wait for sort to finish or warn $! ? "Error closing sort pipe: $!" : "Exit status $? from sort"; [snip]
perldoc perlipc [snip] Using open() for IPC
[snip]
Be careful to check both the open() and the close() return values. If you're writing to a pipe, you should also trap SIGPIPE. Otherwise, think of what happens when you start up a pipe to a command that doesn't exist: the open() will in all likelihood succeed (it only reflects the fork()'s success), but then your output will fail--spectacularly. Perl can't know whether the command worked because your command is actually running in a separate process whose exec() might have failed. Therefore, while readers of bogus commands return just a quick end of file, writers to bogus command will trigger a signal they'd better be prepared to handle. Consider:
open(FH, "|bogus") or die "can't fork: $!"; print FH "bang\n" or die "can't write: $!"; close FH or die "can't close: $!"; [snip]
open (ALERTAS, "<$alertas") || die "No se ha encontrado el archivo $alertas\n$!"; open (TOTAL, ">total.txt") || die "No se puede escribir en el archivo total.txt\n$!";
foreach (<ALERTAS>)
You should use a while loop instead of a foreach loop because the foreach loop will read the entire file into memory.
while (<ALERTAS>)
{ $_=~ s/(\w)\s\t/$1/; $_=~ s/(--)\t\t/$1/; print TOTAL "$_";
The $_ variable is the default for most of perl's operators so you don't *need* to use it in the previous three statements but it doesn't hurt.
print MAIL "$_\n"; } close (ALERTAS);
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>