<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Ivan Bessarabov</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/ivan_bessarabov/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/ivan_bessarabov/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/ivan_bessarabov//1099</id>
    <updated>2013-02-11T16:45:14Z</updated>
    <subtitle>A blog about the Perl programming language</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>Test::Whitespaces</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/ivan_bessarabov/2013/02/test-whitespaces.html" />
    <id>tag:blogs.perl.org,2013:/users/ivan_bessarabov//1099.4313</id>

    <published>2013-02-11T15:36:35Z</published>
    <updated>2013-02-11T16:45:14Z</updated>

    <summary>Perl is very flexible in may ways including whitespaces. Perl does not force you to use tab or spaces. The script works fine no matter if it has DOS or UNIX line breaks. But there are some good practices. I...</summary>
    <author>
        <name>Ivan Bessarabov</name>
        <uri>http://ivan.bessarabov.ru</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/ivan_bessarabov/">
        <![CDATA[<p>Perl is very flexible in may ways including whitespaces. Perl does not force you to use tab or spaces. The script works fine no matter if it has DOS or UNIX line breaks.</p>

<p>But there are some good practices. I preffer these rules:</p>

<ul>
<li>every line ends with "\n" (including the last line)</li>
<li>UNIX way for new lines (only "\n", not "\r\n")</li>
<li>no tabs, but 4 spaces instead</li>
<li>no trailing spaces</li>
<li>no empty lines in the end of the file</li>
</ul>

<p>I want to make sure that all that rules are followed in my source code. So I've written <a href="https://metacpan.org/module/Test::Whitespaces">Test::Whitespaces</a>. There are several good things in this module.</p>

<p>You can create test file xt/whitespaces.t:</p>

<pre><code>use Test::Whitespaces {
    dirs =&gt; [ 'lib', 'bin', 't' ],
};
</code></pre>

<p>It will check all the files in these directories for errors in whitespaces. And it will output the errors in a very friendly manner.</p>

<p>Instead of writing test file you can use script <code>test_whitespaces</code> that will show the problems. Here is the sample output. It is perfect, isn't it? =)</p>

<p><img src="http://blogs.perl.org/users/ivan_bessarabov/test_whitespaces_output.png" alt="test_whitespaces output" /></p>

<p>In case you have found some errors there is a simple way to fix them. There is a script <code>whiter</code> that can fix all the errors in the project files.</p>

<p>I'm using this module to check and fix whitespaces not only in Perl source code, but also in test files and in templates and css/js.</p>

<p>I've written this module with the main idea to simplify the developers work.  It has good documentation and it is as simple as possible.</p>

<p>I really hope that this module can be helpful for the Perl developers. And I would be happy in you express you opinion about this module. =)</p>

<p>PS And I want to thank <a href="http://play-perl.org/quest/511908799144521953000049">play-perl.org</a> for endorsing my work.</p>]]>
        
    </content>
</entry>

<entry>
    <title>$#boo</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/ivan_bessarabov/2011/11/boo.html" />
    <id>tag:blogs.perl.org,2011:/users/ivan_bessarabov//1099.2459</id>

    <published>2011-11-18T11:53:56Z</published>
    <updated>2011-11-18T11:58:19Z</updated>

    <summary>As we all know $#boo returns the last index of array @boo. It is clear why we have the prefixes &apos;$&apos; and &apos;@&apos; (&apos;$&apos; is like the first letter of the word &apos;scalar&apos; and the &apos;@&apos; is like the first...</summary>
    <author>
        <name>Ivan Bessarabov</name>
        <uri>http://ivan.bessarabov.ru</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/ivan_bessarabov/">
        <![CDATA[<p>As we all know $#boo returns the last index of array @boo.</p>

<p>It is clear why we have the prefixes '$' and '@' ('$' is like the first<br />
letter of the word 'scalar' and the '@' is like the first letter of the word<br />
'array').</p>

<p>But is it unclear why there is '#' after the dollar sign. I've checked out <br />
the perl v 1.0 and in the man page there is such text:</p>

<p>> you may find the length of array @days by evaluating "$#days", as in csh.<br />
> [Actually, it's not the length of the array, it's the subscript of the last<br />
> element, since there is (ordinarily) a 0th element.]</p>

<p>So the answer why the number of the last index is $#boo is somewhere is csh.<br />
</p>]]>
        
    </content>
</entry>

</feed>
