Re: mini-quiz
Abigail <[email protected]> Tue, 19 Jun 2007 07:47:48 +0200
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
--huq684BweRXVnRxX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 19, 2007 at 06:45:58AM +0800, Greg Matheson wrote: > On Mon, 18 Jun 2007, Yitzchak Scott-Thoennes wrote: >=20 > > Ovid, on perlmonks, asks[1] if this code is doing too much on one line: >=20 > > my $country =3D $card->country; > > $country =3D $country eq 'gbr' ? '' : uc "[$country]" if $country; >=20 > The problem is understanding what 'gbr' is and why you would want > to delete it. Great Britain, because that is the country the code > is running in? Alternatively, the problem is caused by a=20 > difficult branching. >=20 > my $country =3D $card->country; > $country =3D uc "[$country]" if $country; > $country =3D '' if $country eq '[GBR]'; This makes the assumption that '$card -> country' cannot return 'gbr' in another casing than all lowercase. (Making assumptions about the code, and never ever mentioning that assumption (probably because the author isn't aware their code doesn't run well without the assumption) is very common on Perlmonks).=20 So, if '$card -> country' returns 'Gbr', then your code sets $country=20 to '', while the original code sets it to '[GBR]'. Furthermore, the original code will not warn if '$card -> country' returns an undefined value. Your code will.=20 Abigail --huq684BweRXVnRxX Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFGd24EBOh7Ggo6rasRAvt1AJ9N58eIZrk0X3QEXGODt44NJz4aLACgk/fG FUtD3Dce/3sbWNOnLq1LHb4= =U1Pj -----END PGP SIGNATURE----- --huq684BweRXVnRxX--