<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nano&#039;s Blog &#187; perl</title>
	<atom:link href="http://www.nanohe.net/blog/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nanohe.net/blog</link>
	<description>Hello World!</description>
	<lastBuildDate>Tue, 20 Jul 2010 09:47:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Perl trim function to strip whitespace from a string</title>
		<link>http://www.nanohe.net/blog/2010/07/perl-trim-function-to-strip-whitespace-from-a-string/</link>
		<comments>http://www.nanohe.net/blog/2010/07/perl-trim-function-to-strip-whitespace-from-a-string/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 09:47:36 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/2010/07/perl-trim-function-to-strip-whitespace-from-a-string/</guid>
		<description><![CDATA[Perl does not have a built-in trim function. Use the subroutine below to trim whitespace (spaces and tabs) from the beginning and end of a string in Perl. This function is directly based on the Perl FAQ entry, How do I strip blank space from the beginning/end of a string?. The ltrim and rtrim functions [...]]]></description>
			<content:encoded><![CDATA[<p>Perl does not have a built-in trim function. Use the subroutine below to trim whitespace (spaces and tabs) from the beginning and end of a string in Perl. This function is directly based on the Perl FAQ entry, How do I strip blank space from the beginning/end of a string?. The ltrim and rtrim functions can trim leading or trailing whitespace. </p>
<pre class="brush: perl;">
#!/usr/bin/perl

# Declare the subroutines
sub trim($);
sub ltrim($);
sub rtrim($);

# Create a test string
my $string = &quot;  \t  Hello world!   &quot;;

# Here is how to output the trimmed text &quot;Hello world!&quot;
print trim($string).&quot;\n&quot;;
print ltrim($string).&quot;\n&quot;;
print rtrim($string).&quot;\n&quot;;

# Perl trim function to remove whitespace from the start and end of the string
sub trim($)
{
	my $string = shift;
	$string =~ s/^\s+//;
	$string =~ s/\s+$//;
	return $string;
}
# Left trim function to remove leading whitespace
sub ltrim($)
{
	my $string = shift;
	$string =~ s/^\s+//;
	return $string;
}
# Right trim function to remove trailing whitespace
sub rtrim($)
{
	my $string = shift;
	$string =~ s/\s+$//;
	return $string;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/07/perl-trim-function-to-strip-whitespace-from-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to parse multi record XML file ues XML::Simple in Perl</title>
		<link>http://www.nanohe.net/blog/2010/06/how-to-parse-multi-record-xml-file-ues-xmlsimple-in-perl/</link>
		<comments>http://www.nanohe.net/blog/2010/06/how-to-parse-multi-record-xml-file-ues-xmlsimple-in-perl/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 03:30:30 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/?p=328</guid>
		<description><![CDATA[How to access multiple records 
data.xml

&#60;?xml version=&#34;1.0&#34; encoding=&#34;ISO-8859-1&#34;?&#62;
&#60;catalog&#62;
  &#60;cd country=&#34;UK&#34;&#62;
    &#60;title&#62;Hide your heart&#60;/title&#62;
    &#60;artist&#62;Bonnie Tyler&#60;/artist&#62;
    &#60;price&#62;10.0&#60;/price&#62;
  &#60;/cd&#62;
  &#60;cd country=&#34;CHN&#34;&#62;
    &#60;title&#62;Greatest Hits&#60;/title&#62;
    &#60;artist&#62;Dolly Parton&#60;/artist&#62;
    &#60;price&#62;9.99&#60;/price&#62;
  &#60;/cd&#62;
  &#60;cd country=&#34;USA&#34;&#62;
    &#60;title&#62;Hello&#60;/title&#62;
  [...]]]></description>
			<content:encoded><![CDATA[<p>How to access multiple records </p>
<p><strong>data.xml</strong></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;catalog&gt;
  &lt;cd country=&quot;UK&quot;&gt;
    &lt;title&gt;Hide your heart&lt;/title&gt;
    &lt;artist&gt;Bonnie Tyler&lt;/artist&gt;
    &lt;price&gt;10.0&lt;/price&gt;
  &lt;/cd&gt;
  &lt;cd country=&quot;CHN&quot;&gt;
    &lt;title&gt;Greatest Hits&lt;/title&gt;
    &lt;artist&gt;Dolly Parton&lt;/artist&gt;
    &lt;price&gt;9.99&lt;/price&gt;
  &lt;/cd&gt;
  &lt;cd country=&quot;USA&quot;&gt;
    &lt;title&gt;Hello&lt;/title&gt;
    &lt;artist&gt;Say Hello&lt;/artist&gt;
    &lt;price&gt;0001&lt;/price&gt;
  &lt;/cd&gt;
&lt;/catalog&gt;
</pre>
<p><strong>test.pl</strong></p>
<pre class="brush: perl;">
#!/usr/bin/perl
   # use module
   use strict;
   use warnings;

   use XML::Simple;
   use Data::Dumper;

   # create object
   my $xml = new XML::Simple;

   # read XML file
   my $data = $xml-&gt;XMLin(&quot;data.xml&quot;);

   # access XML data
   # print &quot;$data-&gt;{name} is $data-&gt;{age} years old and works in the $data-&gt;{department} section\n&quot;;

  print $data-&gt;{cd}[0]{country}.&quot;\n&quot;;
  print $data-&gt;{cd}[0]{artist}.&quot;\n&quot;;
  print $data-&gt;{cd}[0]{price}.&quot;\n&quot;;
  print $data-&gt;{cd}[0]{title}.&quot;\n&quot;;
  print &quot;\n\n&quot;;
  print &quot;$data-&gt;{cd}-&gt;[0]-&gt;{country}\n&quot;;
  print &quot;$data-&gt;{cd}-&gt;[0]-&gt;{artist}\n&quot;;
  print &quot;$data-&gt;{cd}-&gt;[0]-&gt;{price}\n&quot;;
  print &quot;$data-&gt;{cd}-&gt;[0]-&gt;{title}\n&quot;;

  print &quot;\n\n&quot;;
   # print output
  print Dumper($data);
</pre>
<p>output:</p>
<pre class="brush: plain;">

D:\learning\perl&gt;t1.pl
could not find ParserDetails.ini in C:/Perl/site/lib/XML/SAX
UK
Bonnie Tyler
10.0
Hide your heart

UK
Bonnie Tyler
10.0
Hide your heart

$VAR1 = {
          'cd' =&gt; [
                    {
                      'country' =&gt; 'UK',
                      'artist' =&gt; 'Bonnie Tyler',
                      'price' =&gt; '10.0',
                      'title' =&gt; 'Hide your heart'
                    },
                    {
                      'country' =&gt; 'CHN',
                      'artist' =&gt; 'Dolly Parton',
                      'price' =&gt; '9.99',
                      'title' =&gt; 'Greatest Hits'
                    },
                    {
                      'country' =&gt; 'USA',
                      'artist' =&gt; 'Say Hello',
                      'price' =&gt; '0001',
                      'title' =&gt; 'Hello'
                    }
                  ]
        };

D:\learning\perl&gt;
</pre>
<p>References:</p>
<p>http://www.go4expert.com/forums/showthread.php?t=812</p>
<p>Tips:</p>
<p>http://www.perlmonks.org/index.pl?node_id=218480</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/06/how-to-parse-multi-record-xml-file-ues-xmlsimple-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Practice Scripts Collection</title>
		<link>http://www.nanohe.net/blog/2010/06/318/</link>
		<comments>http://www.nanohe.net/blog/2010/06/318/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 04:57:32 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[regexp]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/?p=318</guid>
		<description><![CDATA[test1.pl

#!/usr/bin/perl -w
use strict;
use warnings;

use Data::Dumper;

my $s;

$s=&#34;status MaterializeU4&#34;;

print (($s =~ /s\s.*?((MaterializeU4)?)/) ? &#34;Match\n&#34; : &#34;No Match\n&#34;);

$s=&#34;status MaterializeU4&#34;;

print (($s =~ /s\s.*?((MaterializeU4)?)/) ? &#34;Match\n&#34; : &#34;No Match\n&#34;);

$s=&#34;statusaa dMaterializeU4&#34;;

print (($s =~ /s\s.*?((MaterializeU4)?)/) ? &#34;Match\n&#34; : &#34;No Match\n&#34;);

$s=&#34;status &#60; MaterializeU4&#62;&#34;;

print (($s =~ /s\s.*?((MaterializeU4)?)/) ? &#34;Match\n&#34; : &#34;No Match\n&#34;);

$s=&#34;status VIDNAME9000 = &#60;U4 MaterializeU4()&#62;&#34;;

print (($s =~ /s\s.*?((MaterializeU4)?)/) ? &#34;Match\n&#34; : &#34;No Match\n&#34;);

# [...]]]></description>
			<content:encoded><![CDATA[<p><strong>test1.pl</strong></p>
<pre class="brush: perl;">
#!/usr/bin/perl -w
use strict;
use warnings;

use Data::Dumper;

my $s;

$s=&quot;status MaterializeU4&quot;;

print (($s =~ /s\s.*?((MaterializeU4)?)/) ? &quot;Match\n&quot; : &quot;No Match\n&quot;);

$s=&quot;status MaterializeU4&quot;;

print (($s =~ /s\s.*?((MaterializeU4)?)/) ? &quot;Match\n&quot; : &quot;No Match\n&quot;);

$s=&quot;statusaa dMaterializeU4&quot;;

print (($s =~ /s\s.*?((MaterializeU4)?)/) ? &quot;Match\n&quot; : &quot;No Match\n&quot;);

$s=&quot;status &lt; MaterializeU4&gt;&quot;;

print (($s =~ /s\s.*?((MaterializeU4)?)/) ? &quot;Match\n&quot; : &quot;No Match\n&quot;);

$s=&quot;status VIDNAME9000 = &lt;U4 MaterializeU4()&gt;&quot;;

print (($s =~ /s\s.*?((MaterializeU4)?)/) ? &quot;Match\n&quot; : &quot;No Match\n&quot;);

# I inserted another one below
$s=&quot;status VIDNAME9000 = &lt;U4 MaterializeU4()&gt;&quot;;
print (($s =~ /^status .*?((MaterializeU4)?)/) ? &quot;Match\n&quot; : &quot;No Match\n&quot;);
</pre>
<p><strong>output</strong></p>
<pre class="brush: plain;">
Match
Match
No Match
Match
Match
Match
</pre>
<p><strong>test2.pl</strong></p>
<pre class="brush: perl;">
#!/usr/bin/perl -w
use strict;
use warnings;

use Data::Dumper;
my @all_lines = (
 &quot;s 1&quot;
,&quot;b 1&quot;
,&quot;&quot;
, &quot;status VIDNAME9000 = &lt;U4 MaterializeU4()&gt;&quot;
,&quot;b 2&quot;
,&quot;&quot;
, &quot;s 3&quot;
,&quot;b 3&quot;
,&quot;&quot;

);

while (@all_lines) {
    my @block = read_block();
    print Data::Dumper-&gt;Dump([\@block]);
}
exit 0;

# Read a constant definition block from a file handle.
# void return when there is no data left in the file.
# Empty return for skippable (Materialize4U) block!!!
# Otherwise return an array ref containing lines to in the block.
sub read_block {
    my @lines = ();
    my $block_started = 0;
    my $block_ignore = 0;
    while (my $line = shift @all_lines) {
        if ($line =~ /s\s.*?((MaterializeU4)?)/){
            $block_started = 1;   # why can't execute
            $block_ignore = 1 if $1; # or is it #1?
        }
        last if $line =~ /^\s*$/ &amp;&amp; $block_started;
        push @lines, $line unless $block_ignore;
    }
    return \@lines if @lines;
    return;
}
</pre>
<p><strong>output</strong></p>
<pre class="brush: plain;">
$VAR1 = [
          [
            's 1',
            'b 1'
          ]
        ];
$VAR1 = [
          [
            'status VIDNAME9000 = &lt;U4 MaterializeU4()&gt;',
            'b 2'
          ]
        ];
$VAR1 = [
          [
            's 3',
            'b 3'
          ]
        ];
</pre>
<p><strong>test3.pl</strong></p>
<pre class="brush: perl;">
#!/usr/bin/perl -w
use strict;
use warnings;

use Data::Dumper;
my @all_lines = (
 &quot;s 1&quot;
,&quot;b 1&quot;
,&quot;&quot;
, &quot;status VIDNAME9000 = &lt;U4 MaterializeU4()&gt;&quot;
,&quot;b 2&quot;
,&quot;&quot;
, &quot;s 3&quot;
,&quot;b 3&quot;
,&quot;&quot;

);

while (@all_lines) {
    my @block = read_block();
    print Data::Dumper-&gt;Dump([\@block]);
}
exit 0;

# Read a constant definition block from a file handle.
# void return when there is no data left in the file.
# Empty return for skippable (Materialize4U) block!!!
# Otherwise return an array ref containing lines to in the block.
sub read_block {
    my @lines = ();
    my $block_started = 0;
    my $block_ignore = 0;
    while (my $line = shift @all_lines) {
        if ($line =~ /^status .*?((MaterializeU4)?)/) {
            $block_started = 1;   # why can't execute
            $block_ignore = 1 if $1; # or is it #1?
        }
        last if $line =~ /^\s*$/ &amp;&amp; $block_started;
        push @lines, $line unless $block_ignore;
    }
    return \@lines if @lines;
    return;
}
</pre>
<p><strong>output</strong></p>
<pre class="brush: plain;">
$VAR1 = [
          [
            's 1',
            'b 1'
          ]
        ];
$VAR1 = [
          [
            'status VIDNAME9000 = &lt;U4 MaterializeU4()&gt;',
            'b 2'
          ]
        ];
$VAR1 = [
          [
            's 3',
            'b 3'
          ]
        ];
</pre>
<p>Why test2.pl, test3.pl can&#8217;t skip the 2nd block content? thanks.</p>
<p>test4.pl &#8211; final</p>
<pre class="brush: perl;">
#!/usr/bin/perl -w
use strict;
use warnings;

use Data::Dumper;
my @all_lines = (
 &quot;s 1&quot;
,&quot;b 1&quot;
,&quot;&quot;
, &quot;status VIDNAME9000 = &lt;U4 MaterializeU4()&gt;&quot;
,&quot;b 2&quot;
,&quot;&quot;
, &quot;s 3&quot;
,&quot;b 3&quot;
,&quot;&quot;

);

while (@all_lines) {
    my @block = read_block();
    print Data::Dumper-&gt;Dump([\@block]);
}
exit 0;

# Read a constant definition block from a file handle.
# void return when there is no data left in the file.
# Empty return for skippable (Materialize4U) block!!!
# Otherwise return an array ref containing lines to in the block.
sub read_block {
    my @lines = ();
    my $block_started = 0;
    my $block_ignore = 0;
    while (my $line = shift @all_lines) {
        # original expression as below comment.
        # if ($line =~ /status\s.*?((MaterializeU4)?)/){
        if ($line =~ /^status\s.*?((MaterializeU4))/){
            $block_started = 1;   # why can't execute
            $block_ignore = 1 if $1; # or is it #1?
        }
        last if $line =~ /^\s*$/ &amp;&amp; $block_started;
        push @lines, $line unless $block_ignore;
    }
    return \@lines if @lines;
    return;
}
</pre>
<p>output:</p>
<pre class="brush: plain;">
$VAR1 = [
          [
            's 1',
            'b 1'
          ]
        ];
$VAR1 = [];
$VAR1 = [
          [
            's 3',
            'b 3'
          ]
        ];
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/06/318/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The shift and unshift Operators</title>
		<link>http://www.nanohe.net/blog/2010/01/the-shift-and-unshift-operators/</link>
		<comments>http://www.nanohe.net/blog/2010/01/the-shift-and-unshift-operators/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 02:39:26 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/?p=287</guid>
		<description><![CDATA[The shift and unshift operators perform the corresponding actions on the &#8220;start&#8221; of the array (or the &#8220;left&#8221; side of an array, or the portion with the lowest subscripts).
push and pop operators do things to the &#8220;end&#8221; of an array(or the &#8220;right&#8221; sidce of an array).
The foreach control involved to the sample code below.

#!C:\Perl\bin\perl.exe
use strict;
use [...]]]></description>
			<content:encoded><![CDATA[<p>The shift and unshift operators perform the corresponding actions on the &#8220;start&#8221; of the array (or the &#8220;left&#8221; side of an array, or the portion with the lowest subscripts).<br />
push and pop operators do things to the &#8220;end&#8221; of an array(or the &#8220;right&#8221; sidce of an array).</p>
<p>The <strong>foreach</strong> control involved to the sample code below.</p>
<pre class="brush: perl;">
#!C:\Perl\bin\perl.exe
use strict;
use warnings;

my @array = qw# dino fred barney #;
# print @array;
foreach my $array (@array) {
$array = &quot;\t$array&quot;; # put a tab in front of each element of @rocks
$array.= &quot;\n&quot;; # put a newline on the end of each
print $array;
}

my $m = shift(@array); # $m gets &quot;dino&quot;, @array now has (&quot;fred&quot;, &quot;barney&quot;)
my $n = shift @array; # $n gets &quot;fred&quot;, @array now has (&quot;barney&quot;)
shift @array; # @array is now empty
# print a empty array
foreach my $array (@array) {
$array = &quot;\t$array&quot;; # put a tab in front of each element of @rocks
$array.= &quot;\n&quot;; # put a newline on the end of each
print $array; # nothing printed
}

my $o = shift @array; # $o gets undef, @array is still empty
unshift(@array, 5); # @array now has the one-element list (5)
unshift @array, 4; # @array now has (4, 5)
my @others = 1..3;
unshift @array, @others; # @array now has (1, 2, 3, 4, 5)
foreach my $array (@array) {
$array = &quot;\t$array&quot;; # put a tab in front of each element of @rocks
$array.= &quot;\n&quot;; # put a newline on the end of each
print $array;
}
</pre>
<p>Output:</p>
<pre class="brush: perl;">

D:\learning\perl&gt;hi.pl
        dino
        fred
        barney
        1
        2
        3
        4
        5

D:\learning\perl&gt;
</pre>
<p><em>- from Learning Perl 5E</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/01/the-shift-and-unshift-operators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XAMPP for windows</title>
		<link>http://www.nanohe.net/blog/2010/01/xampp-for-windows/</link>
		<comments>http://www.nanohe.net/blog/2010/01/xampp-for-windows/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 16:32:21 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[localhost]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/?p=285</guid>
		<description><![CDATA[new version of XAMPP 1.7.3, including:
Apache 2.2.14 (IPv6 enabled) + OpenSSL 0.9.8l
MySQL 5.1.41 + PBXT engine
PHP 5.3.1
phpMyAdmin 3.2.4
Perl 5.10.1
FileZilla FTP Server 0.9.33
Mercury Mail Transport System 4.72
Download and Install XAMPP 1.7.3
Destination folder: c:\
The perl cgi script could located in
C:\xampp\htdocs\hello.cgi (or hello.pl) recommend.
C:\xampp\cgi-bin\hello.cgi (or hello.pl)
Link: http://www.apachefriends.org/en/xampp-windows.html
]]></description>
			<content:encoded><![CDATA[<p>new version of <strong>XAMPP 1.7.3</strong>, including:<br />
Apache 2.2.14 (IPv6 enabled) + OpenSSL 0.9.8l<br />
MySQL 5.1.41 + PBXT engine<br />
PHP 5.3.1<br />
phpMyAdmin 3.2.4<br />
Perl 5.10.1<br />
FileZilla FTP Server 0.9.33<br />
Mercury Mail Transport System 4.72</p>
<p>Download and Install XAMPP 1.7.3<br />
Destination folder: <strong>c:\</strong></p>
<p>The perl cgi script could located in<br />
C:\xampp\htdocs\hello.cgi (or hello.pl) <em>recommend.</em><br />
C:\xampp\cgi-bin\hello.cgi (or hello.pl)</p>
<p>Link: http://www.apachefriends.org/en/xampp-windows.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/01/xampp-for-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beginning Perl and MySQL Tutorial</title>
		<link>http://www.nanohe.net/blog/2010/01/beginning-perl-and-mysql-tutorial/</link>
		<comments>http://www.nanohe.net/blog/2010/01/beginning-perl-and-mysql-tutorial/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 07:41:22 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/?p=276</guid>
		<description><![CDATA[Step1.
Download &#038; install MySQL.
mysql-essential-5.1.36-win32.zip
Download Link: http://download.cnet.com
Step2.
Setting a root password for MySQL
1. Start your command line by going to the Start Menu > Run and typing cmd (or type command if you are using an older version of windows)
2. Change directory to where you installed mysql to:
C:\> cd C:\mysql\bin 
3. Switch to mysql command line:
C:\mysql\bin> mysql [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Step1.</strong><br />
<strong>Download &#038; install MySQL.</strong><br />
mysql-essential-5.1.36-win32.zip<br />
Download Link: http://download.cnet.com</p>
<p><strong>Step2.</strong><br />
<strong>Setting a root password for MySQL</strong><br />
1. Start your command line by going to the Start Menu > Run and typing cmd (or type command if you are using an older version of windows)<br />
2. Change directory to where you installed mysql to:</p>
<blockquote><p>C:\> cd C:\mysql\bin </p></blockquote>
<p>3. Switch to mysql command line:</p>
<blockquote><p>C:\mysql\bin> mysql -u root mysql</p></blockquote>
<p>4. Then set a default password:</p>
<blockquote><p>mysql> SET PASSWORD FOR root@localhost=PASSWORD(&#8216;newpass&#8217;);</p></blockquote>
<p>where &#8220;<strong>newpass</strong>&#8221; is the password you want to use </p>
<p><strong>Adding more users</strong><br />
Start your command line by going to the Start Menu > Run and typing cmd (or type command if you are using an older version of windows)<br />
Change directory to where you installed mysql to:</p>
<blockquote><p>C:\> cd C:\mysql\bin </p></blockquote>
<p>Switch to mysql command line (if you have not set a root password remove the -p switch when you type it in):</p>
<blockquote><p>C:\mysql\bin> mysql -u root -p mysql </p></blockquote>
<p>Then then add your new user:</p>
<blockquote><p>mysql> GRANT ALL PRIVILEGES ON *.* TO rachel@localhost IDENTIFIED BY &#8217;summer&#8217;;</p></blockquote>
<p>where &#8220;<strong>rachel</strong>&#8221; is the username and &#8220;<strong>summer</strong>&#8221; is the password you want to use. You can also limit users to specific database, allow only certain remote hosts to connect all using the GRANT statement. However, that is outside the scope of this tutorial so search for more info on using GRANT if you are interested in those features. </p>
<p><em>- from www.ricocheting.com</em></p>
<p><strong>Step3.</strong><br />
let&#8217;s create a database called perltest and in that database, we will create a simple table called samples and populate it with some data. Here is the SQL you&#8217;ll need to create the table and fill in a few records, just connect to your MySQL database and run them. </p>
<pre class="brush: perl;">
CREATE DATABASE perltest;
USE perltest;
CREATE TABLE samples (
id int(10) unsigned NOT NULL auto_increment,
name varchar(128) NOT NULL default '',
phone varchar(128) NOT NULL default '',
PRIMARY KEY (id)
);
INSERT INTO samples VALUES (1, 'Some Person', '555-5555');
INSERT INTO samples VALUES (2, 'Another Person', '222-2222');
</pre>
<p><strong>Step4. </strong><br />
Sample Script</p>
<pre class="brush: perl;">
#!/usr/bin/perl -w

use strict;
use warnings;
use DBI;

my $dbh = DBI-&gt;connect('dbi:mysql:perltest','root','myroot')
or die &quot;Connection Error: $DBI::errstr\n&quot;;
my $sql = &quot;select * from samples&quot;;
my $sth = $dbh-&gt;prepare($sql);
$sth-&gt;execute
or die &quot;SQL Error: $DBI::errstr\n&quot;;
while (my @row = $sth-&gt;fetchrow_array) {
print &quot;@row\n&quot;;
}
</pre>
<p><strong>Dissection.</strong></p>
<pre class="brush: perl;">
$dbh = DBI-&gt;connect('dbi:mysql:DATABASE_NAME', USERNAME, PASSWORD)&lt;/blockquote&gt;
</pre>
<p>The <strong>die</strong> option provides an alternative to the program simply not working if a connection is not established. Basically, the connect it tried, and if it fails, your script will die and display an error message that should help you debug. Once we&#8217;ve established a connection to the MySQL database, we will need to create a string of SQL and then prepare it to query the database.</p>
<pre class="brush: perl;">
$sql = &quot;select * from samples&quot;;
$sth = $dbh-&gt;prepare($sql);
</pre>
<p>Next we query the database with our prepared SQL query, or exit the program and display some debugging information if the MySQL query fails to execute. </p>
<pre class="brush: perl;">
$sth-&gt;execute
or die &quot;SQL Error: $DBI::errstr\n&quot;;
</pre>
<p>Finally we use the fetchrow_array function to fetch each row of the results from the MySQL database and print them one to a line. </p>
<pre class="brush: perl;">
while (@row = $sth-&gt;fetchrow_array) {
print &quot;@row\n&quot;;
}
</pre>
<p>If the program is successful, you should see the following output:</p>
<pre class="brush: perl;">
1 Some Person 555-5555
2 Another Person 222-2222
</pre>
<p><em>- from perl.about.com</em></p>
<p><strong>[Tips]</strong><br />
DBD-mysql<br />
I run the script using ActivePerl 5.10.1 on Winxp.<br />
The <strong>DBD-mysql </strong> package didn&#8217;t installed by default. You need install it via Perl Package Manager.<br />
More about DBD-mysql<br />
A MySQL driver for the Perl5 Database Interface (DBI)<br />
	Version:	4.011<br />
	Released:	2009-04-14<br />
	Author:	Patrick Galbraith
<patg@patg.net>
	CPAN:	http://search.cpan.org/dist/DBD-mysql-4.011/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/01/beginning-perl-and-mysql-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The each Function</title>
		<link>http://www.nanohe.net/blog/2010/01/the-each-function/</link>
		<comments>http://www.nanohe.net/blog/2010/01/the-each-function/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 09:09:01 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/?p=265</guid>
		<description><![CDATA[If you wish to iterate over (that is, examine every element of) an entire hash, one of the usual ways is to use the each function, which returns a key-value pair as two-element list.

#!C:\Perl\bin\perl.exe
use strict;
use warnings;

# declare a new hash
my %some_hash;

%some_hash = (&#34;foo&#34;, 35, &#34;bar&#34;, 12.4, 2.5, &#34;hello&#34;,
      &#34;wilma&#34;, 1.72e30, [...]]]></description>
			<content:encoded><![CDATA[<p>If you wish to iterate over (that is, examine every element of) an entire hash, one of the usual ways is to use the each function, which returns a key-value pair as two-element list.</p>
<pre class="brush: perl;">
#!C:\Perl\bin\perl.exe
use strict;
use warnings;

# declare a new hash
my %some_hash;

%some_hash = (&quot;foo&quot;, 35, &quot;bar&quot;, 12.4, 2.5, &quot;hello&quot;,
      &quot;wilma&quot;, 1.72e30, &quot;betty&quot;, &quot;bye&quot;);

my $key;
my $value;

while ( ($key, $value) = each %some_hash)
{
  print &quot;$key =&gt; $value\n&quot;;
}

print &quot;\n&quot;;
foreach $key (sort keys %some_hash) {
  $value = $some_hash{$key};
  print &quot;$key =&gt; $value\n&quot;;
  # Or, we could have avoided the extra $value variable:
  #  print &quot;$key =&gt; $hash{$key}\n&quot;;
}
</pre>
<p>Output</p>
<pre class="brush: perl;">
betty =&gt; bye
bar =&gt; 12.4
wilma =&gt; 1.72e+030
foo =&gt; 35
2.5 =&gt; hello

2.5 =&gt; hello
bar =&gt; 12.4
betty =&gt; bye
foo =&gt; 35
wilma =&gt; 1.72e+030
</pre>
<p><em>-from Learning Perl 5E</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/01/the-each-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Hash As a Whole</title>
		<link>http://www.nanohe.net/blog/2010/01/the-hash-as-a-whole/</link>
		<comments>http://www.nanohe.net/blog/2010/01/the-hash-as-a-whole/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 09:01:05 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/?p=262</guid>
		<description><![CDATA[The order is jumbled because Perl keeps the key-value pairs in an order that’s conven-
ient for Perl so that it can look up any item quickly. 
Elements of a hash are printed out in their internal order, which can not be relied upon and will change as elements are added and removed. If you need [...]]]></description>
			<content:encoded><![CDATA[<p>The order is jumbled because Perl keeps the key-value pairs in an order that’s conven-<br />
ient for Perl so that it can look up any item quickly. </p>
<p>Elements of a hash are printed out in their internal order, which can not be relied upon and will change as elements are added and removed. If you need all of the elements of a hash in some sort of order, sort the keys, and use that list to index the hash. </p>
<p>If you are looking for a structure that holds its elements in order, either use an array, or use one of the ordered hash&#8217;s on CPAN.</p>
<p>the only ordering you can rely upon from a list context hash expansion is that key => value pairs will be together.</p>
<p>use the keys function to get a list of the keys. They will most likely be in the same order as they&#8217;re stored in the hash itself, although there&#8217;s no guarantee. If the order matters, then you either shouldn&#8217;t be using a hash in the first place, or you should use the keys function to get a list, put the items in the desired order, and then loop through that list, accessing each corresponding hash item.</p>
<pre class="brush: perl;">
#!C:\Perl\bin\perl.exe
use strict;
use warnings;

# declare a new hash
my %some_hash;

%some_hash = (&quot;foo&quot;, 35, &quot;bar&quot;, 12.4, 2.5, &quot;hello&quot;,
      &quot;wilma&quot;, 1.72e30, &quot;betty&quot;, &quot;bye&quot;);

my @any_array;
@any_array = %some_hash;

print %some_hash;
print &quot;\n&quot;;
print &quot;\n&quot;;
print @any_array;
print &quot;\n&quot;;
print &quot;\n&quot;;

my @keys;
@keys = keys %some_hash;
for my $k (sort @keys)
{
    print $k, $some_hash{$k};
}
print &quot;\n&quot;;
print &quot;\n&quot;;
print map {$_, $some_hash{$_}} sort keys %some_hash;
</pre>
<p>Output</p>
<pre class="brush: perl;">

D:\learning\perl&gt;test.pl
bettybyebar12.4wilma1.72e+030foo352.5hello

bettybyebar12.4wilma1.72e+030foo352.5hello

2.5hellobar12.4bettybyefoo35wilma1.72e+030

2.5hellobar12.4bettybyefoo35wilma1.72e+030
D:\learning\perl&gt;
</pre>
<p><em>-from StackOverflow.com</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/01/the-hash-as-a-whole/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hash Element Access</title>
		<link>http://www.nanohe.net/blog/2010/01/hash-element-access/</link>
		<comments>http://www.nanohe.net/blog/2010/01/hash-element-access/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 06:28:06 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/?p=257</guid>
		<description><![CDATA[
#!C:\Perl\bin\perl.exe
use strict;
use warnings;

# declare a new hash
my %family_name;

# Initial hash.
# Compared to array access, we use curly braces instead of square brackstes around the subscript(key)
$family_name{&#34;fred&#34;} = &#34;flintstone&#34;;
$family_name{&#34;barney&#34;} = &#34;rubble&#34;;

# print the Values
print $family_name{&#34;fred&#34;};
print &#34;\n&#34;;
print $family_name{&#34;barney&#34;};
print &#34;\n&#34;;

# the hash key maybe any expression. not just the literal strings and simple scalar variables
my $foo = &#34;bar&#34;;
print $family_name{ [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: perl;">
#!C:\Perl\bin\perl.exe
use strict;
use warnings;

# declare a new hash
my %family_name;

# Initial hash.
# Compared to array access, we use curly braces instead of square brackstes around the subscript(key)
$family_name{&quot;fred&quot;} = &quot;flintstone&quot;;
$family_name{&quot;barney&quot;} = &quot;rubble&quot;;

# print the Values
print $family_name{&quot;fred&quot;};
print &quot;\n&quot;;
print $family_name{&quot;barney&quot;};
print &quot;\n&quot;;

# the hash key maybe any expression. not just the literal strings and simple scalar variables
my $foo = &quot;bar&quot;;
print $family_name{ $foo . &quot;ney&quot; };  # prints &quot;rubble&quot;
print &quot;\n&quot;;

# Stuff $person and as the Keys for hash.
foreach my $person (qw&lt; barney fred &gt;) {
  print &quot;I've heard of $person $family_name{$person}.\n&quot;;
}
</pre>
<p>Output</p>
<pre class="brush: perl;">
flintstone
rubble
rubble
I've heard of barney rubble.
I've heard of fred flintstone.
</pre>
<p><em>- from Learning Perl 5E</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/01/hash-element-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The pop and push Operators</title>
		<link>http://www.nanohe.net/blog/2010/01/the-pop-and-push-operators/</link>
		<comments>http://www.nanohe.net/blog/2010/01/the-pop-and-push-operators/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 13:55:39 +0000</pubDate>
		<dc:creator>nano</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.nanohe.net/blog/?p=249</guid>
		<description><![CDATA[The pop operator takes the last element off of an array and returns it;
The converse operation is push, which adds and element (or a list of elements) to the end of array.
The first argument to push or the only argument for pop must be an array variable &#8211; pushing and poping would not make sense [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>pop</strong> operator takes the last element off of an array and returns it;</p>
<p>The converse operation is <strong>push</strong>, which adds and element (or a list of elements) to the end of array.</p>
<p>The first argument to push or the only argument for pop must be an array variable &#8211; pushing and poping would not make sense on a literal list.</p>
<pre class="brush: perl;">
#!C:\Perl\bin\perl.exe
use strict; # enabled
use warnings; 

my @array; 

@array  = 5..9;
my $fred   = pop(@array);  # $fred gets 9, @array now has (5, 6, 7, 8 )
my $barney = pop @array;   # $barney gets 8, @array now has (5, 6, 7)
pop @array;             # @array now has (5, 6). (The 7 is discarded.)

print $fred;
print &quot;\n&quot;;
print $barney;
print &quot;\n&quot;;
print @array;
print &quot;\n&quot;;

my @others;
push(@array, 0);      # @array now has (5, 6, 0)
push @array, 8;       # @array now has (5, 6, 0, 8 )
push @array, 1..10;   # @array now has those ten new elements
@others = qw/ 9 0 2 1 0 /;
push @array, @others; # @array now has those five new elements (19 total)

print @others;
print &quot;\n&quot;;
print @array;
</pre>
<p>Output</p>
<pre class="brush: perl;">
9
8
56
90210
56081234567891090210
</pre>
<p><em>- from Learning Perl 5E</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nanohe.net/blog/2010/01/the-pop-and-push-operators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
