On Mon, Jun 16, 2003 at 10:03:50PM -0700 Richard Heintze wrote: > Why does this program print "yes def" but not "yes > xyz"? It does print "xyz:def", so I don't understand > why it does not print "yes xyz". > > { > my %x = ( xyx => 'abc', d => 'y', f => 'g' ); ^^^ > $x{"def"} = "fhi"; > print qq($_ : ).$x{$_}.qq(\n) foreach (keys %x); > foreach (keys %x) { print "yes xyz\n" if ($_ =~ > "xyz"); } ^^^ > foreach (keys %x) { print "yes def\n" if ($_ =~ > "def"); } > print $x{'xyz'}."\n"; ^^^ > }
Spot the difference? ;-) 'xyx' is not at all the same as 'xyz'. Other than that, two cosmetical things. You shouldn't pretend a pattern is a string. It's not. Correct would be ... if $_ =~ /xyz/; Secondly, this is sort of ugly and hard on the eyes: print qq($_ : ).$x{$_}.qq(\n) foreach (keys %x); Put it all into one string and let perl do the interpolation for you: print "$_: $x{ $_ }\n" foreach keys %x; Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]