<?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>NonStopSites Blog &#187; perl</title>
	<atom:link href="http://blog.nonstopsites.us/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nonstopsites.us</link>
	<description>Dynamic Websites Done Right!</description>
	<lastBuildDate>Sat, 24 Jul 2010 06:02:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Check if a file exists on another domain</title>
		<link>http://blog.nonstopsites.us/check-if-a-file-exists-on-another-domain/</link>
		<comments>http://blog.nonstopsites.us/check-if-a-file-exists-on-another-domain/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 05:56:56 +0000</pubDate>
		<dc:creator>Sech</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.nonstopsites.us/?p=82</guid>
		<description><![CDATA[PERL: Use LWP::Simple and the head function. use LWP::Simple; my $url = 'http://some.server.com/file.gif'; if (head($url)) { # file is there } else { # file is missing } Credit goes to perlmonks.org. PHP: Use get_headers $fileUrl = 'http://some.server.com/file.gif'; $AgetHeaders = @get_headers($fileUrl); if (preg_match("&#124;200&#124;", $AgetHeaders[0])) { # file is there } else { # file is [...]]]></description>
			<content:encoded><![CDATA[<!-- sphereit start --><p><strong>PERL:</strong></p>
<p>Use LWP::Simple and the head function.</p>
<blockquote><p>use LWP::Simple;</p>
<p>my $url = 'http://some.server.com/file.gif';</p>
<p>if (head($url)) {<br />
  # file is there<br />
} else {<br />
  # file is missing<br />
}</p></blockquote>
<p>Credit goes to <a href="http://www.perlmonks.org/?node_id=112853">perlmonks.org</a>.</p>
<p><strong>PHP:</strong></p>
<p>Use get_headers</p>
<blockquote><p>$fileUrl = 'http://some.server.com/file.gif';<br />
$AgetHeaders = @get_headers($fileUrl);<br />
if (preg_match("|200|", $AgetHeaders[0])) {<br />
 # file is there<br />
} else {<br />
 # file is missing<br />
} </p></blockquote>
<p>Credit goes to <a href="http://us2.php.net/file_exists">php.net</a>.</p>
<!-- sphereit end --><span style="margin-bottom:40px; border-bottom:none;"><a class="iconsphere" title="Sphere: Related Content" onclick="return Sphere.Widget.search('http://blog.nonstopsites.us/check-if-a-file-exists-on-another-domain/')" href="http://www.sphere.com/search?q=sphereit:http://blog.nonstopsites.us/check-if-a-file-exists-on-another-domain/">Sphere: Related Content</a></span><br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nonstopsites.us/check-if-a-file-exists-on-another-domain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Apache, Perl &amp; PHP on Windows</title>
		<link>http://blog.nonstopsites.us/installing-apache-perl-php-on-windows/</link>
		<comments>http://blog.nonstopsites.us/installing-apache-perl-php-on-windows/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 06:27:17 +0000</pubDate>
		<dc:creator>Sech</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://blog.nonstopsites.us/?p=71</guid>
		<description><![CDATA[Every once in a while I need to install Apache http server on my pc or laptop to use as local test server. I also need to install Perl, PHP and mysql to have the complete environment to test scripts and applications before uploading them on a live server. Ricocheting.com has a great tutorial for [...]]]></description>
			<content:encoded><![CDATA[<!-- sphereit start --><p>Every once in a while I need to install Apache http server on my pc or laptop to use as local test server. I also need to install Perl, PHP and mysql to have the complete environment to test scripts and applications before uploading them on a live server.</p>
<p>Ricocheting.com has a great <a href="http://www.ricocheting.com/server/" target="_blank">tutorial</a> for installing Apache, PHP and Perl on a Windows server. Last time I had to do a re-install on my PC, I followed their tutorial.</p>
<p>A few impressions and comments:</p>
<p>1) They recommend staying with the default installation of Apache and changing "DocumentRoot" later. I change the installation location to "C:\Apache" which defaults DocumentRoot to C:\Apache\htdocs. It is much better to do it this way. You will not need to modify the configuration file to set DocumentRoot. You will not need to dig into all the way to C:\Program Files\Apache\... to look at log files or configuration files either. </p>
<p>2) I loved their tip about where to install ActiveState Perl: "<strong>C:\usr</strong>". I used to install Perl to C:\Perl directory which forced me to change the shebang lines on scripts. Listen to this:</p>
<blockquote><p>If you will be using Perl CGI programs and want to maintain some level of portability between both Linux machines and Windows machines, you will want to install Perl to the same location on your Windows machine that it is on most Linux machines.</p>
<p>For example, on a standard Linux machine, Perl is located at /usr/bin/perl and so every Perl program that I write begins with #!/usr/bin/perl. So, when I install Perl on a Windows machine, instead of installing it in the default location (which is E:\perl for ActivePerl) I install it in E:\usr so that the Perl executable is located at /usr/bin/perl. This allows me to write code on my Windows machine, then move it (without making any changes) to a Linux machine and have it run there. And vice versa. </p></blockquote>
<p>Wow! I wish I had figured this out earlier... "<strong>#!/usr/bin/perl</strong>" works in windows if you install Perl in C:\usr directory. No, you do not need to have "C:\" on the shebang line. This will save a lot of time and headache.</p>
<p>3) The site also includes the lines required to be added in Apache configuration file to make CGI and PHP work. I will put a copy of these here:</p>
<p>To activate CGI:<br />
Edit the Apache httpd.conf Configuration File and search for Options Indexes FollowSymLinks (about line 190) when you find it add ExecCGI to the end so it looks like </p>
<p><strong>Options Indexes FollowSymLinks ExecCGI </strong></p>
<p>To use CGI outside the cgi-bin directory, uncomment:<br />
#<strong>AddHandler cgi-script .cgi</strong><br />
Also add .pl behind .cgi so 'perl' extension is also treated as cgi files.</p>
<p>To use PHP at the very end of the httpd.conf file add the following lines:</p>
<p>	<strong>LoadModule php5_module "C:/php/php5apache2_2.dll"</strong><br />
	<strong>AddType application/x-httpd-php .php</strong><br />
	<strong>PHPIniDir "C:/php"</strong></p>
<p>Also Open php.ini in a text editor and scroll down about halfway through the file and look for doc_root then change it to point to whatever your Apache DocumentRoot is set to. In my case: doc_root = "C:\Apache\htdocs" </p>
<p>To get Apache to automatically look for an index.php, and index.pl search httpd.conf for DirectoryIndex (about line 212) and add the files you want Apache to look for when a directory is loaded (if it doesn't find any of these files, it displays folder contents). Mine looks like: </p>
<p><IfModule dir_module><br />
<strong>     DirectoryIndex index.php index.pl index.html</strong><br />
</IfModule></p>
<p>They also have information on installing MySQL which is pretty straightforward. </p>
<p>There is one thing I would like to add here though: If you want to use DBD-MySQL package with Perl , you will notice that it is not included in the latest ActiveStatePerl distribution. You can't even install it using the GUI ppm. Here is what you need to do:</p>
<p>At the Command Prompt type:</p>
<p><strong>ppm install http://theoryx5.uwinnipeg.ca/ppms/DBI-mysql.ppd</strong></p>
<p>UPDATE on Jan 9, 2009 >>></p>
<p>If you use ActiveState Perl 5.10, above link will not work either. The easiest way to do this is to start your Perl Package Manager, click on Edit -> Preferences and click on the Repositories tab. Type "http://cpan.uwinnipeg.ca/PPMPackages/10xx/" in Location. You just installed the Repository that has the DBD-MySQL package which will enable you to install it using your Perl ppm.</p>
<p>It sure will be nice to have all this info ready when I need to install Apache, Perl, PHP and MySQL on Windows next time.</p>
<!-- sphereit end --><span style="margin-bottom:40px; border-bottom:none;"><a class="iconsphere" title="Sphere: Related Content" onclick="return Sphere.Widget.search('http://blog.nonstopsites.us/installing-apache-perl-php-on-windows/')" href="http://www.sphere.com/search?q=sphereit:http://blog.nonstopsites.us/installing-apache-perl-php-on-windows/">Sphere: Related Content</a></span><br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nonstopsites.us/installing-apache-perl-php-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Perl to parse CSV files</title>
		<link>http://blog.nonstopsites.us/using-perl-to-parse-csv-files/</link>
		<comments>http://blog.nonstopsites.us/using-perl-to-parse-csv-files/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 07:43:30 +0000</pubDate>
		<dc:creator>Sech</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[web admin]]></category>

		<guid isPermaLink="false">http://blog.nonstopsites.us/2008/03/08/using-perl-to-parse-csv-files/</guid>
		<description><![CDATA[It took me a while to get this right. For future reference and for others who may need the same functionality here is the information: Task: 1. Upload a CSV file to the server, 2. Use a CRON job to run a perl script that inserts the fields in the CSV file to a MYSQL [...]]]></description>
			<content:encoded><![CDATA[<!-- sphereit start --><p>It took me a while to get this right. For future reference and for others who may need the same functionality here is the information:</p>
<p>Task:</p>
<p>1. Upload a CSV file to the server,<br />
2. Use a CRON job to run a perl script that inserts the fields in the CSV file to a MYSQL database file.</p>
<p>Solution 1:</p>
<blockquote><p>#!/usr/bin/perl</p>
<p>use DBI;<br />
my $DSN = 'DBI:mysql:database';<br />
my $dsn_user = 'database_user';<br />
my $dsn_pw = 'database_user_password';<br />
my $dbh = DBI-&gt;connect($DSN,$dsn_user,$dsn_pw)<br />
or die "Couldn't connect to database: " . DBI-&gt;errstr;</p>
<p>$rows = $dbh-&gt;do("DELETE FROM table");</p>
<p>$result = $dbh-&gt;do("OPTIMIZE TABLE table");</p>
<p># Load local comma separated, fields enclosed by quotes text database<br />
#- File has to be in the same directory of this file or give full directory path<br />
$result = $dbh-&gt;do("LOAD DATA LOCAL INFILE '/full_directory_path_to/data.csv' INTO TABLE table FIELDS TERMINATED BY ','ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (table_field1,table_field2,table_field3,so_on)");</p></blockquote>
<p>This solution worked great on a server with a MYSQL 3.23</p>
<p>Challenge:</p>
<p>Time to move to a server with a MYSQL 4 or 5 where -local infile is disabled and it is not possible to get the web host do the necessary changes. You need a work-around fast... It is not easy to find a CSV parser in Perl that will parse a CSV file with comma separated columns that also has several columns that are enclosed by quotation marks ("). After trying several different solutions that either not worked at all or required major changes I found this here:</p>
<p><a href="http://coding.derkeiler.com/Archive/Perl/comp.lang.perl.misc/2004-07/1638.html">http://coding.derkeiler.com/Archive/Perl/comp.lang.perl.misc/2004-07/1638.html</a></p>
<blockquote><p>sub parseCSVLine{<br />
my $line=shift;<br />
my @fields=();my $field=''; # initialize<br />
my @fragments=split(/,/,$line,-1); # split into "," seperated fragments<br />
foreach my $nibble(@fragments){<br />
if($field){$field .= ','} # add the missing commas;<br />
$field .= $nibble; # combine fragment into a field until...<br />
my $count = $field =~tr/"/"/; # count quotes<br />
unless($count % 2){ # ...there's an even number of double quotes<br />
$field =~s/""/"/g; $field=~s/^\s*"//g; $field=~s/"\s*$//g; # fix quotes<br />
# fix quotes<br />
push @fields, $field;<br />
$field=''; # reinitialize $field<br />
}<br />
}<br />
return @fields;<br />
}</p></blockquote>
<p>Surprisingly this worked without a hitch. After you run each line through this subroutine do a REPLACE into the database table.</p>
<h4>Incoming search terms:</h4><ul><li>perl csv to mysql</li></ul><!-- SEO SearchTerms Tagging 2 plugin took 0.53 ms --><!-- sphereit end --><span style="margin-bottom:40px; border-bottom:none;"><a class="iconsphere" title="Sphere: Related Content" onclick="return Sphere.Widget.search('http://blog.nonstopsites.us/using-perl-to-parse-csv-files/')" href="http://www.sphere.com/search?q=sphereit:http://blog.nonstopsites.us/using-perl-to-parse-csv-files/">Sphere: Related Content</a></span><br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.nonstopsites.us/using-perl-to-parse-csv-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
