<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="http://govem.gnu.org.mx/gadgets/Blog/templates/atom.xsl" ?><feed xmlns="http://www.w3.org/2005/Atom">
<link rel="self"  href="http://govem.gnu.org.mx/data/xml/blog.atom" title="Govem" />
<title  type="text" >Govem</title>
	<author>
		<name>Miguel Vazquez Gocobachi</name>
		<uri>http://govem.gnu.org.mx</uri>
	</author>
<subtitle  type="text" >Miguel Vazquez Gocobachi</subtitle>
<id>http://govem.gnu.org.mx</id>
<generator>JAWS 0.8.5</generator>
<rights  type="text" >2008, Miguel Vazquez Gocobachi</rights>
<updated>2008-10-02T20:58:15+02:00</updated>
<entry>
	<title  type="text" ><![CDATA[ ¿Cómo tener autoincrement en PostgreSQL? ]]></title>
	<link rel="alternate"  type="text/html"  href="http://govem.gnu.org.mx/index.php/blog/show/%C2%BFC%C3%B3mo-tener-autoincrement-en-PostgreSQL%3F" title="¿Cómo tener autoincrement en PostgreSQL?" />
	<author>
		<name>Miguel Vazquez Gocobachi</name>
		<uri>http://govem.gnu.org.mx/admin.php</uri>
	</author>
	<id>http://govem.gnu.org.mx/index.php/blog/show/%C2%BFC%C3%B3mo-tener-autoincrement-en-PostgreSQL%3F</id>
	<updated>2008-10-02T20:58:15+02:00</updated>
	<published>2008-10-02T19:23:05+02:00</published>
	<summary  type="html" ><![CDATA[ Este es un punto interesante, si utilizas MySQL y en cierto momento te ves obligado a usar PostgreSQL o simplemente por gusto te encontraras con algunas diferencias ligeramente importantes, una de ellas es el autoincrement que manejas en MySQL y que en PostgreSQL requieres hacer algo diferente <img src="plugins/Emoticons/images/face-smile.png" border="0" alt="face-smile.png " width="16" height="16" /><br />
<br />
Hay dos maneras de utilizar esta funcionalidad en PostgreSQL, la primera es crear una secuencia y la tabla, y la otra es asignarle directamente el tipo al campo de la tabla. En el ejemplo la tabla se llama "foo".<br />
<br />
1.- Creando la secuencia y la tabla<br />
<br />
<div class="code"><div class="sql" style="font-family: monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> SEQUENCE foo_id_seq;<br /><span style="color: #993333; font-weight: bold;">CREATE</span>&#160; <span style="color: #993333; font-weight: bold;">TABLE</span> foo <span style="color: #66cc66;">&#40;</span><br /><br />
&#160; &#160; id integer <span style="color: #993333; font-weight: bold;">DEFAULT</span>&#160; <span style="color: #993333; font-weight: bold;">NEXTVAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'foo_id_seq'</span><span style="color: #66cc66;">&#41;</span><span style="color: #993333; font-weight: bold;">NOT</span>&#160; <span style="color: #993333; font-weight: bold;">NULL</span>,<br /><br />
&#160; &#160; name character varying<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>&#160; <span style="color: #993333; font-weight: bold;">NOT</span>&#160; <span style="color: #993333; font-weight: bold;">NULL</span><br /><span style="color: #66cc66;">&#41;</span>;<br /><br />
&#160;</div></div>
<br />
2.- Creando la tabla con el tipo "serial" para el campo "id".<br />
<div class="code"><div class="sql" style="font-family: monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span>&#160; <span style="color: #993333; font-weight: bold;">TABLE</span> foo <span style="color: #66cc66;">&#40;</span><br /><br />
&#160; &#160; id serial,<br /><br />
&#160; &#160; name character varying<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>&#160; <span style="color: #993333; font-weight: bold;">NOT</span>&#160; <span style="color: #993333; font-weight: bold;">NULL</span><br /><span style="color: #66cc66;">&#41;</span>;<br /><br />
&#160;</div></div>
<br />
Interesante, ¿verdad? <img src="plugins/Emoticons/images/face-smile-big.png" border="0" alt="face-smile-big.png " width="16" height="16" /> ]]></summary>
	<content  type="html" ><![CDATA[ Este es un punto interesante, si utilizas MySQL y en cierto momento te ves obligado a usar PostgreSQL o simplemente por gusto te encontraras con algunas diferencias ligeramente importantes, una de ellas es el autoincrement que manejas en MySQL y que en PostgreSQL requieres hacer algo diferente <img src="plugins/Emoticons/images/face-smile.png" border="0" alt="face-smile.png " width="16" height="16" /><br />
<br />
Hay dos maneras de utilizar esta funcionalidad en PostgreSQL, la primera es crear una secuencia y la tabla, y la otra es asignarle directamente el tipo al campo de la tabla. En el ejemplo la tabla se llama "foo".<br />
<br />
1.- Creando la secuencia y la tabla<br />
<br />
<div class="code"><div class="sql" style="font-family: monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> SEQUENCE foo_id_seq;<br /><span style="color: #993333; font-weight: bold;">CREATE</span>&#160; <span style="color: #993333; font-weight: bold;">TABLE</span> foo <span style="color: #66cc66;">&#40;</span><br /><br />
&#160; &#160; id integer <span style="color: #993333; font-weight: bold;">DEFAULT</span>&#160; <span style="color: #993333; font-weight: bold;">NEXTVAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'foo_id_seq'</span><span style="color: #66cc66;">&#41;</span><span style="color: #993333; font-weight: bold;">NOT</span>&#160; <span style="color: #993333; font-weight: bold;">NULL</span>,<br /><br />
&#160; &#160; name character varying<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>&#160; <span style="color: #993333; font-weight: bold;">NOT</span>&#160; <span style="color: #993333; font-weight: bold;">NULL</span><br /><span style="color: #66cc66;">&#41;</span>;<br /><br />
&#160;</div></div>
<br />
2.- Creando la tabla con el tipo "serial" para el campo "id".<br />
<div class="code"><div class="sql" style="font-family: monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span>&#160; <span style="color: #993333; font-weight: bold;">TABLE</span> foo <span style="color: #66cc66;">&#40;</span><br /><br />
&#160; &#160; id serial,<br /><br />
&#160; &#160; name character varying<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>&#160; <span style="color: #993333; font-weight: bold;">NOT</span>&#160; <span style="color: #993333; font-weight: bold;">NULL</span><br /><span style="color: #66cc66;">&#41;</span>;<br /><br />
&#160;</div></div>
<br />
Interesante, ¿verdad? <img src="plugins/Emoticons/images/face-smile-big.png" border="0" alt="face-smile-big.png " width="16" height="16" /> ]]></content>
		<category scheme="http://govem.gnu.org.mx/index.php/blog/category/2" term="2" label="Hacks"/>
		<category scheme="http://govem.gnu.org.mx/index.php/blog/category/11" term="11" label="SQL"/>
