Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: Please don't use eval for this! (was Re: List Values As Multidimensional Hash Keys)

by ysth (Canon)
on Mar 15, 2004 at 01:07 UTC ( [id://336575] : note . print w/replies, xml ) Need Help??


in reply to Re: Please don't use eval for this! (was Re: List Values As Multidimensional Hash Keys)
in thread List Values As Multidimensional Hash Keys

Taking tachyon's sample code:
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!
You would replace the $key =~ s/:/... line with
use Data::Dumper; $Data::Dumper::Terse = 1; $Data::Dumper::Useqq = 1; $key = join '}{', Dumper split /:/, $key, -1;