<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>CogFault</title>
	
	<link>http://eddiema.ca/cogfault</link>
	<description>coming to a brain near you.</description>
	<lastBuildDate>Sat, 06 Apr 2013 11:52:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Cogfault" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="cogfault" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Printing values from Theano (Python)</title>
		<link>http://eddiema.ca/cogfault/2012/02/15/printing-values-from-theano-python/</link>
		<comments>http://eddiema.ca/cogfault/2012/02/15/printing-values-from-theano-python/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 23:16:32 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[deeplearning.net]]></category>
		<category><![CDATA[Numpy]]></category>
		<category><![CDATA[Printing]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tensor]]></category>
		<category><![CDATA[Theano]]></category>

		<guid isPermaLink="false">http://eddiema.ca/cogfault/?p=230</guid>
		<description><![CDATA[Here&#8217;s how to look inside Theano tensors &#8212; I start with a wrong way (dir()) and end with the correct way ([row for row in theano.function([], data)]). Theano is this really pretty package for Python &#8212; it operates on top of Numpy to provide short hand and functionality useful for machine learning algorithms. I bumped into [...]]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s how to look inside Theano tensors &#8212; I start with a wrong way (<em>dir()</em>) and end with the correct way (<em>[row for row in theano.function([], data)]</em>).</p>
<p><a href="http://deeplearning.net/software/theano/">Theano</a> is this really pretty package for <a href="http://python.org/">Python</a> &#8212; it operates on top of <a href="http://www.scipy.org/">Numpy</a> to provide short hand and functionality useful for machine learning algorithms. I bumped into this when I was running some demo code available at <a href="http://deeplearning.net/">deeplearning.net</a>. The demo data used by this code is actually a Python Pickled +Gzipped version of the <a href="http://yann.lecun.com/exdb/mnist/">MNIST handwritten digit database</a>. In this scenario, all I wanted to do was print the MNIST data after it had been already been loaded by Theano into the demo script. The data is accessible via instances of the <strong><a href="http://deeplearning.net/software/theano/library/tensor/basic.html">theano.TensorVariable</a></strong> class.</p>
<p>The first attempt worked for the rows of data corresponding to the images stored as 2D arrays since Theano tensors of type matrix have a convenience method that lets one grab the data as a familiar 2D Numpy array using an undocumented <strong>get_value()</strong> method (it doesn&#8217;t appear in the API for <strong>theano.TensorVariable</strong>, but is mentioned briefly elsewhere). This convenience method disappears for the 1D arrays, since these were not constructed with a shared reference to an underlying Numpy array.</p>
<p>After spending a solid amount of time working away with Python&#8217;s <strong>dir()</strong>, searching for a way to coerce Theano into showing me its innards, I finally came to my senses and realized I should probably see what canonical solutions are. Completely new to Theano, and only having recently read about them &#8212; I simply wasn&#8217;t well versed enough with the notion of compiling a Theano function. Finally, peering into the loaded MNIST data came down to this &#8230;</p>
<pre class="brush: python; title: ; notranslate">
datasets = load_data(dataset)

train_set_x, train_set_y = datasets[0]
valid_set_x, valid_set_y = datasets[1]
test_set_x , test_set_y  = datasets[2]

##### -- my code begins here ...

def print_set(data, name):
    with open(&amp;quot;extract/&amp;quot; + name + &amp;quot;.txt&amp;quot;, &amp;quot;w+&amp;quot;) as handle:
        print &amp;gt;&amp;gt;handle, &amp;quot;# type(python)&amp;quot;, type(data)
        print &amp;gt;&amp;gt;handle, &amp;quot;# type(theano)&amp;quot;, data.type
        print &amp;gt;&amp;gt;handle, &amp;quot;# dimensions  &amp;quot;, data.ndim
        if data.ndim == 2:
            print &amp;gt;&amp;gt;handle, &amp;quot;# rows(numpy) &amp;quot;, len(data.get_value())
            print &amp;gt;&amp;gt;handle, &amp;quot;# cols(numpy) &amp;quot;, len(data.get_value()[0])
            for row in theano.function([], data)():
                for val in row:
                    print &amp;gt;&amp;gt;handle, &amp;quot;%0.3f&amp;quot; % val,
                print &amp;gt;&amp;gt;handle
        elif data.ndim == 1:
            for row in theano.function([], data)():
                print &amp;gt;&amp;gt;handle, &amp;quot;%d&amp;quot; % row
        else:
            return

print_set(train_set_x, &amp;quot;train_set_x&amp;quot;)
print_set(train_set_y, &amp;quot;train_set_y&amp;quot;)
print_set(valid_set_x, &amp;quot;valid_set_x&amp;quot;)
print_set(valid_set_y, &amp;quot;valid_set_y&amp;quot;)
print_set(test_set_x,  &amp;quot;test_set_x&amp;quot; )
print_set(test_set_y,  &amp;quot;test_set_y&amp;quot; )

return
</pre>
<p>Here, the magic is in the constructor <strong><a href="http://deeplearning.net/software/theano/library/compile/function.html">theano.function([], data)</a></strong> (&#8211; Thanks: <a href="http://groups.google.com/group/theano-users/browse_thread/thread/020b62d408185230?pli=1">Olivier Delalleau</a>) The great thing about working through this problem is that I should be able to extend this solution to building <em>actual</em> functions in Theano. The stumbling around did force me to understand more about Theano&#8217;s tensors and Theano&#8217;s compiled function graphs.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/cogfault/2012/02/15/printing-values-from-theano-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ternary vs relational precedence (C)</title>
		<link>http://eddiema.ca/cogfault/2011/12/22/ternary-vs-relational-precedence-c/</link>
		<comments>http://eddiema.ca/cogfault/2011/12/22/ternary-vs-relational-precedence-c/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 06:22:58 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Operator Precedence]]></category>
		<category><![CDATA[Relational Operators]]></category>
		<category><![CDATA[Ternary Conditional Operator]]></category>

		<guid isPermaLink="false">http://eddiema.ca/cogfault/?p=149</guid>
		<description><![CDATA[I thought that the relational operators had the lowest precedence &#8211; the ternary conditional operator actually has a lower precedence*. Updated thanks to Wyatt and Devon in the comments. The assignment below &#8230; Will assign A to D if B is C and A to E if B is not C. This is equal to saying [...]]]></description>
				<content:encoded><![CDATA[<p>I thought that the relational operators had the lowest precedence &#8211; the ternary conditional operator actually has a lower precedence*.</p>
<p><em>Updated thanks to Wyatt and Devon in the comments.</em></p>
<p>The assignment below &#8230;</p>
<pre class="brush: cpp; title: ; notranslate">
int A = B == C ? D : E;
</pre>
<p>Will assign A to D if B is C and A to E if B is not C. This is equal to saying &#8230;</p>
<pre class="brush: cpp; title: ; notranslate">
int A = (B == C) ? D : E; // Correct
</pre>
<p>An incorrect interpretation is &#8230;</p>
<pre class="brush: cpp; title: ; notranslate">
int A = B == (C ? D : E); // Incorrect
</pre>
<p>Thanks to Wyatt for checking this and pointing it out in the comments &#8212; I had a typo in my original code which lead to an incorrect interpretation. Fittingly of a CogFault, the intro is still true (ternary has lower precedence). This post has been updated to reflect these changes.</p>
<p>Either way, as Devon points out in the comments &#8212; when the expression &#8220;B == C&#8221; gets even slightly more complicated, like &#8220;B == C-1&#8243;, then it&#8217;s better to use parentheses.</p>
<p>So, thanks everyone for making this CogFault better.</p>
<p>*Note that the middle expression between &#8220;?&#8221; and &#8220;:&#8221; of the ternary conditional operator is always evaluated first.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/cogfault/2011/12/22/ternary-vs-relational-precedence-c/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Restore default man pages in manpath</title>
		<link>http://eddiema.ca/cogfault/2011/11/15/deleted-default-manpath-from-bash_profile/</link>
		<comments>http://eddiema.ca/cogfault/2011/11/15/deleted-default-manpath-from-bash_profile/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 14:50:34 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[accidentally removed]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[man pages]]></category>
		<category><![CDATA[restore]]></category>
		<category><![CDATA[Snow Leopard]]></category>

		<guid isPermaLink="false">http://eddiema.ca/cogfault/?p=184</guid>
		<description><![CDATA[Accidentally removed manpath for default man pages (manual pages) in Mac OS X. Solution: add this line to .bash_profile &#8230; export MANPATH=/usr/share/man:$MANPATH &#8230; as /usr/share/man is the default location of the system man pages.]]></description>
				<content:encoded><![CDATA[<p>Accidentally removed manpath for default man pages (manual pages) in Mac OS X.</p>
<p>Solution: add this line to .bash_profile &#8230;</p>
<pre>export MANPATH=/usr/share/man:$MANPATH</pre>
<p>&#8230; as /usr/share/man is the default location of the system man pages.</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/cogfault/2011/11/15/deleted-default-manpath-from-bash_profile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Progress bar hang (Java thread sync)</title>
		<link>http://eddiema.ca/cogfault/2011/07/04/progress-bar-hang-java-thread-sync/</link>
		<comments>http://eddiema.ca/cogfault/2011/07/04/progress-bar-hang-java-thread-sync/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 20:20:07 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Progress Bar]]></category>
		<category><![CDATA[Synchronized]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://eddiema.ca/cogfault/?p=135</guid>
		<description><![CDATA[Multithreaded Java code can hang indefinitely while waiting on the current state of a progress bar if incorrectly coded in this example (threading care of one of ExecutorServices&#8217; thread pool methods &#8212; progress bar care of swing). Example &#8212; several functions execute a statement similar to the update line below. Summary: Enclose the updating in a [...]]]></description>
				<content:encoded><![CDATA[<p>Multithreaded Java code can hang indefinitely while waiting on the current state of a progress bar if incorrectly coded in this example (threading care of one of ExecutorServices&#8217; thread pool methods &#8212; progress bar care of swing).</p>
<p>Example &#8212; several functions execute a statement similar to the update line below.</p>
<pre class="brush: java; title: ; notranslate">
static final int PRG = 100; // total progress that each thread contributes
static final int TOTAL_PRG = 1000; // total progress for all ten threads
static int progress = 0;

public double calculateSomething(double[] inputs) {
    double output = 0;
    int prev = 0;
    for(int iter = 0; iter &lt; maximum; iter ++) {
        int diff = PRG * iter / maximum % PRG - prev;
        if(diff &gt; 0) {
            progress += diff; // !!! update the progress bar integer !!!
            prev += diff;
        }
        // . . . math or function logic goes here --
        // calculate something with inputs, save in output . . .
    progress += PRG - prev; // finishes this bar
    return output;
}
</pre>
<p>Summary: Enclose the updating in a synchronized function as below.</p>
<pre class="brush: java; title: ; notranslate">
protected synchronized void updateProgress(int amount) {
    progress += amount;
}

// ... OR -- make a thread safe mutator / accessor combo ...
// -- giving this function 0 will make it behave like a get.

protected synchronized int updateProgress(int amount) {
    progress += amount;
    return progress;
}

public double calculateSomething(double[] inputs) {
    double output = 0;
    int prev = 0;
    for(int iter = 0; iter &lt; maximum; iter ++) {
        int diff = PRG * iter / maximum % PRG - prev;
        if(diff &gt; 0) {
            updateProgress(diff); // update the progress bar integer (fixed)
            prev += diff;
        }
        // . . . math or function logic goes here --
        // calculate something with inputs, save in output . . .
    updateProgress(PRG - prev); // finishes this bar (fixed)
    return output;
}
</pre>
<p>Lesson: Always be thread safe &#8212; even on operations that look like they should be atomic (such as addition above).</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/cogfault/2011/07/04/progress-bar-hang-java-thread-sync/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binary path confusion (OSX)</title>
		<link>http://eddiema.ca/cogfault/2011/05/26/gnu-binaries-co-osx-fink-macports/</link>
		<comments>http://eddiema.ca/cogfault/2011/05/26/gnu-binaries-co-osx-fink-macports/#comments</comments>
		<pubDate>Thu, 26 May 2011 13:39:43 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[CogFault]]></category>
		<category><![CDATA[*NIX]]></category>
		<category><![CDATA[binaries]]></category>
		<category><![CDATA[GNU]]></category>
		<category><![CDATA[versions]]></category>

		<guid isPermaLink="false">http://eddiema.ca/cogfault/?p=111</guid>
		<description><![CDATA[I couldn&#8217;t figure out why my OSX 10.6.6 had tar 1.14 instead of a newer version. Symptoms: Trying to archive 175MB of data over 7680 files resulted in this &#8230; Delving into this, the last reports of this issue that Google could dig up was all the way back in 2005 &#8212; that fits with [...]]]></description>
				<content:encoded><![CDATA[<p>I couldn&#8217;t figure out why my OSX 10.6.6 had tar 1.14 instead of a newer version.</p>
<p>Symptoms: Trying to archive 175MB of data over 7680 files resulted in this &#8230;</p>
<pre class="brush: xml; title: ; notranslate">
$ tar -cvzf exp_tin.tgz exp_tin
tar: exp_tin: Cannot savedir: Cannot allocate memory
tar: Error exit delayed from previous errors
Tin:CIS6650_Chicago eddiema$
</pre>
<p>Delving into this, the last reports of this issue that Google could dig up was all the way back in 2005 &#8212; that fits with this information &#8230;</p>
<pre class="brush: xml; title: ; notranslate">
$ tar --version
tar (GNU tar) 1.14
Copyright (C) 2004 Free Software Foundation, Inc.
This program comes with NO WARRANTY, to the extent permitted by law.
You may redistribute it under the terms of the GNU General Public License;
see the file named COPYING for details.
Written by John Gilmore and Jay Fenlason.
</pre>
<p>None of my other machines had this problem &#8211;</p>
<p>Finally, I did this &#8230;</p>
<pre class="brush: xml; title: ; notranslate">
$ which tar
/sw/bin/tar
</pre>
<p>Which made me realize that this version of tar came from an old fink update.</p>
<p>Solution: I moved /sw/bin/tar to /sw/bin/tar114 and the default version of tar given by OSX became the default &#8230;</p>
<pre class="brush: xml; title: ; notranslate">
$ tar --version
bsdtar 2.6.2 - libarchive 2.6.2
</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/cogfault/2011/05/26/gnu-binaries-co-osx-fink-macports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Namespace, directory confusion</title>
		<link>http://eddiema.ca/cogfault/2011/04/09/namespace-and-directory-structure-confusion/</link>
		<comments>http://eddiema.ca/cogfault/2011/04/09/namespace-and-directory-structure-confusion/#comments</comments>
		<pubDate>Sat, 09 Apr 2011 15:44:18 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[gmcs]]></category>
		<category><![CDATA[Main function]]></category>
		<category><![CDATA[makefile]]></category>
		<category><![CDATA[mono]]></category>

		<guid isPermaLink="false">http://eddiema.ca/cogfault/?p=88</guid>
		<description><![CDATA[Couldn&#8217;t figure out why gmcs (mono C# compiler) wasn&#8217;t able to find HMOther as the container of the Main() function I wanted Example: incorrect &#8230; correct &#8230; This took a while to track down since I kept looking at the directory structure rather than the namespaces! &#160;]]></description>
				<content:encoded><![CDATA[<p>Couldn&#8217;t figure out why gmcs (mono C# compiler) wasn&#8217;t able to find HMOther as the container of the Main() function I wanted</p>
<p>Example:</p>
<p>incorrect &#8230;</p>
<pre class="brush: xml; title: ; notranslate">
heat2.exe: heatmap/OtherHeat.cs heatmap/heatmap.cs
    gmcs -r:System.drawing -out:$@ $+ -main:$&lt;/HMOther
</pre>
<p>correct &#8230;</p>
<pre class="brush: xml; title: ; notranslate">
heat2.exe: heatmap/OtherHeat.cs heatmap/heatmap.cs
    gmcs -r:System.drawing -out:$@ $+ -main:heatmap.HMOther
</pre>
<p>This took a while to track down since I kept looking at the directory structure rather than the namespaces!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/cogfault/2011/04/09/namespace-and-directory-structure-confusion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LaTeX Multirow Extra Newline</title>
		<link>http://eddiema.ca/cogfault/2011/04/04/latex-multirow-extra-newline/</link>
		<comments>http://eddiema.ca/cogfault/2011/04/04/latex-multirow-extra-newline/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 09:22:31 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Markup]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[multirow]]></category>
		<category><![CDATA[newline]]></category>
		<category><![CDATA[rowbreak]]></category>
		<category><![CDATA[tables]]></category>

		<guid isPermaLink="false">http://eddiema.ca/cogfault/?p=15</guid>
		<description><![CDATA[This vertical misalignment took a while to track down. It turns out it was an added newline (rowbreak) immediately after a sideways multirow entry in a LaTeX table. Which results in this ugliness &#8230; The outermost item in that cell is not the sideways environment, rather it is the multirow &#8212; i.e. count the number [...]]]></description>
				<content:encoded><![CDATA[<p>This vertical misalignment took a while to track down.</p>
<p>It turns out it was an added newline (rowbreak) immediately after a sideways multirow entry in a LaTeX table.</p>
<pre class="brush: latex; title: ; notranslate">
\begin{table}[h!tp]
\caption{\label{table:irisgamma1}
The allowed values of $\Gamma_1$ in the Iris Dataset cluster task given
$N, \alpha_0$.
}
\centering
\begin{tabular}{c | c | c c c c c c}
$\Gamma_1$ &amp; \multicolumn{7}{c}{Epochs $N$} \\ \hline
\multirow{6}{*}
{
\begin{sideways}
Learning $\alpha_0$
\end{sideways}
} \\ % &lt;-- EXTRA NEWLINE HERE
 &amp;   &amp; 1 &amp; 10 &amp; 50 &amp; 100 &amp; 500 &amp; 1000\\
 \cline{2-8}
 &amp; 0.01 &amp; b &amp; c &amp; d &amp; e &amp; f &amp; g\\
 &amp; 0.05 &amp; b &amp; c &amp; d &amp; e &amp; f &amp; g\\
 &amp; 0.1 &amp; b &amp; c &amp; d &amp; e &amp; f &amp; g\\
 &amp; 0.5 &amp; b &amp; c &amp; d &amp; e &amp; f &amp; g\\
 &amp; 1.0 &amp; b &amp; c &amp; d &amp; e &amp; f &amp; g\\
\end{tabular}
\end{table}
</pre>
<p>Which results in this ugliness &#8230;</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-34" title="badness" src="http://eddiema.ca/cogfault/wp-content/uploads/2011/04/badness.png" alt="" width="590" height="208" /></p>
<p>The outermost item in that cell is not the sideways environment, rather it is the multirow &#8212; i.e. count the number of columns before adding a linebreak.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-33" title="goodness" src="http://eddiema.ca/cogfault/wp-content/uploads/2011/04/goodness.png" alt="" width="587" height="188" /></p>
<p>The above example with the rowbreak removed (correct).</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/cogfault/2011/04/04/latex-multirow-extra-newline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PERL goto label syntax (parse error)</title>
		<link>http://eddiema.ca/cogfault/2011/04/03/perl-goto-label-syntax-parse-error/</link>
		<comments>http://eddiema.ca/cogfault/2011/04/03/perl-goto-label-syntax-parse-error/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 10:50:48 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[goto]]></category>
		<category><![CDATA[PERL]]></category>
		<category><![CDATA[sub]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://eddiema.ca/cogfault/?p=29</guid>
		<description><![CDATA[The below construction leads to a syntax error &#8230; Reason: PERL will not accept the subroutine declaration immediately after a goto label. Solution: Add an empty statement at the goto label &#8230; Note &#8212; error messages will generally be ambiguous as in &#8230;]]></description>
				<content:encoded><![CDATA[<p>The below construction leads to a syntax error &#8230;</p>
<pre class="brush: perl; title: ; notranslate">
goto STEP6;
# Some code happens here that we don't want to run ...
STEP6:

sub do_the {
}
</pre>
<p>Reason: PERL will not accept the subroutine declaration immediately after a goto label.</p>
<p>Solution: Add an empty statement at the goto label &#8230;</p>
<pre class="brush: perl; title: ; notranslate">
STEP6:; #BAM! Empty statement.

sub do_the {
}
</pre>
<p>Note &#8212; error messages will generally be ambiguous as in &#8230;</p>
<pre class="brush: perl; title: ; notranslate">
syntax error at make.pl line 279, near &quot;sub do_the &quot;
Execution of make.pl aborted due to compilation errors.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/cogfault/2011/04/03/perl-goto-label-syntax-parse-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PERL regex flags matter</title>
		<link>http://eddiema.ca/cogfault/2011/04/01/perl-regex-flags-matter/</link>
		<comments>http://eddiema.ca/cogfault/2011/04/01/perl-regex-flags-matter/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 19:26:44 +0000</pubDate>
		<dc:creator>Eddie Ma</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PERL]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://eddiema.ca/cogfault/?p=23</guid>
		<description><![CDATA[I wanted to make a simple scrubber that would replace all non-ascii high-value characters with an ascii hyphen (&#8216;-&#8217;). This was the PERL script I used &#8230; Which only picked up the first non-ascii character per line &#8212; this is the correct script &#8230; Regular expressions do greedy matching for the Kleene Star (&#8216;*&#8217;) and [...]]]></description>
				<content:encoded><![CDATA[<p>I wanted to make a simple scrubber that would replace all non-ascii high-value characters with an ascii hyphen (&#8216;-&#8217;).</p>
<p>This was the PERL script I used &#8230;</p>
<pre class="brush: perl; title: ; notranslate">
while(&lt;&gt;) {
    $_ =~ s/[^[:ascii:]]+/-/;
    print $_;
}
</pre>
<p>Which only picked up the first non-ascii character per line &#8212; this is the correct script &#8230;</p>
<pre class="brush: perl; title: ; notranslate">
while(&lt;&gt;) {
    $_ =~ s/[^[:ascii:]]+/-/g; #BAM! 'g' flag!
    print $_;
}
</pre>
<p>Regular expressions do greedy matching for the Kleene Star (&#8216;*&#8217;) and Kleene Plus (&#8216;+&#8217;) operators; use the question mark (&#8216;?&#8217;) to denote that we want the shortest match possible instead where appropriate.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://eddiema.ca/cogfault/2011/04/01/perl-regex-flags-matter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
