Ir al contenido principal

Entradas

Mostrando entradas de 2013

Derreferenciamiento en Perl

Interpretación provisoria. No está basada en la teoría, sino en el caso empírico dado. perl -w o bien use strict deberían quejarse de la mayoría de estos casos. Código: @ARY = ( [ qw(vilma palma vampiro) ], [ qw(zapallo zanahoria zapallito) ] ); print "@ARY\n";   # 1) Testigo print ARY[1];   # 2) La expresión de derreferenciamiento requiere un caracter de tipo bien al principio. El subscript [] no es suficiente para que Perl sepa que nos estamos refiriendo al array ARY. print "\n"; print "@{ARY[1]}\n";   # 3) Adentro de {}: no rige la regla del caso (2). Afuera de {}: derreferenciamento impropio de un escalar con @. print "@ARY[1]\n"; # 4) El caracter de tipo tiene mayor precedencia que el subscript de matrices [] (perldsc sobre Perl 5.12.5, "Caveat on precedence"), excepto que la regla (2) tiene mayor prioridad. Mismo mecanismo que el caso (3). print "@{@ARY[1]}\n"; # 5) Adentro de {}: Si hay un @ bien al principio...

Pruebas manejo de punteros y matrices en C

Código 1: Compilador: gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5), y a parte Visual C++ (ver nota a continuación) Compilation flags -Wall -g // matrix operations #include <stdio.h> void myPrint(int **table, int x, int y); int main(int argc, char **argv) {   int matrix[3][3];   matrix[0][0] = 2;   matrix[0][1] = 3;   matrix[0][2] = 5;   matrix[1][0] = 1;   matrix[1][1] = 4;   matrix[1][2] = 16;   matrix[2][0] = 9;   matrix[2][1] = 28;   matrix[2][2] = 14;   myPrint(matrix, 2, 1);   return 0; } void myPrint(int **table, int x, int y) {   printf("%d\n", table[x][y]); } Compilación: warning: passing argument 1 of ‘myPrint’ from incompatible pointer type note: expected ‘int **’ but argument is of type ‘int (*)[3]’ Ejecución: Fallo de segmentación Nota: en Visual C++ la validación de tip os es más estr icta y ha y que agregar - myPrint((int **)matrix, 2, 1);   // conciliación de tipos entre parámetro...

SQL - selección en base a rangos de fechas

Patrón: - La relación tiene atributos de fecha inicio y fin (fecha_inicio_relación y fecha_fin_relación). - La selección se quiere hacer según un rango fecha inicio y fin (fecha_inicio_selección y fecha_fin_selección), seleccionando todas en las que los segmentos se toquen o se superpongan (ver imagen): fecha_inicio_relación                          f echa_fin_relación |——————————————| fecha_inicio_selección                        fecha_fin_selección |——————————————| Query: select * from relación where (fecha_inicio_relación <= fecha_inicio_selección and fecha_fin_relación >= fecha_inicio_selección or fecha_inicio_relación <= fecha_fin_selección and fecha_fin_relación >= fecha_fin_selección or fecha_inicio_relación ...

CVS desde la línea de comandos

Software: http://www.nongnu.org/cvs/ Login cvs -d:método_acceso*:user@host:/path login Emitir un log de tags: archivo, revisión actual head, branch y su revisión actual, todas las revisiones cvs -d:método_acceso*:user@host:/path_1 rlog path_2 (relativo a path_1) Emitir un reporte histórico: movimiento, fecha hora, revisión, archivo, path cvs -d:método_acceso*:user@host:/path_1 history path_2 (relativo a path_1) -c *método_acceso: pserver, local, etc.

Tokens - programa en Perl para parsear XML

Sinopsis use Tokens; open my $regex_fh, '&lt;', $ARGV[0]; #regex.txt open my $target_fh, '&lt;', $ARGV[1]; #file.txt my $target; {   local $/ = undef;   $target = &lt;$target_fh&gt;; #the content   $target =~ s/\n/ /g; } my $regex; {   local $/ = undef;   $regex = &lt;$regex_fh&gt;; #the content } printAll parse $target, $regex;   Códio (archivo: Tokens.pm): =pod  Copyright 2013 Gabriel Czernikier     This program is free software: you can redistribute it and/or modify     it under the terms of the GNU General Public License as published by     the Free Software Foundation, either version 3 of the License, or     (at your option) any later version.     This program is distributed in the hope that it will be useful,     but WITHOUT ANY WARRANTY; without even the implied warranty of     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  Se...

DB2 - manejar jerarquías de idiomas

En DB2, seleccionar datos de una tabla "tabla_origen", buscando con una "mi_clave_busqueda" que tiene multiplicidad n (los datos están en n idiomas), de los cuales me interesa recuperar el idioma que (para mí) tenga mayor prioridad, si no el siguiente, y así sucesivamente. with mis_idiomas as (       select * from table (             select 'es' ,   1 from sysibm.sysdummy1 union all             select 'fr' ,   2 from sysibm.sysdummy1 union all             select 'en' ,   3 from sysibm.sysdummy1 union all             select 'he' ,   4 from sysibm.sysdummy1       ) as t (idioma, ord) ), T2 as (       select tor.mi_clave_busqueda, min (o...