<?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>Developer OneNote &#187; Code Snippets</title>
	<atom:link href="http://devonenote.com/tag/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://devonenote.com</link>
	<description>Emma&#039;s OneNote for Microsoft Windows, Office and Programming</description>
	<lastBuildDate>Thu, 02 Feb 2012 05:19:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CSharp &#8211; Get Assembly and File Version</title>
		<link>http://devonenote.com/2011/03/csharp-get-assembly-and-file-version/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=csharp-get-assembly-and-file-version</link>
		<comments>http://devonenote.com/2011/03/csharp-get-assembly-and-file-version/#comments</comments>
		<pubDate>Fri, 11 Mar 2011 17:44:21 +0000</pubDate>
		<dc:creator>emma</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[CSharp]]></category>

		<guid isPermaLink="false">http://devonenote.com/2011/03/csharp-get-assembly-and-file-version/</guid>
		<description><![CDATA[If you want to know the version of currently executing managed assembly, you can use Reflection.Assembly. Here is code snippet which can be used to do get managed assembly version. private string GetVersion() { &#160;&#160;&#160;&#160;&#160; return Assembly.GetExecutingAssembly().GetName().Version.ToString(); } Related posts: &#8230; <a href="http://devonenote.com/2011/03/csharp-get-assembly-and-file-version/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://devonenote.com/2010/04/use-coalescing-operator-to-write-more-readable-code/' rel='bookmark' title='Use coalescing operator to write more readable code'>Use coalescing operator to write more readable code</a></li>
<li><a href='http://devonenote.com/2010/03/c-reading-from-and-write-to-text-file/' rel='bookmark' title='C# reading from and write to text file'>C# reading from and write to text file</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/05/how-to-validate-url-in-c/' rel='bookmark' title='How to Validate URL in C#'>How to Validate URL in C#</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If you want to know the version of currently executing managed assembly, you can use Reflection.Assembly. </p>
<p>Here is code snippet which can be used to do get managed assembly version.</p>
<p class="textborder">private string GetVersion()    <br />{     <br />&#160;&#160;&#160;&#160;&#160; return Assembly.GetExecutingAssembly().GetName().Version.ToString();     <br />}</p>
<p>Related posts:<ol>
<li><a href='http://devonenote.com/2010/04/use-coalescing-operator-to-write-more-readable-code/' rel='bookmark' title='Use coalescing operator to write more readable code'>Use coalescing operator to write more readable code</a></li>
<li><a href='http://devonenote.com/2010/03/c-reading-from-and-write-to-text-file/' rel='bookmark' title='C# reading from and write to text file'>C# reading from and write to text file</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/05/how-to-validate-url-in-c/' rel='bookmark' title='How to Validate URL in C#'>How to Validate URL in C#</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://devonenote.com/2011/03/csharp-get-assembly-and-file-version/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Perl Replace String in File</title>
		<link>http://devonenote.com/2010/06/perl-replace-string-in-file/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=perl-replace-string-in-file</link>
		<comments>http://devonenote.com/2010/06/perl-replace-string-in-file/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 17:00:35 +0000</pubDate>
		<dc:creator>emma</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://devonenote.com/2010/06/perl-replace-string-in-file/</guid>
		<description><![CDATA[This code snippet demonstrates how to replace string in file using perl. This perl script takes in an input file, replaces the all string foo with bar. my $file = $ARGV[0]; my $filetmp = &#34;$ARGV[0].tmp&#34;; open (INPUT, &#34;&#60; $file&#34;) or &#8230; <a href="http://devonenote.com/2010/06/perl-replace-string-in-file/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl/' rel='bookmark' title='Perl Escape Backslashes in String Substitution'>Perl Escape Backslashes in String Substitution</a></li>
<li><a href='http://devonenote.com/2010/03/c-reading-from-and-write-to-text-file/' rel='bookmark' title='C# reading from and write to text file'>C# reading from and write to text file</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-backslash-in-regular-expression/' rel='bookmark' title='Perl Backslash in Regular Expression'>Perl Backslash in Regular Expression</a></li>
<li><a href='http://devonenote.com/2010/06/perl-add-directory-to-path/' rel='bookmark' title='Perl Add Directory to Path'>Perl Add Directory to Path</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This code snippet demonstrates how to replace string in file using perl. This perl script takes in an input file, replaces the all string foo with bar.</p>
<p class="textborder">my $file = $ARGV[0];    <br />my $filetmp = &quot;$ARGV[0].tmp&quot;;     <br />open (INPUT, &quot;&lt; $file&quot;) or die(&quot;Unable to open $file&quot;);     <br />open (TMP, &quot;&gt; $filetmp&quot;) or die(&quot;Unable to open $filetmp&quot;);     <br />while(&lt;INPUT&gt;) {     <br />&#160;&#160;&#160; if(/foo/) {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; s/foo/bar/;&#160;&#160; # replace foo with bar&#160;&#160;&#160; <br />&#160;&#160;&#160; }     <br />&#160;&#160;&#160; print TMP $_;     <br />}     <br />close(INPUT);     <br />close(TMP);     <br />rename $filetmp, $file;     </p>
<p>Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl/' rel='bookmark' title='Perl Escape Backslashes in String Substitution'>Perl Escape Backslashes in String Substitution</a></li>
<li><a href='http://devonenote.com/2010/03/c-reading-from-and-write-to-text-file/' rel='bookmark' title='C# reading from and write to text file'>C# reading from and write to text file</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-backslash-in-regular-expression/' rel='bookmark' title='Perl Backslash in Regular Expression'>Perl Backslash in Regular Expression</a></li>
<li><a href='http://devonenote.com/2010/06/perl-add-directory-to-path/' rel='bookmark' title='Perl Add Directory to Path'>Perl Add Directory to Path</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://devonenote.com/2010/06/perl-replace-string-in-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Last Element of Split</title>
		<link>http://devonenote.com/2010/06/perl-last-element-of-split/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=perl-last-element-of-split</link>
		<comments>http://devonenote.com/2010/06/perl-last-element-of-split/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 17:09:16 +0000</pubDate>
		<dc:creator>emma</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://devonenote.com/2010/06/perl-last-element-of-split/</guid>
		<description><![CDATA[There is an easier way to get last element on a split operation, save split result to an array and use $array[-1] and this will access last element of the arrays. Example $strings=”foo,bar,test”; my @fields = split(/,/, $strings); print $fields[-1] &#8230; <a href="http://devonenote.com/2010/06/perl-last-element-of-split/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl/' rel='bookmark' title='Perl Escape Backslashes in String Substitution'>Perl Escape Backslashes in String Substitution</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-backslash-in-regular-expression/' rel='bookmark' title='Perl Backslash in Regular Expression'>Perl Backslash in Regular Expression</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
<li><a href='http://devonenote.com/2010/06/perl-add-directory-to-path/' rel='bookmark' title='Perl Add Directory to Path'>Perl Add Directory to Path</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>There is an easier way to get last element on a split operation, save split result to an array and use $array[-1] and this will access last element of the arrays.</p>
<h3>Example</h3>
<p class="textborder">$strings=”foo,bar,test”;   <br />my @fields = split(/,/, $strings);    <br />print $fields[-1] ;&#160; # the last str in $strings</p>
<p>Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl/' rel='bookmark' title='Perl Escape Backslashes in String Substitution'>Perl Escape Backslashes in String Substitution</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-backslash-in-regular-expression/' rel='bookmark' title='Perl Backslash in Regular Expression'>Perl Backslash in Regular Expression</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
<li><a href='http://devonenote.com/2010/06/perl-add-directory-to-path/' rel='bookmark' title='Perl Add Directory to Path'>Perl Add Directory to Path</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://devonenote.com/2010/06/perl-last-element-of-split/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Backslash in Regular Expression</title>
		<link>http://devonenote.com/2010/06/perl-backslash-in-regular-expression/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=perl-backslash-in-regular-expression</link>
		<comments>http://devonenote.com/2010/06/perl-backslash-in-regular-expression/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 16:51:13 +0000</pubDate>
		<dc:creator>emma</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://devonenote.com/2010/06/perl-backslash-in-regular-expression/</guid>
		<description><![CDATA[This note is for a trick to use \Q and \E&#160; to escape characters for regular expression. You will find it very useful when you do string substitution and your pattern contains characters like slashes or backslashes . Here is &#8230; <a href="http://devonenote.com/2010/06/perl-backslash-in-regular-expression/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl/' rel='bookmark' title='Perl Escape Backslashes in String Substitution'>Perl Escape Backslashes in String Substitution</a></li>
<li><a href='http://devonenote.com/2010/06/perl-last-element-of-split/' rel='bookmark' title='Perl Last Element of Split'>Perl Last Element of Split</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-add-directory-to-path/' rel='bookmark' title='Perl Add Directory to Path'>Perl Add Directory to Path</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This note is for a trick to use \Q and \E&#160; to escape characters for regular expression. You will find it very useful when you do string substitution and your pattern contains characters like slashes or backslashes .</p>
<p>  <span id="more-377"></span>
<p>Here is an example example,&#160; in following code we try to replace c:\foo to d:\bar for a given directory name. </p>
<p class="textborder">my $dir = &quot;c:\\foo\\test&quot;;    <br />my $foo = &quot; c:\\foo&quot;;     <br />my $bar = &quot; d:\\bar&quot;;     <br />$str =~ s/$a/$b/g;&#160;&#160;&#160; # this prints c:\foo\test</p>
<p>The code will not work as backslashes are escaped to \\ in regular expression pattern, after using \Q and \E to escape backslashes in pattern, </p>
<p class="textborder">my $dir = &quot;c:\\foo\\test&quot;;    <br />my $foo = &quot; c:\\foo&quot;;     <br />my $bar = &quot; d:\\bar&quot;;     <br />$str =~ s/\Q$a\E/$b/g;&#160;&#160;&#160; # this prints d:\bar\test</p>
<p>Now we get what we expected.</p>
<p>More information can be found at</p>
<p><a href="http://www.sdsc.edu/~moreland/courses/IntroPerl/docs/manual/pod/perlre.html">http://www.sdsc.edu/~moreland/courses/IntroPerl/docs/manual/pod/perlre.html</a></p>
<p>\E end case modification (think vi) </p>
<p>\Q quote (disable) pattern metacharacters till \E </p>
<p>Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl/' rel='bookmark' title='Perl Escape Backslashes in String Substitution'>Perl Escape Backslashes in String Substitution</a></li>
<li><a href='http://devonenote.com/2010/06/perl-last-element-of-split/' rel='bookmark' title='Perl Last Element of Split'>Perl Last Element of Split</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-add-directory-to-path/' rel='bookmark' title='Perl Add Directory to Path'>Perl Add Directory to Path</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://devonenote.com/2010/06/perl-backslash-in-regular-expression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Escape Backslashes in String Substitution</title>
		<link>http://devonenote.com/2010/06/perl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=perl</link>
		<comments>http://devonenote.com/2010/06/perl/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 16:48:49 +0000</pubDate>
		<dc:creator>emma</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://devonenote.com/2010/06/perl/</guid>
		<description><![CDATA[This note is for a trick to use \Q and \E  to escape characters for regular expression. You will find it very useful when you do string substitution and your pattern contains characters like slashes or backslashes . Here is &#8230; <a href="http://devonenote.com/2010/06/perl/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl-backslash-in-regular-expression/' rel='bookmark' title='Perl Backslash in Regular Expression'>Perl Backslash in Regular Expression</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
<li><a href='http://devonenote.com/2010/06/perl-last-element-of-split/' rel='bookmark' title='Perl Last Element of Split'>Perl Last Element of Split</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-add-directory-to-path/' rel='bookmark' title='Perl Add Directory to Path'>Perl Add Directory to Path</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This note is for a trick to use \Q and \E  to escape characters for regular expression. You will find it very useful when you do string substitution and your pattern contains characters like slashes or backslashes .</p>
<p><span id="more-376"></span> Here is an example example,  in following code we try to replace c:\foo to d:\bar for a given directory name.</p>
<p class="textborder">my $dir = &#8220;c:\\foo\\test&#8221;;<br />
my $foo = &#8221; c:\\foo&#8221;;<br />
my $bar = &#8221; d:\\bar&#8221;;<br />
$dir =~ s/$foo/$bar/g;    # this prints c:\foo\test</p>
<p>The code will not work as backslashes are escaped to \\ in regular expression pattern, after using \Q and \E to escape backslashes in pattern,</p>
<p class="textborder">my $dir = &#8220;c:\\foo\\test&#8221;;<br />
my $foo = &#8220;c:\\foo&#8221;;<br />
my $bar = &#8220;d:\\bar&#8221;;<br />
$str =~ s/\Q$foo\E/$bar/g;    # this prints d:\bar\test</p>
<p>Now we get what we expected.</p>
<p>More information can be found at</p>
<p><a href="http://www.sdsc.edu/~moreland/courses/IntroPerl/docs/manual/pod/perlre.html">http://www.sdsc.edu/~moreland/courses/IntroPerl/docs/manual/pod/perlre.html</a></p>
<p>\E end case modification (think vi)</p>
<p>\Q quote (disable) pattern metacharacters till \E</p>
<p>Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl-backslash-in-regular-expression/' rel='bookmark' title='Perl Backslash in Regular Expression'>Perl Backslash in Regular Expression</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
<li><a href='http://devonenote.com/2010/06/perl-last-element-of-split/' rel='bookmark' title='Perl Last Element of Split'>Perl Last Element of Split</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-add-directory-to-path/' rel='bookmark' title='Perl Add Directory to Path'>Perl Add Directory to Path</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://devonenote.com/2010/06/perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Add Directory to Path</title>
		<link>http://devonenote.com/2010/06/perl-add-directory-to-path/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=perl-add-directory-to-path</link>
		<comments>http://devonenote.com/2010/06/perl-add-directory-to-path/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 16:20:24 +0000</pubDate>
		<dc:creator>emma</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://devonenote.com/2010/06/perl-add-directory-to-path/</guid>
		<description><![CDATA[Say you have a directory d:\bin and you want to add it to path environment at the beginning of your Perl script. Following code will do the trick. my $dir=&#34;d:\\bin&#34;; $ENV{PATH}.=&#34;;$dir&#34;; Then $dir will be included in new $ENV{PATH} Related &#8230; <a href="http://devonenote.com/2010/06/perl-add-directory-to-path/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl/' rel='bookmark' title='Perl Escape Backslashes in String Substitution'>Perl Escape Backslashes in String Substitution</a></li>
<li><a href='http://devonenote.com/2010/06/perl-backslash-in-regular-expression/' rel='bookmark' title='Perl Backslash in Regular Expression'>Perl Backslash in Regular Expression</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
<li><a href='http://devonenote.com/2011/06/generate-guid-in-perl/' rel='bookmark' title='Generate GUID in PERL'>Generate GUID in PERL</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Say you have a directory d:\bin and you want to add it to path environment at the beginning of your Perl script. Following code will do the trick.</p>
<p class="textborder">my $dir=&quot;d:\\bin&quot;;    <br />$ENV{PATH}.=&quot;;$dir&quot;;</p>
<p>Then $dir will be included in new $ENV{PATH}</p>
<p>Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl/' rel='bookmark' title='Perl Escape Backslashes in String Substitution'>Perl Escape Backslashes in String Substitution</a></li>
<li><a href='http://devonenote.com/2010/06/perl-backslash-in-regular-expression/' rel='bookmark' title='Perl Backslash in Regular Expression'>Perl Backslash in Regular Expression</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
<li><a href='http://devonenote.com/2011/06/generate-guid-in-perl/' rel='bookmark' title='Generate GUID in PERL'>Generate GUID in PERL</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://devonenote.com/2010/06/perl-add-directory-to-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Redirect Command Output</title>
		<link>http://devonenote.com/2010/05/redirect-command-output-in-perl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=redirect-command-output-in-perl</link>
		<comments>http://devonenote.com/2010/05/redirect-command-output-in-perl/#comments</comments>
		<pubDate>Sat, 29 May 2010 18:18:55 +0000</pubDate>
		<dc:creator>emma</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://devonenote.com/2010/05/redirect-command-output-in-perl/</guid>
		<description><![CDATA[In Perl, you can execute external commands using system() or &#8220;. However, system and &#8220; does not redirect command output to console and this results people who runs your perl script can&#8217;t see it. This also make debug much harder. &#8230; <a href="http://devonenote.com/2010/05/redirect-command-output-in-perl/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl-last-element-of-split/' rel='bookmark' title='Perl Last Element of Split'>Perl Last Element of Split</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
<li><a href='http://devonenote.com/2010/06/perl/' rel='bookmark' title='Perl Escape Backslashes in String Substitution'>Perl Escape Backslashes in String Substitution</a></li>
<li><a href='http://devonenote.com/2010/06/perl-backslash-in-regular-expression/' rel='bookmark' title='Perl Backslash in Regular Expression'>Perl Backslash in Regular Expression</a></li>
<li><a href='http://devonenote.com/2010/06/perl-add-directory-to-path/' rel='bookmark' title='Perl Add Directory to Path'>Perl Add Directory to Path</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In Perl, you can execute external commands using system() or &#8220;. However, system and &#8220; does not redirect command output to console and this results people who runs your perl script can&#8217;t see it. This also make debug much harder. Perl does not have a build in switch that equals to batch scripts’ &#8220;@echo on&#8221;, however this can be worked around by creating a ExecuteCommand subroutine.</p>
<p class="textborder">sub ExecuteCommand {<br />
my $cmd= $_;<br />
my @cmdoutput = `$cmd`;<br />
for $line (@cmdoutput) {<br />
print $line;<br />
}</p>
<p>Now just change your code from system($command) or `$command` to ExecuteCommand($command) and you will see all command output are redirected to console.<span id="more-362"></span></p>
<p>En, good but …</p>
<h3>I want to see the command that it’s running</h3>
<p>Just add print following line prior the call of command.</p>
<p class="textborder">print &#8220;Now running $cmd …\n&#8221;;</p>
<p>or call your logging subrountine.</p>
<h3>I want to know return code of $cmd</h3>
<p>Use my $cmdexitcode = $? &gt;&gt; 8; to get the return code of $cmd and then add     return $cmdexitcode; at the end of ExecuteCommand</p>
<h3>I want to pass more than one command to ExecuteCommand</h3>
<p>Try this version</p>
<p class="textborder">sub ExecuteCommand {<br />
@cmdlist = (@_);<br />
my $cmd = join(&#8221; \&amp; &#8220;, @cmdlist);<br />
my @cmdoutput = `$cmd`;<br />
my $cmdexitcode = $? &gt;&gt; 8;<br />
for $line (@cmdoutput) {<br />
print $line;<br />
}<br />
return $cmdexitcode;<br />
}</p>
<p>Now you should call ExecuteCommand like this when you want to pass more than one command.</p>
<p class="textborder">push @cmdlist, $cmd1;<br />
push @cmdlist, $cmd2;<br />
push @cmdlist, $cmd3;<br />
ExecuteCommand(@cmdlist);</p>
<p>And $cmd1, cmd2, cmd3 will be run in one context shell.</p>
<p>Related posts:<ol>
<li><a href='http://devonenote.com/2010/06/perl-last-element-of-split/' rel='bookmark' title='Perl Last Element of Split'>Perl Last Element of Split</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
<li><a href='http://devonenote.com/2010/06/perl/' rel='bookmark' title='Perl Escape Backslashes in String Substitution'>Perl Escape Backslashes in String Substitution</a></li>
<li><a href='http://devonenote.com/2010/06/perl-backslash-in-regular-expression/' rel='bookmark' title='Perl Backslash in Regular Expression'>Perl Backslash in Regular Expression</a></li>
<li><a href='http://devonenote.com/2010/06/perl-add-directory-to-path/' rel='bookmark' title='Perl Add Directory to Path'>Perl Add Directory to Path</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://devonenote.com/2010/05/redirect-command-output-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Validate URL in C#</title>
		<link>http://devonenote.com/2010/05/how-to-validate-url-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-validate-url-in-c</link>
		<comments>http://devonenote.com/2010/05/how-to-validate-url-in-c/#comments</comments>
		<pubDate>Thu, 27 May 2010 13:37:01 +0000</pubDate>
		<dc:creator>emma</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://devonenote.com/2010/05/how-to-validate-url-in-c/</guid>
		<description><![CDATA[I searched google for how to valicate URL in C# and most results say using a regular expression. Eventually I found Uri.TryCreate which is a built in method in C# to check if a string is a valid URL Uri &#8230; <a href="http://devonenote.com/2010/05/how-to-validate-url-in-c/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://devonenote.com/2010/04/use-coalescing-operator-to-write-more-readable-code/' rel='bookmark' title='Use coalescing operator to write more readable code'>Use coalescing operator to write more readable code</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2011/03/csharp-get-assembly-and-file-version/' rel='bookmark' title='CSharp &#8211; Get Assembly and File Version'>CSharp &#8211; Get Assembly and File Version</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I searched google for how to valicate URL in C# and most results say using a regular expression. Eventually I found Uri.TryCreate which is a built in method in C# to check if a string is a valid URL</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">Uri</span> uri = <span style="color: blue">null</span>;</p>
<p style="margin: 0px"><span style="color: blue">if</span> (!<span style="color: #2b91af">Uri</span>.TryCreate(url, <span style="color: #2b91af">UriKind</span>.Absolute, <span style="color: blue">out</span> uri) || <span style="color: blue">null</span> == uri)</p>
<p style="margin: 0px">{&#160; </p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: green">//Invalid URL</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">return</span> <span style="color: blue">false</span>;</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">&#160;</p>
</p></div>
<p>Reference:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms131572(v=VS.90).aspx">http://msdn.microsoft.com/en-us/library/ms131572(v=VS.90).aspx</a></p>
<p>Related posts:<ol>
<li><a href='http://devonenote.com/2010/04/use-coalescing-operator-to-write-more-readable-code/' rel='bookmark' title='Use coalescing operator to write more readable code'>Use coalescing operator to write more readable code</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2011/03/csharp-get-assembly-and-file-version/' rel='bookmark' title='CSharp &#8211; Get Assembly and File Version'>CSharp &#8211; Get Assembly and File Version</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://devonenote.com/2010/05/how-to-validate-url-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SpellChecker in WPF4 TextBox</title>
		<link>http://devonenote.com/2010/05/spellchecker-in-wpf4-textbox/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spellchecker-in-wpf4-textbox</link>
		<comments>http://devonenote.com/2010/05/spellchecker-in-wpf4-textbox/#comments</comments>
		<pubDate>Tue, 04 May 2010 16:27:19 +0000</pubDate>
		<dc:creator>emma</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SpellChecker]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://devonenote.com/2010/05/spellchecker-in-wpf4/</guid>
		<description><![CDATA[TextBox and RichTextBox in WPF4 has the built in SpellChecker functionality. It’s currently available in following four languages #LID 1033 – English #LID 3082 – Spanish #LID 1031 – German #LID 1036 – French Enable SpellChecker functionality on TextBox or &#8230; <a href="http://devonenote.com/2010/05/spellchecker-in-wpf4-textbox/">Continue reading <span class="meta-nav">&#8594;</span></a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>TextBox and RichTextBox in WPF4 has the built in SpellChecker functionality. It’s currently available in following four languages</p>
<ul>
<li>#LID 1033 – English</li>
<li>#LID 3082 – Spanish</li>
<li>#LID 1031 – German</li>
<li>#LID 1036 – French</li>
</ul>
<p>Enable SpellChecker functionality on TextBox or RichTextBox is as easy as just setting SpellCheck.IsEnabled to True on the controls.</p>
<pre>   &lt;TextBox SpellCheck.IsEnabled="True" /&gt;</pre>
<p><span id="more-319"></span>Then all misspelled words will be underlined with a wavy red line in run time. And when user right clicks on misspelled word, a list of suggestion words will be displayed.</p>
<h3>Example</h3>
<p><a href="http://devonenote.com/wp-content/uploads/2010/05/image.png"><img class="wlDisabledImage" style="margin: 0px auto; display: block; float: none; border-width: 0px;" title="image" src="http://devonenote.com/wp-content/uploads/2010/05/image_thumb.png" border="0" alt="image" width="480" height="208" /></a></p>
<h3>Update</h3>
<p>As per this MSDN <a href="http://social.msdn.microsoft.com/Forums/en/wpf/thread/c4a62da5-9a7d-4e1d-bcbc-12945046fc42" target="_blank">thread</a>, <em>you need to install language pack for .NET Framework 4.0 to enable spell check for some language in your WPF4 applications. For example, if you want to spell check for German, you need to install .NET Framework 4.0 German language pack on your machine. So far the .NET Framework 4.0 language pack is not available, but it will be soon.<br />
</em></p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://devonenote.com/2010/05/spellchecker-in-wpf4-textbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use coalescing operator to write more readable code</title>
		<link>http://devonenote.com/2010/04/use-coalescing-operator-to-write-more-readable-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=use-coalescing-operator-to-write-more-readable-code</link>
		<comments>http://devonenote.com/2010/04/use-coalescing-operator-to-write-more-readable-code/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 13:35:40 +0000</pubDate>
		<dc:creator>emma</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[CSharp]]></category>

		<guid isPermaLink="false">http://devonenote.com/2010/04/use-coalescing-operator-to-write-more-readable-code/</guid>
		<description><![CDATA[Tired of code like this? public string Foo { get { return foo; } set { if (value == null) value = String.Empty; foo = value; } } public string Bar { get { return bar; } set { if &#8230; <a href="http://devonenote.com/2010/04/use-coalescing-operator-to-write-more-readable-code/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://devonenote.com/2010/05/how-to-validate-url-in-c/' rel='bookmark' title='How to Validate URL in C#'>How to Validate URL in C#</a></li>
<li><a href='http://devonenote.com/2010/03/c-reading-from-and-write-to-text-file/' rel='bookmark' title='C# reading from and write to text file'>C# reading from and write to text file</a></li>
<li><a href='http://devonenote.com/2011/03/csharp-get-assembly-and-file-version/' rel='bookmark' title='CSharp &#8211; Get Assembly and File Version'>CSharp &#8211; Get Assembly and File Version</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Tired of code like this?</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">string</span> Foo</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;"><span style="color: blue;">get</span> { <span style="color: blue;">return</span> foo; }</p>
<p style="margin: 0px;"><span style="color: blue;">set</span></p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;"><span style="color: blue;">if</span> (<span style="color: blue;">value</span> == <span style="color: blue;">null</span>)</p>
<p style="margin: 0px;"><span style="color: blue;">value</span> = <span style="color: #2b91af;">String</span>.Empty;</p>
<p style="margin: 0px;">foo = <span style="color: blue;">value</span>;</p>
<p style="margin: 0px;">}</p>
<p style="margin: 0px;">}</p>
<p style="margin: 0px;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">string</span> Bar</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;"><span style="color: blue;">get</span> { <span style="color: blue;">return</span> bar; }</p>
<p style="margin: 0px;"><span style="color: blue;">set</span></p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;"><span style="color: blue;">if</span> (<span style="color: blue;">value</span> == <span style="color: blue;">null</span>)</p>
<p style="margin: 0px;"><span style="color: blue;">value</span> = <span style="color: #2b91af;">String</span>.Empty;</p>
<p style="margin: 0px;">bar = <span style="color: blue;">value</span>;</p>
<p style="margin: 0px;">}</p>
<p style="margin: 0px;">}</p>
</div>
<p>Use coalescing operator to make your code a bit more readable.</p>
<p><span id="more-308"></span><span style="font-family: consolas;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> Foo</span></p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt;">
<p style="margin: 0px;">{</p>
<p style="margin: 0px;"><span style="color: blue;">get</span> { <span style="color: blue;">return</span> foo; }</p>
<p style="margin: 0px;"><span style="color: blue;">set</span></p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;">foo = <span style="color: blue;">value</span> ?? <span style="color: #2b91af;">String</span>.Empty;</p>
<p style="margin: 0px;">}</p>
<p style="margin: 0px;">}</p>
<p style="margin: 0px;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">string</span> Bar</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;"><span style="color: blue;">get</span> { <span style="color: blue;">return</span> bar; }</p>
<p style="margin: 0px;"><span style="color: blue;">set</span></p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;">bar = <span style="color: blue;">value</span> ?? <span style="color: #2b91af;">String</span>.Empty;</p>
<p style="margin: 0px;">}</p>
<p style="margin: 0px;">}</p>
</div>
<p>Does this look better? The ?? operator is called the null-coalescing operator and is used to define a default value for a nullable value types as well as reference types. It returns the left-hand operand if it is not null; otherwise it returns the right operand. More information on ?? can be found at <a href="http://msdn.microsoft.com/en-us/library/ms173224.aspx">http://msdn.microsoft.com/en-us/library/ms173224.aspx</a></p>
<p>Related posts:<ol>
<li><a href='http://devonenote.com/2010/05/how-to-validate-url-in-c/' rel='bookmark' title='How to Validate URL in C#'>How to Validate URL in C#</a></li>
<li><a href='http://devonenote.com/2010/03/c-reading-from-and-write-to-text-file/' rel='bookmark' title='C# reading from and write to text file'>C# reading from and write to text file</a></li>
<li><a href='http://devonenote.com/2011/03/csharp-get-assembly-and-file-version/' rel='bookmark' title='CSharp &#8211; Get Assembly and File Version'>CSharp &#8211; Get Assembly and File Version</a></li>
<li><a href='http://devonenote.com/2010/05/redirect-command-output-in-perl/' rel='bookmark' title='Perl Redirect Command Output'>Perl Redirect Command Output</a></li>
<li><a href='http://devonenote.com/2010/06/perl-replace-string-in-file/' rel='bookmark' title='Perl Replace String in File'>Perl Replace String in File</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://devonenote.com/2010/04/use-coalescing-operator-to-write-more-readable-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

