perl sorting variables

Good morning!!

Im trying to practice withe Perl and sorting variables is not going good at all!

#!/usr/bin/perl

$username = $ENV {'LOGNAME'};
print "Hello, $username\n";

I want to add sort and 'mail' and 'home'. This below is what I have came up with,but of course its not working.

#!/usr/bin/perl

$username = $ENV (sort('LOGNAME'('HOME'('MAIL'))));
print "Hello, $username\n";

Any help is greatly appreciated!!

Ben

What do you mean by "I want to add sort and 'mail' and 'home'"? What should be the result of your operation? The three environment variables, concatenated in sorted order? Or something different?

Pludi,

Yes....The three environment variables, concatenated in sorted order?

I want the output to be:

Hello, (username)with MAIL, LOGNAME, HOME printed out on the screen.

Make sense?

Raven

**It doesnt have to be those 3 variables I chose, it can be any in the environment.

Sorted by the variable name:

$environ = join " ", map { $ENV{$_} } sort qw/LESS MAIL HOME/;

Sorted by the variable contents:

$environ = join " ", map { $ENV{$_} } sort { $ENV{$a} cmp $ENV{$b} } qw/LESS MAIL HOME/;

Pludi,

Im going to read some more about the $_, and " ". After I read more, if I have questions about your response.....Ill reply to this thread.

Thanks so much for your help!
Ben

Be sure to read (at least)
perldoc -f sort
perldoc -f join
perldoc -f map
perldoc perlintro
perldoc perlop
perldoc perlvar