<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, "Emmanuel Mejias" <emmanuel.mejias@gmail.com> 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>
<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 (@). An array being a list a, b, c, d where a hash can be though of as a label value pair 1 => apple, 2 => banana, 3 => grape. 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>
'SHELL',<BR>
'HOSTNAME',<BR>
'TERM',<BR>
'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 = ( ‘USER’ => ‘SHELL’,<BR>
‘HOSTNAME’ => ‘TERM’,<BR>
‘HOME’ => ‘’):<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>
'USER' => '',<BR>
'SHELL' => '',<BR>
'HOSTNAME' => '',<BR>
'TERM' => '',<BR>
'HOME' => ''<BR>
);<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>
$env{$key} = $ENV{$key};<BR>
}<BR>
<BR>
#--- print out the labels and values<BR>
#-- in the %env hash<BR>
foreach $key ( sort keys %env) {<BR>
print "$key $env{$key}\n";<BR>
}<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>