<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EVOL.reverse &#187; Perl</title>
	<atom:link href="http://www.morgadinho.org/category/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.morgadinho.org</link>
	<description>Let Yourself Be Conducted By It</description>
	<lastBuildDate>Mon, 26 Jul 2010 14:56:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Hackers, Makers and Geeks in Lisbon</title>
		<link>http://www.morgadinho.org/2009/12/11/hackers-makers-and-geeks-in-lisbon/</link>
		<comments>http://www.morgadinho.org/2009/12/11/hackers-makers-and-geeks-in-lisbon/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 10:50:14 +0000</pubDate>
		<dc:creator>Nuno Morgadinho</dc:creator>
				<category><![CDATA[Entrepreneurship]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Ruby on Rails - MVC]]></category>
		<category><![CDATA[Start-ups]]></category>

		<guid isPermaLink="false">http://www.morgadinho.org/?p=2204</guid>
		<description><![CDATA[As I mentioned in my previous post, I have some friends who are not applying to SeedCapital because they are by themselves. Unfortunately there isn&#8217;t yet a place where people can see what projects are in need of more people. It is also not that easy to meet someone on-line to work together. We need [...]]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my previous post, I have some friends who are not applying to <a href="http://www.seedcapital.pt" target="_blank">SeedCapital</a> because they are by themselves. Unfortunately there isn&#8217;t yet a place where people can see what projects are in need of more people. It is also not that easy to meet someone on-line to work together. We need a certain trust in that person, etc.</p>
<p>I think the best way to meet people that are interested, smart and have initiative is to attend one of the many hacker events that are held monthly (or at least regularly). In Lisbon we have several of them:</p>
<p>Twittlis &#8211; monthly meeting of twitter.com users in Lisbon<br />
<a href="http://upcoming.yahoo.com/event/4884748/pt/Lisbon/Twittlis-monthly-meeting-of-twittercom-users-in-Lisbon-19/Mar-Adentro" target="_blank">http://upcoming.yahoo.com/event/4884748/pt/Lisbon/Twittlis-monthly-meeting-of-twittercom-users-in-Lisbon-19/Mar-Adentro</a></p>
<p>AltLab Hackerspace Lisbon<br />
<a href="http://altlab.org/" target="_blank">http://altlab.org/</a></p>
<p>Lisbon Perl Mongers Group<br />
<a href="http://lisbon.pm.org/" target="_blank">http://lisbon.pm.org/</a></p>
<p>Comunidade Portuguesa de Rich Internet Applications<br />
<a href="http://www.riapt.org/" target="_blank">http://www.riapt.org/</a></p>
<p>Lisbon Ruby Group<br />
<a href="http://www.ruby-pt.org/ " target="_blank"><a href="http://www.ruby-pt.org/" rel="nofollow">http://www.ruby-pt.org/</a> </a></p>
<p>Gathering of Developers<br />
<a href="http://god.pt/" target="_blank">http://god.pt/</a></p>
<p>One Over Zero Group<br />
<a href="http://oneoverzero.org/" target="_blank">http://oneoverzero.org/</a></p>
<p>Do you know of any other groups?</p>
<p><strong>Update (13/12/2009): </strong>Since this post I&#8217;ve found out about the following groups:</p>
<p>XAMLPT – Comunidade Portuguesa para Tecnologias de Apresentação da Microsoft: WPF, Silverlight, Surface<br />
<a href="http://www.xamlpt.com" target="_blank">http://www.xamlpt.com</a></p>
<p>Ignite Portugal<br />
<a href="http://www.igniteportugal.blogspot.com" target="_blank">http://www.igniteportugal.blogspot.com</a></p>
<p>Portuguese Ubuntu Community<br />
<a href="http://www.ubuntu-pt.org" target="_blank">http://www.ubuntu-pt.org</a></p>
<p>Mobile Monday Portugal<br />
<a href="http://mobilemondayportugal.com" target="_blank">http://mobilemondayportugal.com</a></p>
<p>Confraria Security &amp; IT<br />
<a href="http://events.linkedin.com/Confraria-Security-TB-Store/pub/50120" target="_blank">http://events.linkedin.com/Confraria-Security-TB-Store/pub/50120</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.morgadinho.org/2009/12/11/hackers-makers-and-geeks-in-lisbon/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Perl Reading XML</title>
		<link>http://www.morgadinho.org/2009/01/29/perl-reading-xml/</link>
		<comments>http://www.morgadinho.org/2009/01/29/perl-reading-xml/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 18:16:14 +0000</pubDate>
		<dc:creator>Nuno Morgadinho</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.morgadinho.org/?p=1456</guid>
		<description><![CDATA[<p>
Today I had to do a <acronym title="Practical Extraction and Report Language">Perl</acronym> program to poke inside an <acronym title="Extensible Markup Language">XML</acronym> file and read out some values. I had a quick go with the CPAN module <acronym title="Extensible Markup Language">XML</acronym>::Simple but found it to be horrible. Yuck. I ended up using <acronym title="Extensible Markup Language">XML</acronym>::MyXML instead and I must say I&#8217;m much more impressed with it. I also wrote some test code just to be sure everything was ok and guarantee it doesn&#8217;t break if someone changes the <acronym title="Extensible Markup Language">XML</acronym>. Here is a quick roundup of what I did.
</p>
<p>
This was the <acronym title="Extensible Markup Language">XML</acronym> I had:
</p>

<pre class="code">



    Param1
    domain
    Filetype1
    machine1

      machine1
      machine2


      /export/home/user/file1.tmp

    Thursday, 29 January 2009 08:45:05 GMT


  FLOWING


</pre>

<p>
Only the attributes &#8220;Destinations&#8221; and &#8220;File_Names&#8221; are more complicated because they can contain multiple entries. Everything else is pretty straight forward, even using <acronym title="Extensible Markup Language">XML</acronym>::Simple.
</p>
<p>
<!-- SECTION [0-29] --></p>
<a name="the_main_program"></a><h2 class='wiki'>The Main Program</h2><div class="level2">

<p>
Here is the main file I did. It consists basically of opening the <acronym title="Extensible Markup Language">XML</acronym> file, reading it and calling one of the functions that reads one of the attributes of the <acronym title="Extensible Markup Language">XML</acronym>, in this case, get_filetype.
</p>

<pre class="code">
#!/usr/bin/perl -w

use strict;
use XML::MyXML qw(tidy_xml xml_to_object);
use XML::MyXML qw(:all);

require &quot;readXML.pl&quot;;

sub main() {
    my $file = &quot;test.xml&quot;;

    # this is needed because we read the whole file at once
    my $holdTerminator = $/;
    undef $/;

    open(FILE, &quot;&amp;lt;$file&amp;quot;) || die &amp;quot;Could not open file: $1&amp;quot;;
    my $xml = ;
    #print tidy_xml($xml); # uncomment to get a nice view of the XML
    my $obj = xml_to_object($xml);
    print get_filetype($obj) . &quot;\n&quot;;
}

main();
</pre>

<p>
<!-- SECTION [30-59] --></p>
</div><a name="the_xml_reading"></a><h2 class='wiki'>The XML Reading</h2><div class="level2">

<p>
The next file is here I&#8217;ve abstracted all the functions that are reading values from the <acronym title="Extensible Markup Language">XML</acronym> object we created earlier. It&#8217;s basically the <acronym title="Extensible Markup Language">XML</acronym> reading part. I like the way <acronym title="Extensible Markup Language">XML</acronym>::MyXML allows the reading of values by path. That&#8217;s cool. The first two sub-routines return arrays and the rest returns a string.
</p>

<pre class="code">
#!/usr/bin/perl -w

use strict;
use XML::MyXML qw(tidy_xml xml_to_object);
use XML::MyXML qw(:all);

# returns an array with the destinations
sub get_destinations {
    my $obj = shift;
    my @destinations;

    foreach my $d ($obj-&amp;gt;path('Mandatory_Info/Destinations/Destination')) {
        push @destinations, $d-&amp;gt;value;
    }

    return @destinations;
}

# returns an array with the filenames
sub get_filenames {
    my $obj = shift;
    my @filenames;

    foreach my $d ($obj-&amp;gt;path('Mandatory_Info/File_Names/File')) {
        push @filenames, $d-&amp;gt;value;
    }

    return @filenames;
}
sub get_filetype {
    my $obj = shift;
    return $obj-&amp;gt;path('Mandatory_Info/File_Type')-&amp;gt;value;
}

sub get_monitor {
    my $obj = shift;
    return $obj-&amp;gt;path('Mandatory_Info/Monitor')-&amp;gt;value;
}

sub get_domain {
    my $obj = shift;
    return $obj-&amp;gt;path('Mandatory_Info/Domain')-&amp;gt;value;
}

sub get_source {
    my $obj = shift;
    return $obj-&amp;gt;path('Mandatory_Info/Source')-&amp;gt;value;
}

sub get_submissiontime {
    my $obj = shift;
    return $obj-&amp;gt;path('Mandatory_Info/Submission_Time')-&amp;gt;value;
}

sub get_filestatus {
    my $obj = shift;
    return $obj-&amp;gt;path('Optional_Info/File_Status')-&amp;gt;value;
}

# needed to use a require when including this file
return 1;
</pre>

<p>
<!-- SECTION [60-127] --></p>
</div><a name="test_code_and_data"></a><h2 class='wiki'>Test Code and Data</h2><div class="level2">

<p>
And following is the test code I wrote. Not a big deal but it makes easy to check if the functions are working correctly. I choosed to embed a test <acronym title="Extensible Markup Language">XML</acronym> in this file instead of reading it from a file.
</p>

<pre class="code">
#!/usr/bin/perl -w

use strict;
use XML::MyXML qw(tidy_xml xml_to_object);
use XML::MyXML qw(:all);

require &quot;readXML.pl&quot;;

my $xml = &quot;



    Param1
    domain
    tmp
    machine1

      machine1
      machine2


      /export/home/user/file1.tmp

    Thursday, 29 January 2009 08:45:05 GMT


  FLOWING


&quot;;

my $obj = xml_to_object($xml);
run_tests($obj);

# Test sub-routine to assert that we are reading the correct
# values from the XML. Use only with $test_xml.
sub run_tests {
    my $obj = shift;
    my @destinations = get_destinations($obj);

    assert ($destinations[0] ,  &quot;machine1&quot;, &quot;get_destinations&quot;);
    assert ($destinations[1] ,  &quot;machine2&quot;, &quot;get_destinations&quot;);

    my @file_names = get_filenames($obj);

    assert ($file_names[0] ,  &quot;/export/home/user/file1.tmp&quot;,
            &quot;get_filenames&quot;);

    my $filetype = get_filetype($obj);
    assert ($filetype ,  &quot;tmp&quot;, &quot;get_filetype&quot;);

    my $monitor = get_monitor($obj);
    assert ($monitor ,  &quot;Param1&quot;, &quot;get_monitor&quot;);

    my $domain = get_domain($obj);
    assert ($domain ,  &quot;domain&quot;, &quot;get_domain&quot;);

    my $source = get_source($obj);
    assert ($source ,  &quot;machine1&quot;, &quot;get_source&quot;);

    my $submission_time = get_submissiontime($obj);
    assert ($submission_time ,  &quot;Thursday, 29 January 2009 08:45:05 GMT&quot;,
            &quot;get_submissiontime&quot;);

    my $file_status = get_filestatus($obj);
    assert ($file_status ,  &quot;FLOWING&quot;, &quot;get_filestatus&quot;);
}

# Test if the first two arguments are the same string
# Used in run_tests from testing
sub assert {
    my $arg1 = shift;
    my $arg2 = shift;
    my $descr = shift;

    if ($arg1 eq $arg2) {
        print &quot;PASSED\n&quot;;
        return;
    }

    print $descr . &quot;\tFAILED!!!\n&quot;;
    return;
}
</pre>

<p>
Hope it helps someone. It will surely help me the next time I try to do it. My <acronym title="Practical Extraction and Report Language">Perl</acronym> skills were all rusty.
</p>


<!-- SECTION [128-] --></div>]]></description>
			<content:encoded><![CDATA[<p>
Today I had to do a <acronym title="Practical Extraction and Report Language">Perl</acronym> program to poke inside an <acronym title="Extensible Markup Language">XML</acronym> file and read out some values. I had a quick go with the CPAN module <acronym title="Extensible Markup Language">XML</acronym>::Simple but found it to be horrible. Yuck. I ended up using <acronym title="Extensible Markup Language">XML</acronym>::MyXML instead and I must say I&#8217;m much more impressed with it. I also wrote some test code just to be sure everything was ok and guarantee it doesn&#8217;t break if someone changes the <acronym title="Extensible Markup Language">XML</acronym>. Here is a quick roundup of what I did.
</p>
<p>
This was the <acronym title="Extensible Markup Language">XML</acronym> I had:
</p>

<pre class="code">



    Param1
    domain
    Filetype1
    machine1

      machine1
      machine2


      /export/home/user/file1.tmp

    Thursday, 29 January 2009 08:45:05 GMT


  FLOWING


</pre>

<p>
Only the attributes &#8220;Destinations&#8221; and &#8220;File_Names&#8221; are more complicated because they can contain multiple entries. Everything else is pretty straight forward, even using <acronym title="Extensible Markup Language">XML</acronym>::Simple.
</p>
<p>
<!-- SECTION [0-29] --></p>
<a name="the_main_program"></a><h2 class='wiki'>The Main Program</h2><div class="level2">

<p>
Here is the main file I did. It consists basically of opening the <acronym title="Extensible Markup Language">XML</acronym> file, reading it and calling one of the functions that reads one of the attributes of the <acronym title="Extensible Markup Language">XML</acronym>, in this case, get_filetype.
</p>

<pre class="code">
#!/usr/bin/perl -w

use strict;
use XML::MyXML qw(tidy_xml xml_to_object);
use XML::MyXML qw(:all);

require &quot;readXML.pl&quot;;

sub main() {
    my $file = &quot;test.xml&quot;;

    # this is needed because we read the whole file at once
    my $holdTerminator = $/;
    undef $/;

    open(FILE, &quot;&amp;lt;$file&amp;quot;) || die &amp;quot;Could not open file: $1&amp;quot;;
    my $xml = ;
    #print tidy_xml($xml); # uncomment to get a nice view of the XML
    my $obj = xml_to_object($xml);
    print get_filetype($obj) . &quot;\n&quot;;
}

main();
</pre>

<p>
<!-- SECTION [30-59] --></p>
</div><a name="the_xml_reading"></a><h2 class='wiki'>The XML Reading</h2><div class="level2">

<p>
The next file is here I&#8217;ve abstracted all the functions that are reading values from the <acronym title="Extensible Markup Language">XML</acronym> object we created earlier. It&#8217;s basically the <acronym title="Extensible Markup Language">XML</acronym> reading part. I like the way <acronym title="Extensible Markup Language">XML</acronym>::MyXML allows the reading of values by path. That&#8217;s cool. The first two sub-routines return arrays and the rest returns a string.
</p>

<pre class="code">
#!/usr/bin/perl -w

use strict;
use XML::MyXML qw(tidy_xml xml_to_object);
use XML::MyXML qw(:all);

# returns an array with the destinations
sub get_destinations {
    my $obj = shift;
    my @destinations;

    foreach my $d ($obj-&amp;gt;path('Mandatory_Info/Destinations/Destination')) {
        push @destinations, $d-&amp;gt;value;
    }

    return @destinations;
}

# returns an array with the filenames
sub get_filenames {
    my $obj = shift;
    my @filenames;

    foreach my $d ($obj-&amp;gt;path('Mandatory_Info/File_Names/File')) {
        push @filenames, $d-&amp;gt;value;
    }

    return @filenames;
}
sub get_filetype {
    my $obj = shift;
    return $obj-&amp;gt;path('Mandatory_Info/File_Type')-&amp;gt;value;
}

sub get_monitor {
    my $obj = shift;
    return $obj-&amp;gt;path('Mandatory_Info/Monitor')-&amp;gt;value;
}

sub get_domain {
    my $obj = shift;
    return $obj-&amp;gt;path('Mandatory_Info/Domain')-&amp;gt;value;
}

sub get_source {
    my $obj = shift;
    return $obj-&amp;gt;path('Mandatory_Info/Source')-&amp;gt;value;
}

sub get_submissiontime {
    my $obj = shift;
    return $obj-&amp;gt;path('Mandatory_Info/Submission_Time')-&amp;gt;value;
}

sub get_filestatus {
    my $obj = shift;
    return $obj-&amp;gt;path('Optional_Info/File_Status')-&amp;gt;value;
}

# needed to use a require when including this file
return 1;
</pre>

<p>
<!-- SECTION [60-127] --></p>
</div><a name="test_code_and_data"></a><h2 class='wiki'>Test Code and Data</h2><div class="level2">

<p>
And following is the test code I wrote. Not a big deal but it makes easy to check if the functions are working correctly. I choosed to embed a test <acronym title="Extensible Markup Language">XML</acronym> in this file instead of reading it from a file.
</p>

<pre class="code">
#!/usr/bin/perl -w

use strict;
use XML::MyXML qw(tidy_xml xml_to_object);
use XML::MyXML qw(:all);

require &quot;readXML.pl&quot;;

my $xml = &quot;



    Param1
    domain
    tmp
    machine1

      machine1
      machine2


      /export/home/user/file1.tmp

    Thursday, 29 January 2009 08:45:05 GMT


  FLOWING


&quot;;

my $obj = xml_to_object($xml);
run_tests($obj);

# Test sub-routine to assert that we are reading the correct
# values from the XML. Use only with $test_xml.
sub run_tests {
    my $obj = shift;
    my @destinations = get_destinations($obj);

    assert ($destinations[0] ,  &quot;machine1&quot;, &quot;get_destinations&quot;);
    assert ($destinations[1] ,  &quot;machine2&quot;, &quot;get_destinations&quot;);

    my @file_names = get_filenames($obj);

    assert ($file_names[0] ,  &quot;/export/home/user/file1.tmp&quot;,
            &quot;get_filenames&quot;);

    my $filetype = get_filetype($obj);
    assert ($filetype ,  &quot;tmp&quot;, &quot;get_filetype&quot;);

    my $monitor = get_monitor($obj);
    assert ($monitor ,  &quot;Param1&quot;, &quot;get_monitor&quot;);

    my $domain = get_domain($obj);
    assert ($domain ,  &quot;domain&quot;, &quot;get_domain&quot;);

    my $source = get_source($obj);
    assert ($source ,  &quot;machine1&quot;, &quot;get_source&quot;);

    my $submission_time = get_submissiontime($obj);
    assert ($submission_time ,  &quot;Thursday, 29 January 2009 08:45:05 GMT&quot;,
            &quot;get_submissiontime&quot;);

    my $file_status = get_filestatus($obj);
    assert ($file_status ,  &quot;FLOWING&quot;, &quot;get_filestatus&quot;);
}

# Test if the first two arguments are the same string
# Used in run_tests from testing
sub assert {
    my $arg1 = shift;
    my $arg2 = shift;
    my $descr = shift;

    if ($arg1 eq $arg2) {
        print &quot;PASSED\n&quot;;
        return;
    }

    print $descr . &quot;\tFAILED!!!\n&quot;;
    return;
}
</pre>

<p>
Hope it helps someone. It will surely help me the next time I try to do it. My <acronym title="Practical Extraction and Report Language">Perl</acronym> skills were all rusty.
</p>


<!-- SECTION [128-] --></div>]]></content:encoded>
			<wfw:commentRss>http://www.morgadinho.org/2009/01/29/perl-reading-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