</entry>
<entry>
	<title  type="text" ><![CDATA[ Trim en Perl ]]></title>
	<link rel="alternate"  type="text/html"  href="http://govem.gnu.org.mx/index.php/blog/show/Trim-en-Perl" title="Trim en Perl" />
	<author>
		<name>Miguel Vazquez Gocobachi</name>
		<uri>http://govem.gnu.org.mx/admin.php</uri>
	</author>
	<id>http://govem.gnu.org.mx/index.php/blog/show/Trim-en-Perl</id>
	<updated>2008-10-02T19:20:04+02:00</updated>
	<published>2008-09-19T19:33:51+02:00</published>
	<summary  type="html" ><![CDATA[ <br />
Muchas veces he utilizado la función trim() en PHP para eliminar espacios al principio y final de una linea. Esto se vuelve un problema cuando deseas hacer lo mismo en Perl, ¿por qué? Porque no existe función en perl que haga tal cosa, asi que aquí tenemos un ejemplo de como implementarlo en nuestras aplicaciones de Perl.<br />
<br />
<div class="code"><div class="perl" style="font-family: monospace;"><span style="color: #000000; font-weight: bold;">sub</span> trim <span style="color: #66cc66;">&#123;</span><br /><br />
&#160; &#160; <span style="color: #b1b100;">my</span>&#160; <span style="color: #0000ff;">$str</span> = <a href="http://www.perldoc.com/perl5.6/pod/func/shift.html"><span style="color: #000066;">shift</span></a>;<br /><br />
&#160; &#160; <span style="color: #0000ff;">$str</span> =~ <a href="http://www.perldoc.com/perl5.6/pod/func/s.html"><span style="color: #000066;">s</span></a>/^\<a href="http://www.perldoc.com/perl5.6/pod/func/s.html"><span style="color: #000066;">s</span></a>+//;<br /><br />
&#160; &#160; <span style="color: #0000ff;">$str</span> =~ <a href="http://www.perldoc.com/perl5.6/pod/func/s.html"><span style="color: #000066;">s</span></a>/\<a href="http://www.perldoc.com/perl5.6/pod/func/s.html"><span style="color: #000066;">s</span></a>+$//;<br /><br />
&#160; &#160; <a href="http://www.perldoc.com/perl5.6/pod/func/return.html"><span style="color: #000066;">return</span></a>&#160; <span style="color: #0000ff;">$str</span>;<br /><span style="color: #66cc66;">&#125;</span><br /><br />
&#160;</div></div>
<br />
Y su uso es tan simple como lo siguiente:<br />
<br />
<div class="code"><div class="perl" style="font-family: monospace;"><span style="color: #b1b100;">my</span>&#160; <span style="color: #0000ff;">$string</span> = trim<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">' Foo bar '</span><span style="color: #66cc66;">&#41;</span>;<br /><br />
&#160;</div></div>
<br />
Happy hacking! ]]></summary>
	<content  type="html" ><![CDATA[ <br />
Muchas veces he utilizado la función trim() en PHP para eliminar espacios al principio y final de una linea. Esto se vuelve un problema cuando deseas hacer lo mismo en Perl, ¿por qué? Porque no existe función en perl que haga tal cosa, asi que aquí tenemos un ejemplo de como implementarlo en nuestras aplicaciones de Perl.<br />
<br />
<div class="code"><div class="perl" style="font-family: monospace;"><span style="color: #000000; font-weight: bold;">sub</span> trim <span style="color: #66cc66;">&#123;</span><br /><br />
&#160; &#160; <span style="color: #b1b100;">my</span>&#160; <span style="color: #0000ff;">$str</span> = <a href="http://www.perldoc.com/perl5.6/pod/func/shift.html"><span style="color: #000066;">shift</span></a>;<br /><br />
&#160; &#160; <span style="color: #0000ff;">$str</span> =~ <a href="http://www.perldoc.com/perl5.6/pod/func/s.html"><span style="color: #000066;">s</span></a>/^\<a href="http://www.perldoc.com/perl5.6/pod/func/s.html"><span style="color: #000066;">s</span></a>+//;<br /><br />
&#160; &#160; <span style="color: #0000ff;">$str</span> =~ <a href="http://www.perldoc.com/perl5.6/pod/func/s.html"><span style="color: #000066;">s</span></a>/\<a href="http://www.perldoc.com/perl5.6/pod/func/s.html"><span style="color: #000066;">s</span></a>+$//;<br /><br />
&#160; &#160; <a href="http://www.perldoc.com/perl5.6/pod/func/return.html"><span style="color: #000066;">return</span></a>&#160; <span style="color: #0000ff;">$str</span>;<br /><span style="color: #66cc66;">&#125;</span><br /><br />
&#160;</div></div>
<br />
Y su uso es tan simple como lo siguiente:<br />
<br />
<div class="code"><div class="perl" style="font-family: monospace;"><span style="color: #b1b100;">my</span>&#160; <span style="color: #0000ff;">$string</span> = trim<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">' Foo bar '</span><span style="color: #66cc66;">&#41;</span>;<br /><br />
&#160;</div></div>
<br />
Happy hacking! ]]></content>
		<category scheme="http://govem.gnu.org.mx/index.php/blog/category/2" term="2" label="Hacks"/>
		<category scheme="http://govem.gnu.org.mx/index.php/blog/category/7" term="7" label="Perl"/>
