<HTML>
<HEAD>
<TITLE>Re: [Kc] Perl Noob</TITLE>
</HEAD>
<BODY>
<FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'><BR>
<BR>
<BR>
On 9/19/07 10:06 AM, &quot;Emmanuel Mejias&quot; &lt;emmanuel.mejias@gmail.com&gt; wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'><BR>
Thanks for the feedback guys! Just to answer some questions out there, I am familiar with the -w switch as well as strict. The class that I am taking is through Oreilly Media and they use the <I>Learning Perl</I> book from Oreilly except that the instructor has not covered warnings or strict yet. Where as in the <I>Perl by Example</I> book that I was using prior to the class mentioned this early. <BR>
&nbsp;<BR>
In this exercise the instructor was asking that I use the pre-defined environment variable hash that is discussed in this lesson, which is </SPAN></FONT><SPAN STYLE='font-size:12.0px'><FONT COLOR="#0000FF"><FONT FACE="Courier, Courier New">print %ENV;</FONT></FONT><FONT FACE="Verdana, Helvetica, Arial"> so that is why I created the script as a hash originally. I'm just confused as to why it only prints out 3 and skips every other one. <BR>
<BR>
<BR>
</FONT></SPAN></BLOCKQUOTE><FONT SIZE="2"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:10.0px'><BR>
</SPAN></FONT></FONT><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>I think the main issue of confusion there is the difference between a hash (%) and an array (@). &nbsp;An array being a list a, b, c, d where a hash can be though of as a label value pair 1 =&gt; apple, 2 =&gt; banana, 3 =&gt; grape. &nbsp;So in your original program where you write this:<BR>
<BR>
</SPAN></FONT><FONT SIZE="2"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:10.0px'>%env = ('USER',<BR>
&nbsp;'SHELL',<BR>
&nbsp;'HOSTNAME',<BR>
&nbsp;'TERM',<BR>
&nbsp;'HOME');<BR>
<BR>
</SPAN></FONT></FONT><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>The way I would write what you are doing here is:<BR>
</SPAN></FONT><FONT SIZE="2"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:10.0px'><BR>
%env = ( &#8216;USER&#8217; =&gt; &#8216;SHELL&#8217;,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8216;HOSTNAME&#8217; =&gt; &#8216;TERM&#8217;,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8216;HOME&#8217; =&gt; &#8216;&#8217;):<BR>
<BR>
</SPAN></FONT></FONT><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>My translation of what you are trying to do is as follows<BR>
</SPAN></FONT><FONT SIZE="2"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:10.0px'><BR>
#!/usr/bin/perl<BR>
use warnings;<BR>
use strict;<BR>
<BR>
#--- Setup Hash<BR>
my %env = (<BR>
&nbsp;'USER' &nbsp;&nbsp;&nbsp;&nbsp;=&gt; '',<BR>
&nbsp;'SHELL' &nbsp;&nbsp;&nbsp;=&gt; '',<BR>
&nbsp;'HOSTNAME' =&gt; '',<BR>
&nbsp;'TERM' &nbsp;&nbsp;&nbsp;&nbsp;=&gt; '',<BR>
&nbsp;'HOME' &nbsp;&nbsp;&nbsp;&nbsp;=&gt; ''<BR>
&nbsp;&nbsp;);<BR>
<BR>
#--- Query environment variables in <BR>
#--- the actual %ENV hash and<BR>
#--- put the value in the bucket the<BR>
#--- label corresponds to in the %env hash<BR>
foreach $key ( sort keys %env) {<BR>
&nbsp;$env{$key} = $ENV{$key};<BR>
&nbsp;}<BR>
<BR>
#--- print out the labels and values<BR>
#-- in the %env hash<BR>
foreach $key ( sort keys %env) {<BR>
&nbsp;print &quot;$key $env{$key}\n&quot;;<BR>
&nbsp;}<BR>
<BR>
</SPAN></FONT></FONT><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>-- <BR>
Scott Kahler<BR>
Systems Engineer <BR>
uclick, LLC (an Andrews McMeel Universal Company)<BR>
scottk@uclick.com<BR>
www.uclick.com www.gocomics.com<BR>
</SPAN></FONT>
</BODY>
</HTML>