<?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>Functional Verification Blog &#187; Perl</title>
	<atom:link href="http://blog.asicguru.com/category/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.asicguru.com</link>
	<description>A Functional Verification Blog</description>
	<lastBuildDate>Tue, 18 May 2010 16:19:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sourcing a Shell script into perl</title>
		<link>http://blog.asicguru.com/2008/08/sourcing-a-shell-script-into-perl/</link>
		<comments>http://blog.asicguru.com/2008/08/sourcing-a-shell-script-into-perl/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 13:37:28 +0000</pubDate>
		<dc:creator>Puneet</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://puneetworld.com/archives/37</guid>
		<description><![CDATA[A lot of times we require to source the shell variables or shell script into the perl environment. One way to do this is you add very variable into the perl script something like :
$ENV{&#8221;SOME_VAR&#8221;} = &#8220;SOME_VAL&#8221;;
The other best way to do this task is parse the shell file and source all the environment variables [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of times we require to source the shell variables or shell script into the perl environment. One way to do this is you add very variable into the perl script something like :</p>
<p>$ENV{&#8221;SOME_VAR&#8221;} = &#8220;SOME_VAL&#8221;;</p>
<p>The other best way to do this task is parse the shell file and source all the environment variables in to perl script environment. This way we don&#8217;t need to modify your perl script every time the shell script is modified. <img src='http://blog.asicguru.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>my ($envar, $enval);<br />open IN, &#8220;. ./3rdParty.env; env |&#8221;<br />  or die &#8220;Could not run shell: $!\n&#8221;;<br />while ( &lt;IN&gt; ) {<br />  print  $_;<br />  chomp;<br />  ($envar,$enval) = split /=/,$_,2;<br />  $ENV{$envar} = $enval;<br />}<br />close IN;</p>
<p>This is very useful if the shell script is changed very frequently by the users.</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asicguru.com/2008/08/sourcing-a-shell-script-into-perl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ways to add library path in perl</title>
		<link>http://blog.asicguru.com/2008/08/ways-to-add-library-path-in-perl/</link>
		<comments>http://blog.asicguru.com/2008/08/ways-to-add-library-path-in-perl/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 11:34:05 +0000</pubDate>
		<dc:creator>Puneet</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://puneetworld.com/archives/35</guid>
		<description><![CDATA[Run a perl script using libraries in nonstandard locations.======================================
Use perl -V to see the include paths @INC array I will be something like :     /usr/lib/perl5/5.8.0/i386-linux-thread-multi    /usr/lib/perl5/5.8.0    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi    /usr/lib/perl5/site_perl/5.8.0    /usr/lib/perl5/site_perl    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi    /usr/lib/perl5/vendor_perl/5.8.0   [...]]]></description>
			<content:encoded><![CDATA[<p><b>R</b><b>un a perl script using libraries in nonstandard locations.<br />======================================</p>
<p></b>Use perl -V to see the include paths @INC array <br />I will be something like :<br />     /usr/lib/perl5/5.8.0/i386-linux-thread-multi<br />    /usr/lib/perl5/5.8.0<br />    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi<br />    /usr/lib/perl5/site_perl/5.8.0<br />    /usr/lib/perl5/site_perl<br />    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi<br />    /usr/lib/perl5/vendor_perl/5.8.0<br />    /usr/lib/perl5/vendor_perl</p>
<p><b><br />1. Using the module lib<br />===============</b><br />The standard module lib can be used to specify an explicit path to include. It must be stated at the <br />top of the script:<br />#!/usr/bin/perl<br />#<br />use lib &#8220;/opt/special/plib&#8221;;<br />use strict;<br />use warnings;<br /><b><br />2. Using the switch -I at the command line<br />============================</b></p>
<p>The switch I can be used to specify additional library locations when invoking the interpreter.<br />perl -I /opt/special/plib script.pl</p>
<p><b>3. Using the switch -I in the first line of the script<br />=================================<br /></b>The same I switch can be added to the interpreter specification.<br />#!/usr/bin/perl -I /opt/special/plib<br />#<br />use strict;<br />use warnings;<br />..</p>
<p>This works when invoking the script via the shell (which will run the interpreter with full <br />options and arguments as specified in the first line) and also when invoking the interpreter <br />directly: It apparently scans the first line for options.</p>
<p><b>4. Manipulating @INC directly<br />====================<br /></b>The array @INC can be manipulated directly using array operations :</p>
<p>#!/usr/bin/perl<br />#<br />BEGIN {<br />     unshift(@INC, &#8220;/opt/special/plib&#8221;);<br />}<br />use strict;<br />use warnings;</p>
<p><b>5. Using the environment variable PERL5LIB<br />==============================<br /></b>The environment variable PERL5LIB can be used to specify additional include directories whe<br />running a perl script.<br />&gt; export PERL5LIB=/opt/special/plib</p>
<p><b>6. Changing @INC at compile time<br />=======================<br /></b>        <br />When running Configure to compile the perl interpreter itself, there are several possibilities to add <br />additional library path elements:<br />        · Using the variable vendorprefix<br />        · Using the variable otherlibdirs<br />Both must be specified when calling Configure as a define, eg<br />    &gt; sh Configure -Dotherlibdirs=/opt/special/plib<br />The variable otherlibdirs is preferred, as it can hold mutliple values separated by a colon just like <br />the familiar PATH environment variable.<br />Details about compiling perl can be found on the CPAN network : <br /><a href="http://search.cpan.org/%7Enwclark/perl5.8.3/INSTALL">http://search.cpan.org/~nwclark/perl5.8.3/INSTALL</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asicguru.com/2008/08/ways-to-add-library-path-in-perl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Replace text in multiple files with perl just in one line&#8230;</title>
		<link>http://blog.asicguru.com/2007/03/replace-text-in-multiple-files-with-perl-just-in-one-line/</link>
		<comments>http://blog.asicguru.com/2007/03/replace-text-in-multiple-files-with-perl-just-in-one-line/#comments</comments>
		<pubDate>Mon, 12 Mar 2007 11:30:30 +0000</pubDate>
		<dc:creator>Puneet</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://puneetworld.com/archives/24</guid>
		<description><![CDATA[How do I do a mass search and replace in a directory?
How can I search for a string in all my files and replace it with a text?
Are there any spiffy shortcuts for search/replace in a directory using command line Perl?
How do I load a list of replace patterns from a file in a one-liner?
Use [...]]]></description>
			<content:encoded><![CDATA[<p><strong>How do I do a mass search and replace in a directory?</strong></p>
<p><strong>How can I search for a string in all my files and replace it with a text?</strong></p>
<p><strong>Are there any spiffy shortcuts for search/replace in a directory using command line Perl?</strong></p>
<p><strong>How do I load a list of replace patterns from a file in a one-liner?</strong></p>
<p>Use this my all time favorite one line scripts &#8230;.:)</p>
<p>Assuming you are in the directory where you want to effect this search and replace</p>
<blockquote><p>perl -pi -e &#8217;s/lookFor/replaceWith/&#8217; *.fileExtension</p>
<p>perl -pi -e &#8217;s/lookFor/replaceWith/g&#8217; *.fileExtension</p>
<p>perl -pi -e &#8217;s/lookFor/replaceWith/gi&#8217; *.fileExtension</p></blockquote>
<p><strong>Explanation :</strong></p>
<blockquote><p>- lookFor is the word you wish to look for.</p>
<p>- replaceWith is the word you wish to replace your original word with</p>
<p>- g stands for global, it will basically replace all the occurences of lookFor with replaceWith in all your files in a directory</p>
<p>- i stands for case insensitive</p></blockquote>
<p><strong>To load a series of replace expressions from a text file:</strong></p>
<pre>perl -pi -e "`/path/to/replace-patterns.txt`" *.fileExtension</pre>
<blockquote><p>s/lookForPatternOne/replaceWithOne/;</p>
<p>s/lookForPatTwo/replaceWithTwo/g;</p>
<p>s/lookForPatThree/replaceWithThree/gi;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.asicguru.com/2007/03/replace-text-in-multiple-files-with-perl-just-in-one-line/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to get a date or timestamp of a file in perl.</title>
		<link>http://blog.asicguru.com/2007/01/how-to-get-a-date-or-timestamp-of-a-file-in-perl/</link>
		<comments>http://blog.asicguru.com/2007/01/how-to-get-a-date-or-timestamp-of-a-file-in-perl/#comments</comments>
		<pubDate>Mon, 29 Jan 2007 12:27:20 +0000</pubDate>
		<dc:creator>Puneet</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://puneetworld.com/archives/19</guid>
		<description><![CDATA[Once i was trying to get the date when the file is written in perl. I found the following solutions all of them are giving the complete timestamp of the file but i needed only the date.
You can get the timestamp of a file in following ways in perl :
First Method :
$write_secs = (stat($file))[9];
print &#8220;file [...]]]></description>
			<content:encoded><![CDATA[<p>Once i was trying to get the date when the file is written in perl. I found the following solutions all of them are giving the complete timestamp of the file but i needed only the date.<br />
You can get the timestamp of a file in following ways in perl :</p>
<p><strong>First Method :</strong></p>
<blockquote><p>$write_secs = (stat($file))[9];<br />
print &#8220;file $file updated at &#8220;, scalar(localtime($file)), &#8220;\n&#8221;;</p></blockquote>
<p><strong>Second Method :</strong><br />
Using standard module File::stat and Time::locatime(bundled with all 5.x perl installations)</p>
<blockquote><p>use File::stat;<br />
use Time::localtime;<br />
$date_string = ctime(stat($file)->mtime);<br />
print &#8220;file $file updated at $date_string\n&#8221;;</p></blockquote>
<p><strong>To get only the data of file I used this solution :</strong></p>
<blockquote><p>$tm = localtime(stat($path)->mtime);<br />
#get only the data from time object<br />
$date_string = $tm->mday.&#8221;-&#8221;.(($tm->mon)+1).&#8221;-&#8221;.(($tm->year)+1900);<br />
print &#8220;file $file updated at $date_string\n&#8221;;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.asicguru.com/2007/01/how-to-get-a-date-or-timestamp-of-a-file-in-perl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple redirection in Java Script</title>
		<link>http://blog.asicguru.com/2006/10/simple-redirection-in-java-script/</link>
		<comments>http://blog.asicguru.com/2006/10/simple-redirection-in-java-script/#comments</comments>
		<pubDate>Sun, 08 Oct 2006 12:27:31 +0000</pubDate>
		<dc:creator>Puneet</dc:creator>
				<category><![CDATA[Java Script & Ajax]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://puneetworld.com/archives/16</guid>
		<description><![CDATA[Once I am trying to redirect a cgi script with cookies or after writing the cookies header. I searched a lot of stuff and found that in cgi redirection can be done only before writing the header information. Digging in to the problem  I found this simple solution&#8230;.
 location.href="www.geo-location.com" mce_href="www.geo-location.com"     [...]]]></description>
			<content:encoded><![CDATA[<p>Once I am trying to redirect a cgi script with cookies or after writing the cookies header. I searched a lot of stuff and found that in cgi redirection can be done only before writing the header information. Digging in to the problem  I found this simple solution&#8230;.<br />
<textarea rows="5" cols="50"><script language="JavaScript"> location.href="www.geo-location.com" mce_href="www.geo-location.com"                ; </script> </textarea></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asicguru.com/2006/10/simple-redirection-in-java-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
