Tie::IxHash::Easy with "eval()"

PERL

    Next

  • 1. neuronal pattern / network
    hello, does anybody of you have had the opportunity to program a neuronal pattern / network in perl? has anybody some hints for me where to find some info about that? thanks, stefan
  • 2. Help with encrypt password and uid.
    Now I want to write one CGI(Perl) program. User will login to a web page, and have to enter a user id and password(Inlcuding registering). And submit to Server. Then I need encrypt the UID and password. In server, I get the encrypted msg and then decode the msg to get UID and password. How should I do? Is there some document for this? Thank you! Franklin
  • 3. how to automate webpage interaction?
    Dear all, I try to use Perl to automating the log-on process to 'mail.yahoo.com' webpage. Here is my program: --------------------------------------------------- use Clone; use WWW::Automate; my $agent = WWW::Automate->new(); $url='mail.yahoo.com'; $agent->get($url); #$agent->follow($link); $agent->form(2); $agent->field($name, $value); $agent->click($button); $agent->back(); $agent->add_header($name => $value); print "OK" if $agent->{content} =~ /$expected/; ----------------------------------------------------------- However, it gives error message that "there is no form number 2"... Can anybody tell me what is the form number of that "login" and "passwd" field in "mail.yahoo.com"? And how to find it out? Thanks a lot, -Walala
  • 4. Help using Getopt::Mixed
    I'm trying to add a usage message to a script that uses Getopt::Mixed. I want to print this message whenever a bad commnad line option is passed to the script. I' using the module like this: use Getopt::Mixed "nextOption" ; Getopt::Mixed::init('F i e f=s d:i debug:i configfile=s'); my $badOption = \&print_usage; while (($option, $value, $pretty) = nextOption()) { if(( $option eq 'f') || ( $option eq 'configfile' )) I just added the "print_usage" line, based upon my reading of the perldoc page on this module, but it's not calling the print_usage() function (which is defiend earlier in the script, when I pass it an undefined argument (-Z for instance). Instead, I get the following generic error mesage: webcam.pl: unrecognized option `-Z' What am I doing wrong here? -- "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin

Tie::IxHash::Easy with "eval()"

Postby Pat » Thu, 07 Feb 2008 09:07:06 GMT

Hi,

I'd like to use "Tie::IxHash" to maintain the order of keys in a hash.  
Since the hash can contain other hashes (and so on), I need to use 
"Tie::IxHash::Easy" so that the nested hashes also maintain their ordering.

I'm reading the entire hash from a file.  The format of the file is exactly 
like Data::Dumper so that I can build the hash by simply saying:

   eval($file_contents);

This fails because there's no way to "tie" the internal workings of eval to 
"Tie::IxHash::Easy" so it always just returns a normal hash.  Copying the 
returned into an IxHash has no effect because the ordering is already lost.

So, how can I load an IxHash from a file in Data::Dumper format and 
preserve its order (including nested hashes)?

Thanks.   

Similar Threads:

1.Howto reverse SortByValue with Tie::IxHash

Hi,

I have a problem using Tie::IxHash.
My question is how can I sort the hash
by value in descending order.

I tried this to get the descending order,
but doesn't seem to work:

__BEGIN__
my %hash =(
            '1-1' => 3,
            '2-3' => 2,
            '2-2' => 1,
            '1-2' => 6,
            '1-3' => 3
          );
my $t = Tie::IxHash->new(%hash);
$t->SortByValue;  # ascending, ok!

$t->$hash{$b}<=>$hash{$a}SortByValue; #tried this but doesn't work

__END__

Can anybody advice how to go about this?
Thanks beforehand.

Regards,
Edward WIJAYA
SINGAPORE

2.Reverse SortByValue with Tie::IxHash

Hi,

I am a newbie in using Perl Module
especially it's OO method.

I have a problem using Tie::IxHash.
My question is how can I sort the hash
by value in desending order.

e.g:
$t->SortByValue;  # ascending

I tried this to get the descending order, but doesn't seem to work:
$t->$hash{$b}<=>$hash{$a}SortByValue;

Please kindly advice, how can I go about it.

This is the hash, by the way:

my %hash =(
            '1-1' => 3,
            '2-3' => 2,
            '2-2' => 1,
            '1-2' => 6,
            '1-3' => 3
          );


Thanks beforehand.

Regards,
Edward WIJAYA
SINGAPORE

3.Using Tie::IxHash order a hash reference

Hi, 
How can I order the entries in a hash if I use a reference to a hash
instead of a hash. For e.g.

$ref={
key=>"value",
};

instead of

%ref=(
key=>"value",
);

Thanks!

4.maintaining order in a hash (without Tie::IxHash)

Many times, there exists a module on CPAN that solves a problem I'm
attempting to solve.
I'm aware that generally the better choice to solving such a problem
is to use the CPAN module.
However, regarding the problem of maintaining sort order of a hash,
and the Tie::IxHash module, I have a question.

I've heard that Tie::IxHash can be a little slow, and the cost of
using this in addition to installation costs (where developers don't
have the permission to have modules installed, especially across all
environments, and the process for having the module(s) installed by
admins can be trying to say the least) is much higher than the simple
solution of adding an extra sortval attribute to a hash value, where
the value of sortval is simply an incremented counter.

then if you need to access the hash in the order in which items were
inserted, you could simply:

for my $key ( sort { $hash{$a}{sortval} <=> $hash{$b}{sortval} } keys
%hash ) {
    # do something
}


Is there something wrong with my reasoning? Would this solution be a
good candidate for addition into the FAQ How can I make my hash
remember the order I put elements
          into it?


5.Different behavior between eval "07" and eval "08"

eval "07" gets 7 but eval "08" gets an undefined value.  I tested perl
5.8.8 on fedora 8 and ubuntu.

Is there any difference between those two eval statements?  Is this a
bug?

6. Chaining a Tie::File to a Tie::Tk::Listbox

7. tie() with DB_File not tie()ing ?

8. Is Tie::CSV_File dependable on Tie:File



Return to PERL

 

Who is online

Users browsing this forum: No registered users and 7 guest