walto has asked for the wisdom of the Perl Monks concerning the following question:
gives : 50.00 as I would expect#!/usr/bin/perl -w # # use strict; my $price = "50,-"; $price =~ m/(\d{1,4}),(\d{0,2})/; if ($2 ) { $price = $1 . "." . $2; } else { $price = $1 . "." . "00"; } print "$price\n";
gives 50.if (defined $2 ) { $price = $1 . "." . $2; } else { $price = $1 . "." . "00"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: if ($2) behaves differently than if (defined $2)
by moritz (Cardinal) on Apr 15, 2008 at 17:41 UTC | |
|
Re: if ($2) behaves differently than if (defined $2)
by starbolin (Hermit) on Apr 15, 2008 at 17:42 UTC | |
by radiantmatrix (Parson) on Apr 15, 2008 at 18:09 UTC | |
by repellent (Priest) on Apr 16, 2008 at 16:57 UTC | |
|
Re: if ($2) behaves differently than if (defined $2)
by toolic (Bishop) on Apr 15, 2008 at 18:49 UTC |