<br><br>
<div><span class="gmail_quote">On 9/19/07, <b class="gmail_sendername">Andrew Moore</b> &lt;<a href="mailto:amoore@mooresystems.com">amoore@mooresystems.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">On Wed, Sep 19, 2007 at 10:06:18AM -0500, Emmanuel Mejias wrote:<br>&gt; In this exercise the instructor was asking that I use the pre-defined
<br>&gt; environment variable hash that is discussed in this lesson, which is print<br>&gt; %ENV; so that is why I created the script as a hash originally. I&#39;m just<br>&gt; confused as to why it only prints out 3 and skips every other one.
<br><br>%ENV is already defined to contain a hash of things like:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;PWD&#39; =&gt; &#39;/home/amoore&#39;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;LANG&#39; =&gt; &#39;en_US&#39;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;USER&#39; =&gt; &#39;amoore&#39;,
<br><br>It&#39;s pretty much always defined when perl is running, so you don&#39;t<br>have to define it yourself or anything.<br><br>And so you can certainly print stuff out of it as it sounds like your<br>instructor asked you to.
<br><br>print &quot;HOME is: $ENV{&#39;HOME&#39;}\n&quot;;<br><br>Or, you could walk through a list of terms to print out:<br><br>foreach my $key qw( HOME USER TERM ) {<br>&nbsp;&nbsp; print &quot;$key is set to: $ENV{$key}\n&quot;;
<br>}<br><br>You can even define that list of keys in advance:<br><br>my @keys = qw( HOME USER TERM );<br>foreach my $key ( @keys ) {<br>&nbsp;&nbsp; print &quot;$key is set to: $ENV{$key}\n&quot;;<br>}<br><br>Or, you could walk through each of the keys in the hash and print out
<br>the values in order to get them all (especially if you didn&#39;t know<br>what keys may be in there when you wrote the program):<br><br>foreach my $key ( keys %ENV ) {<br>&nbsp;&nbsp; print &quot;$key is set to: $ENV{$key}\n&quot;;
<br>}<br><br>It appears that you were trying to create a list of keys, like: my<br>@keys = qw( HOME USER TERM ); but using a hash. That&#39;s probably not a<br>good use of a hash, as you&#39;re discovering.<br><br>Hope this helps a bit, please ask more and show us your code if not.
<br><br>-Andy<br><br>_______________________________________________<br>kc mailing list<br><a href="mailto:kc@pm.org">kc@pm.org</a><br><a href="http://mail.pm.org/mailman/listinfo/kc">http://mail.pm.org/mailman/listinfo/kc
</a><br></blockquote></div>
<div><br>That worked great, Andrew! Thanks! I added my sort and two extra lines so it does what it&#39;s suppose to do and&nbsp; prints out&nbsp;envirnoment variables that I was asking it to print. here is my end result:</div>
<div>&nbsp;</div>
<div>#!/usr/bin/perl -w</div>
<div>&nbsp;</div>
<div>@key = qw(SHELL USER LANG HOSTNAME TERM HOME);</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp; foreach my $key (sort(keys %ENV)){</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach $check (@key){</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($key eq $check){</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;$key: $ENV{$key}\n&quot;;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div>}</div>