in reply to List Values As Multidimensional Hash Keys

Something like this?:
use strict; use warnings; my $a = 'a1:a2:a3=foo'; my ($key, $val) = split /=/, $a, 2; $key =~ s/:/}{/g; my %hash; eval "\$hash{$key}=\"$val\"";

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re: Re: List Values As Multidimensional Hash Keys
by tachyon (Chancellor) on Mar 15, 2004 at 00:30 UTC

    Leving aside the fact that this does not compile under strict as you don't declare %hash, this is a security hole just waiting for a cracker.The string form of eval is *dangerous*, don't use it until after you understand why. Here is a hint....

    use strict; use warnings; my %hash; my $a = '1};print "You have just been cracked!\n";#a1:a2:a3=foo'; my ($key, $val) = split /=/, $a, 2; $key =~ s/:/}{/g; eval "\$hash{$key}=\"$val\""; __END__ You have just been cracked!

    The print could be any arbitrary code. unlink, rm, shutdown....*any* code, running with the perms of whoever started the script.

    cheers

    tachyon

•Re: Re: List Values As Multidimensional Hash Keys
by merlyn (Sage) on Mar 14, 2004 at 23:44 UTC
      Your post has been downvoted. Please don't malform internal links again (you see, manually editing the URI is just sooooo incredibly difficult). Of course I am entirely kidding.