Directory listing - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Directory listing

generalengeneralen Posts: 68Member
Hi Iam doing a litte shell in Perl..I have written this code..


#!/usr/bin/perl -w


print "$_=$ENV{$_}
" for sort keys %ENV;
chdir $ENV{'HOMEPATH'};


when I compile and execute this it lists a lot of things..Why doesent it just list exempel C:/documents and Settings ????

Please HELP!!!

Comments

  • JonathanJonathan Posts: 2,914Member
    : Hi Iam doing a litte shell in Perl..I have written this code..
    :
    :
    : #!/usr/bin/perl -w
    :
    :
    : print "$_=$ENV{$_}
    " for sort keys %ENV;
    : chdir $ENV{'HOMEPATH'};
    :
    :
    : when I compile and execute this it lists a lot of things..Why doesent it just list exempel C:/documents and Settings ????
    :
    Probably because your program asks for it to print loads of stuff, and not just the one of them. :-)

    : Please HELP!!!
    :
    Your program prints everything that is in the environment (all the stuff in %ENV). To write the code more verbosely...

    [code]my @evnNames = sort keys %ENV;
    foreach my $envName (@envNames) {
    print "$envName=$ENV{$envName}
    ";
    }[/code]

    %ENV is just a hash of all environment variables. To just print the HOMEPATH entry you'd do:-

    print $ENV{'HOMEPATH'};

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.