On 2/8/10, 7 <7stud.7s...@gmail.com> wrote: > On 2/8/10, 7 <7stud.7s...@gmail.com> wrote: >> On 2/8/10, Chris Coggins <cacogg...@cox.net> wrote: >>> What is the proper syntax for a comparison at the end of a subroutine to >>> stop the script if a certain variable is "0" or ''? >>> >>> sub routine{ >>> (get data and process it) >>> if $varA = '' || $varA = "0" { >>> (stop script, print error message to user) >>> } >>> else{ >>> (continue with script) >>> } >>> >> >> if ($varA = '' || $varA = "0") { #space after 'if' >> #code >> } >> else { #space after 'else' >> #code >> } >> > > Rather: > > if ($varA eq '' || $varA eq "0") { #space after 'if' > #code > } > else { #space after 'else' > #code > } >
...and you might want to consider: if (defined $var && ($var eq '' || $var eq '0')) { #code } to handle cases where $var = undef. undef acts like it is a blank string when used as a string. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/