<?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>Nano&#039;s Blog &#187; practice</title>
	<atom:link href="http://www.nanohe.net/blog/tag/practice/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nanohe.net/blog</link>
	<description>Hello World!</description>
	<lastBuildDate>Tue, 20 Jul 2010 09:47:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to assign String to list when use strict enabled?</title>
		<link>http://www.nanohe.net/blog/2010/01/how-to-assign-string-to-list-when-use-strict-enabled/</link>
		<comments>http://www.nanohe.net/blog/2010/01/how-to-assign-string-to-list-when-use-strict-enabled/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 13:26:42 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[practice]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/?p=244</guid>
		<description><![CDATA[Don&#8217;t use &#8220;my&#8221; again and again to declare $rock[0], $rock[1] etc. Declare the array once (@rocks) once and use it.
you need to declare my @rocks and then not use my any more when referring to $rocks[xxx].
If you don&#8217;t know how many elements are going to be in there, you can use push to add new [...]]]></description>
			<content:encoded><![CDATA[<p>Don&#8217;t use &#8220;<strong>my</strong>&#8221; again and again to declare $rock[0], $rock[1] etc. Declare the array once (<strong>@rocks</strong>) once and use it.</p>
<p>you need to declare <strong>my @rocks </strong>and then not use <strong>my</strong> any more when referring to <strong>$rocks[xxx]</strong>.<br />
If you don&#8217;t know how many elements are going to be in there, you can use <strong>push</strong> to add new elements into the (initially 0-sized) array.</p>
<p><em>- from StackOverflow.com</em></p>
<pre class="brush: perl;">
#!C:\Perl\bin\perl.exe
# activePerl 5.8 based
use strict; # enabled
use warnings; 

my @rocks; 

($rocks[0], $rocks[1]) = qw/Hello World/;  

$rocks[2] = 'Tom';
$rocks[3] = 'Cat'; 

print $rocks[0];
print $rocks[1];
print $rocks[2];
print $rocks[3];
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/01/how-to-assign-string-to-list-when-use-strict-enabled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to print a complex dictionary with StringBuilder?</title>
		<link>http://www.nanohe.net/blog/2010/01/how-to-print-a-complex-dictionary-with-stringbuilder/</link>
		<comments>http://www.nanohe.net/blog/2010/01/how-to-print-a-complex-dictionary-with-stringbuilder/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 10:14:21 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[cs]]></category>
		<category><![CDATA[practice]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/?p=146</guid>
		<description><![CDATA[Purpose
Create a complex dictionary
Print the dictionary with StringBuilder
Scope
C#, Dictionary, StringBuilder
Limitations
The sample dictionary was fixed. The code can&#8217;t handle the dynamical dictionary.
Note
1. 

// watch out for NullReferenceException
            if (!ReferenceEquals(null, mainDict[pair1.Key]) &#38;&#38; (mainDict[pair1.Key] is string))

2. 

// IDictionary is not the one from the Generics namespace, it [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Purpose</strong></p>
<p>Create a complex dictionary<br />
Print the dictionary with StringBuilder</p>
<p><strong>Scope</strong></p>
<p>C#, Dictionary, StringBuilder</p>
<p><strong>Limitations</strong></p>
<p>The sample dictionary was fixed. The code can&#8217;t handle the dynamical dictionary.</p>
<p><strong>Note</strong><br />
1. </p>
<pre class="brush: csharp;">
// watch out for NullReferenceException
            if (!ReferenceEquals(null, mainDict[pair1.Key]) &amp;&amp; (mainDict[pair1.Key] is string))
</pre>
<p>2. </p>
<pre class="brush: csharp;">
// IDictionary is not the one from the Generics namespace, it is the one from the System.Collections namespace
using System.Collections;
</pre>
<p><strong>Code Sample</strong></p>
<pre class="brush: csharp;">
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class test
{
    private static Dictionary&lt;string, object&gt; mainDict = new Dictionary&lt;string, object&gt;();

    public static void Main()
    {
        Dictionary&lt;string, object&gt; aSubDict = new Dictionary&lt;string,object&gt;();
        Dictionary&lt;string, object&gt; aSub1Dict = new Dictionary&lt;string, object&gt;();
        Dictionary&lt;string, object&gt; aSub2Dict = new Dictionary&lt;string, object&gt;();
        Dictionary&lt;string, object&gt; aSub3Dict = new Dictionary&lt;string, object&gt;();
        Dictionary&lt;string, object&gt; aSub4Dict = new Dictionary&lt;string, object&gt;();

        mainDict.Add(&quot;ADKey&quot;, aSubDict);
        mainDict.Add(&quot;ASKey&quot;, &quot;AValue&quot;);
        aSubDict.Add(&quot;BDKey&quot;, aSub1Dict);
        aSubDict.Add(&quot;BSKey&quot;, &quot;BValue&quot;);
        aSub1Dict.Add(&quot;CDKey&quot;, aSub2Dict);
        aSub1Dict.Add(&quot;CSKey&quot;, &quot;CValue&quot;);
        aSub2Dict.Add(&quot;DDKey&quot;,aSub3Dict);
        aSub2Dict.Add(&quot;DSKey&quot;, &quot;DValue&quot;);
        aSub3Dict.Add(&quot;EDKey&quot;, aSub4Dict);
        aSub3Dict.Add(&quot;ESKey&quot;, &quot;EValue&quot;);
        aSub4Dict.Add(&quot;FKey&quot;, &quot;FValue&quot;);

        StringBuilder sb;

        foreach (KeyValuePair&lt;string, object&gt; pair1 in mainDict)
            // watch out for NullReferenceException
            if (!ReferenceEquals(null, mainDict[pair1.Key]) &amp;&amp; (mainDict[pair1.Key] is string))
            {
                Console.WriteLine(&quot;Key = {0}, Value = {1}&quot;, pair1.Key, pair1.Value);
                sb = new StringBuilder();
                sb.AppendFormat(&quot;{0}, {1}&quot;, pair1.Key, pair1.Value);
                Console.WriteLine(sb.ToString());
            }
            // IDictionary is not the one from the Generics namespace, it is the one from the System.Collections namespace
            else if (!ReferenceEquals(null, mainDict[pair1.Key]) &amp;&amp; (mainDict[pair1.Key] is Dictionary&lt;string, object&gt;))
            {
                foreach (KeyValuePair&lt;string, object&gt; pair2 in (Dictionary&lt;string, object&gt;)pair1.Value)
                    if (!ReferenceEquals(null, ((Dictionary&lt;string, object&gt;)pair1.Value)[pair2.Key]) &amp;&amp; (((Dictionary&lt;string, object&gt;)pair1.Value)[pair2.Key] is string))
                    {
                        Console.WriteLine(&quot;SubKey = {0}, Value = {1}&quot;, pair2.Key, pair2.Value);
                        sb = new StringBuilder();
                        sb.AppendFormat(&quot;{0}/{1}, {2}&quot;, pair1.Key, pair2.Key, pair2.Value);
                        Console.WriteLine(sb.ToString());
                    }
                    else if (!ReferenceEquals(null, ((Dictionary&lt;string, object&gt;)pair1.Value)[pair2.Key]) &amp;&amp; (((Dictionary&lt;string, object&gt;)pair1.Value)[pair2.Key] is Dictionary&lt;string, object&gt;))
                    {
                        foreach (KeyValuePair&lt;string, object&gt; pair3 in (Dictionary&lt;string, object&gt;)pair2.Value)
                            if (!ReferenceEquals(null, ((Dictionary&lt;string, object&gt;)pair2.Value)[pair3.Key]) &amp;&amp; (((Dictionary&lt;string, object&gt;)pair2.Value)[pair3.Key] is string))
                            {
                                Console.WriteLine(&quot;SubKey = {0}, Value = {1}&quot;, pair3.Key, pair3.Value);
                                sb = new StringBuilder();
                                sb.AppendFormat(&quot;{0}/{1}/{2}, {3}&quot;, pair1.Key, pair2.Key, pair3.Key, pair3.Value);
                                Console.WriteLine(sb.ToString());
                            }
                            else if (!ReferenceEquals(null, ((Dictionary&lt;string, object&gt;)pair2.Value)[pair3.Key]) &amp;&amp; (((Dictionary&lt;string, object&gt;)pair2.Value)[pair3.Key] is Dictionary&lt;string, object&gt;))
                            {
                                foreach (KeyValuePair&lt;string, object&gt; pair4 in (Dictionary&lt;string, object&gt;)pair3.Value)
                                    if (!ReferenceEquals(null, ((Dictionary&lt;string, object&gt;)pair3.Value)[pair4.Key]) &amp;&amp; (((Dictionary&lt;string, object&gt;)pair3.Value)[pair4.Key] is string))
                                    {
                                        Console.WriteLine(&quot;SubKey = {0}, Value = {1}&quot;, pair4.Key, pair4.Value);
                                        sb = new StringBuilder();
                                        sb.AppendFormat(&quot;{0}/{1}/{2}/{3}, {4}&quot;, pair1.Key, pair2.Key, pair3.Key, pair4.Key, pair4.Value);
                                        Console.WriteLine(sb.ToString());
                                    }
                                    else if (!ReferenceEquals(null, ((Dictionary&lt;string, object&gt;)pair3.Value)[pair4.Key]) &amp;&amp; (((Dictionary&lt;string, object&gt;)pair3.Value)[pair4.Key] is Dictionary&lt;string, object&gt;))
                                    {
                                        foreach (KeyValuePair&lt;string, object&gt; pair5 in (Dictionary&lt;string, object&gt;)pair4.Value)
                                            if (!ReferenceEquals(null, ((Dictionary&lt;string, object&gt;)pair4.Value)[pair5.Key]) &amp;&amp; (((Dictionary&lt;string, object&gt;)pair4.Value)[pair5.Key] is string))
                                            {
                                                Console.WriteLine(&quot;SubKey = {0}, Value = {1}&quot;, pair5.Key, pair5.Value);
                                                sb = new StringBuilder();
                                                sb.AppendFormat(&quot;{0}/{1}/{2}/{3}/{4}, {5}&quot;, pair1.Key, pair2.Key, pair3.Key, pair4.Key, pair5.Key, pair5.Value);
                                                Console.WriteLine(sb.ToString());
                                            }
                                            else if (!ReferenceEquals(null, ((Dictionary&lt;string, object&gt;)pair4.Value)[pair5.Key]) &amp;&amp; (((Dictionary&lt;string, object&gt;)pair4.Value)[pair5.Key] is Dictionary&lt;string, object&gt;))
                                            {
                                                foreach (KeyValuePair&lt;string, object&gt; pair6 in (Dictionary&lt;string, object&gt;)pair5.Value)
                                                    if (!ReferenceEquals(null, ((Dictionary&lt;string, object&gt;)pair5.Value)[pair6.Key]) &amp;&amp; (((Dictionary&lt;string, object&gt;)pair5.Value)[pair6.Key] is string))
                                                    {
                                                        Console.WriteLine(&quot;SubKey = {0}, Value = {1}&quot;, pair6.Key, pair6.Value);
                                                        sb = new StringBuilder();
                                                        sb.AppendFormat(&quot;{0}/{1}/{2}/{3}/{4}/{5}, {6}&quot;, pair1.Key, pair2.Key, pair3.Key, pair4.Key, pair5.Key, pair6.Key, pair6.Value);
                                                        Console.WriteLine(sb.ToString());
                                                    }
                                                    else if (!ReferenceEquals(null, ((Dictionary&lt;string, object&gt;)pair5.Value)[pair6.Key]) &amp;&amp; (((Dictionary&lt;string, object&gt;)pair5.Value)[pair6.Key] is Dictionary&lt;string, object&gt;))
                                                    {
                                                        Console.WriteLine(&quot;sub Dict Found&quot;);
                                                    }
                                            }
                                    }
                            }
                    }
            }
    }
}
</pre>
<p><strong>Output</strong></p>
<pre class="brush: csharp;">
SubKey = FKey, Value = FValue
ADKey/BDKey/CDKey/DDKey/EDKey/FKey, FValue
SubKey = ESKey, Value = EValue
ADKey/BDKey/CDKey/DDKey/ESKey, EValue
SubKey = DSKey, Value = DValue
ADKey/BDKey/CDKey/DSKey, DValue
SubKey = CSKey, Value = CValue
ADKey/BDKey/CSKey, CValue
SubKey = BSKey, Value = BValue
ADKey/BSKey, BValue
Key = ASKey, Value = AValue
ASKey, AValue
</pre>
<p><strong>Requirement</strong><br />
Code above tested in Visual Studio 2005 Professional Edition compiled against FrameWork 2.0 SP2.</p>
<p><em>- from StackOverflow.com</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/01/how-to-print-a-complex-dictionary-with-stringbuilder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