</entry>
<entry>
	<title  type="text" ><![CDATA[ Serialización en Perl ]]></title>
	<link rel="alternate"  type="text/html"  href="http://govem.gnu.org.mx/index.php/blog/show/Serializando-en-Perl" title="Serialización en Perl" />
	<author>
		<name>Miguel Vazquez Gocobachi</name>
		<uri>http://govem.gnu.org.mx/admin.php</uri>
	</author>
	<id>http://govem.gnu.org.mx/index.php/blog/show/Serializando-en-Perl</id>
	<updated>2008-10-02T19:19:33+02:00</updated>
	<published>2008-09-19T00:34:30+02:00</published>
	<summary  type="html" ><![CDATA[ <br />
Una de las cosas que utilizo con mayor frecuencia es la serialización de datos en PHP. Ahora, trabajando con Perl he decidido utilizar dicha funcionalidad para el almacenamiento de cierta información en un sistema Web, así que utilizando el grandioso CPAN he obtenido el módulo correspondiente.<br />
<br />
Para poder serializar datos es necesario contar con el modulo <strong><a href="http://search.cpan.org/~bobtfish/PHP-Serialization-0.29/lib/PHP/Serialization.pm">PHP::Serialization</a></strong>, el cual puede ser instalado por medio del shell de perl para CPAN. A continuación, un sencillo ejemplo de su uso:<br />
<br />
<div class="code"><div class="perl" style="font-family: monospace;"><span style="color: #000000; font-weight: bold;">use</span> strict;<br /><span style="color: #000000; font-weight: bold;">use</span> PHP::<span style="color: #006600;">Serialization</span>&#160; <a href="http://www.perldoc.com/perl5.6/pod/func/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #66cc66;">&#40;</span>serialize unserialize<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #b1b100;">my</span>&#160; <span style="color: #0000ff;">$serialized</span>&#160; &#160;= serialize<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>a =&gt; <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span>, b =&gt; <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #b1b100;">my</span>&#160; <span style="color: #0000ff;">$deserialized</span> = deserialize<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$serialized</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<a href="http://www.perldoc.com/perl5.6/pod/func/print.html"><span style="color: #000066;">print</span></a>&#160; <span style="color: #0000ff;">$deserialized</span>-&gt;<span style="color: #66cc66;">&#123;</span>b<span style="color: #66cc66;">&#125;</span>;<br /><br />
&#160;</div></div>
<br />
Su uso es muy simple, asi se que solo basta almacenar la información de <strong>$serialized</strong> en un campo text de <strong>SQL</strong>. ]]></summary>
	<content  type="html" ><![CDATA[ <br />
Una de las cosas que utilizo con mayor frecuencia es la serialización de datos en PHP. Ahora, trabajando con Perl he decidido utilizar dicha funcionalidad para el almacenamiento de cierta información en un sistema Web, así que utilizando el grandioso CPAN he obtenido el módulo correspondiente.<br />
<br />
Para poder serializar datos es necesario contar con el modulo <strong><a href="http://search.cpan.org/~bobtfish/PHP-Serialization-0.29/lib/PHP/Serialization.pm">PHP::Serialization</a></strong>, el cual puede ser instalado por medio del shell de perl para CPAN. A continuación, un sencillo ejemplo de su uso:<br />
<br />
<div class="code"><div class="perl" style="font-family: monospace;"><span style="color: #000000; font-weight: bold;">use</span> strict;<br /><span style="color: #000000; font-weight: bold;">use</span> PHP::<span style="color: #006600;">Serialization</span>&#160; <a href="http://www.perldoc.com/perl5.6/pod/func/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #66cc66;">&#40;</span>serialize unserialize<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #b1b100;">my</span>&#160; <span style="color: #0000ff;">$serialized</span>&#160; &#160;= serialize<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>a =&gt; <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span>, b =&gt; <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #b1b100;">my</span>&#160; <span style="color: #0000ff;">$deserialized</span> = deserialize<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$serialized</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<a href="http://www.perldoc.com/perl5.6/pod/func/print.html"><span style="color: #000066;">print</span></a>&#160; <span style="color: #0000ff;">$deserialized</span>-&gt;<span style="color: #66cc66;">&#123;</span>b<span style="color: #66cc66;">&#125;</span>;<br /><br />
&#160;</div></div>
<br />
Su uso es muy simple, asi se que solo basta almacenar la información de <strong>$serialized</strong> en un campo text de <strong>SQL</strong>. ]]></content>
		<category scheme="http://govem.gnu.org.mx/index.php/blog/category/2" term="2" label="Hacks"/>
		<category scheme="http://govem.gnu.org.mx/index.php/blog/category/7" term="7" label="Perl"/>
</entry>
</feed>