in reply to uninitialized value in phonebook program

If you think about it for a second, /^0$/ is really the same thing as == 0 eq '0' (thanks chipmunk!) ... here is some code for you to meditate upon:
use strict; my $name = 'school&0'; my ($first,$last) = $name =~ /(.+)&(.+)/; print "$first:$last\n"; print "== is true\n" if $last == 0; print "eq is true\n" if $last eq '0'; print "=~ is true\n" if $last =~ /^0$/;

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: uninitialized value in phonebook program
by smgfc (Monk) on Feb 25, 2002 at 04:58 UTC
    update: you are totally right however, about using eq '0', i should have read your node a little more closely! sorry :)

    the problem with using == instead of /^0$/ is that what if the input is "william&meyer" instead of "school&0"? if you use == on meyer ($2) then you get a warning about context (== on a string), whereas if you use /^0$/ you dont have to worry about wether $2 is a string (meyer) or a number (0)