liri has asked for the wisdom of the Perl Monks concerning the following question:


I've got a hash which is %Login, it contains something
like the following pairs:

URL=http://123.456.789.0
username=admin
password=12345

On the other hand, there is the following structure:

$fields = { "username" => "admin", "password" => "12345" };

And now to the point - how do I take the hash, loop through
it and disregard only the URL entry in the hash.

Thanks.

Replies are listed 'Best First'.
Re: A little bit of help with hashes... (once again :) )
by ikegami (Patriarch) on Nov 11, 2005 at 00:15 UTC

    Faster and shorter:

    my $fields = { %Login }; delete $fields->{URL};
Re: A little bit of help with hashes... (once again :) )
by sauoq (Abbot) on Nov 11, 2005 at 00:39 UTC

    TIMTOWTDI...

    my $fields; @$fields{qw( username password )} = @Login{qw( username password )};
    Are you sure that you actually need to get rid of the extra key/value pair, though?

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: A little bit of help with hashes... (once again :) )
by kirbyk (Friar) on Nov 11, 2005 at 00:10 UTC
    I think you want to generate the hashref from the %Login hash.
    for my $key (keys %Login) { next if $key eq 'URL'; $fields->{$key'} = $Login{$key}; }
    Ta-da!

    -- Kirby, WhitePages.com