<?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; Perl</title>
	<atom:link href="http://devonenote.com/tag/perl/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>Generate GUID in PERL</title>
		<link>http://devonenote.com/2011/06/generate-guid-in-perl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=generate-guid-in-perl</link>
		<comments>http://devonenote.com/2011/06/generate-guid-in-perl/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 16:13:41 +0000</pubDate>
		<dc:creator>emma</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://devonenote.com/2011/06/generate-guid-in-perl/</guid>
		<description><![CDATA[It’s very common for developer to generate a GUID in code to guarantee uniqueness. Here is the sample code to generate a GUID in Perl my $guid = `uuidgen.exe`; chomp $guid; Uuuidgen.exe is a tool from DotNet Framework. You can &#8230; <a href="http://devonenote.com/2011/06/generate-guid-in-perl/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<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-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/' 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>
</ol>]]></description>
			<content:encoded><![CDATA[<p>It’s very common for developer to generate a GUID in code to guarantee uniqueness. Here is the sample code to generate a GUID in Perl</p>
<p class="textborder">my $guid = `uuidgen.exe`;    <br />chomp $guid;</p>
<p>Uuuidgen.exe is a tool from DotNet Framework. You can append &quot;-c&quot; option to generate uppercase letters</p>
<p>Run uuidgen /? to see the detail usage of uuidgen.    <br />Microsoft UUID Generator v1.01 Copyright (c) Microsoft Corporation. All rights reserved.</p>
<p>usage: uuidgen [-xisconvh?]    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; x &#8211; Generate sequential (V1) UUIDs     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; i &#8211; Output UUID in an IDL interface template     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; s &#8211; Output UUID as an initialized C struct     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; c &#8211; Output UUID in upper case     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; o&lt;filename&gt; &#8211; redirect output to a file, specified immediately after o     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; n&lt;number&gt; &#8211; Number of UUIDs to generate, specified immediately after n     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; v &#8211; display version information about uuidgen     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; h,? &#8211; Display command option summary</p>
<p>Related posts:<ol>
<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-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/' 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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://devonenote.com/2011/06/generate-guid-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</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>
	</channel>
</rss>

