Okay I'll give that a try. I think that he wanted us to use the hash that was in the lesson. thanks again!<br><br>
<div><span class="gmail_quote">On 9/18/07, <b class="gmail_sendername">Frank Wiles</b> <<a href="mailto:frank@wiles.org">frank@wiles.org</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">On Tue, 18 Sep 2007 13:48:02 -0500<br>"Emmanuel Mejias" <<a href="mailto:emmanuel.mejias@gmail.com">
emmanuel.mejias@gmail.com</a>> wrote:<br><br>> Cool! Thanks all for the feeback and links. I've hit a few of those<br>> in the past as well. I'm like John as well, I need to do it to learn<br>> it. I've been in the BASH world so a lot of this stuff is new to me
<br>> and I'm trying to relate how some of the things you can do in Bash<br>> how they work in Perl.<br>><br>> Well here goes. I just recently started taking an online course in<br>> Perl and I've also been using Perl by Example book as a reference. In
<br>> one of my exercises I have to write a script that prints out a sorted<br>> list of environment variables. Well for some reason it is only<br>> printing out 3 of the 5 that I specified. It doesn't matter what
<br>> order I put the environment variables in, it just prints out every<br>> other one. In this case it prints out HOME, HOSTNAME and USER, but<br>> leaves out TERM and SHELL. What am I not doing right in my code?
<br>><br>> #!/usr/bin/perl<br>><br>> %env = ('USER',<br>> 'SHELL',<br>> 'HOSTNAME',<br>> 'TERM',<br>> 'HOME');<br>><br>> foreach $key (sort(keys(%env))){
<br>> print "$env $ENV{$key}\n";<br>> }<br>> Thoughts?<br><br>You're using a hash like an array when you shouldn't be:<br><br>What that is doing is creating this:<br><br>$env{USER} = 'SHELL';
<br>$env{HOSTNAME} = 'TERM';<br>$env{HOME} = '';<br><br>Do this instead:<br><br>my @envs = qw( USER SHELL HOSTNAME TERM HOME );<br><br>foreach my $env ( @envs ) {<br> print "$env $ENV{$env}\n";
<br>}<br><br>-------------------------------------------------------<br> Frank Wiles, Revolution Systems, LLC.<br> Personal : <a href="mailto:frank@wiles.org">frank@wiles.org</a> <a href="http://www.wiles.org">http://www.wiles.org
</a><br> Work : <a href="mailto:frank@revsys.com">frank@revsys.com</a> <a href="http://www.revsys.com">http://www.revsys.com</a><br><br></blockquote></div><br>