Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Perl on OSX > Re: Is there a ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 11 Topic 1001 of 1075
Post > Topic >>

Re: Is there a True Boolean type in Perl?

by mbarto@[EMAIL PROTECTED] (Michael Barto) Oct 15, 2007 at 06:20 PM

--------------040501080005010308020203
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

I think in the more newer languages, they have implemented true 
booleans. Perl is kind of old school. Pascal defines them as a 
grandfather of languages. Therefore as one migrates the languages to a 
higher levels (e.g. Perl[n]), they all will end up with a boolean data 
type. Therefore, I think the $true and $false is a more consistent 
method in a multiple languages environments (particularly doing web 
things [Java and Javascript] for a consistent set of rules across the 
board. Thanks for your input.

jeremiah@[EMAIL PROTECTED]
 wrote:
>
> On Oct 15, 2007, at 11:25 PM, Gary Blackburn wrote:
>
>>
>> On Oct 15, 2007, at 4:27 PM, Michael Barto wrote:
>>
>>> As both Java and Javascript both have a 'true' and 'false' or 
>>> Boolean data type, is there any interest in evolution of Perl to 
>>> have a true Boolean. Or what is the preferred method to do this in 
>>> Perl. The "C" programmers want me to use "0"'s and "1"'s.
>>
>> In my experience the most common convention is to use undef and 1 as 
>> your boolean values, as in:
>>
>> my $is_scared;    # is_scared is initially set to undef, which 
>> evaluates as "false"
>>
>> if ($monsters_under_my_bed) {
>>     $is_scared = 1;
>> }
>>
>> Yeah, it's probably bad karma to use "undef" when you mean "0" but 
>> this approach is very perl-ish, easy to read, and even recommended by 
>> Damian Conway in his "Perl Best Practices" book (page 40... just 
>> checked. :-D)
>
> You can, if you really want to, do this:
>
> my $true = 1;
> my $false;
>
> Still, it is not much of a substitute for knowing what exactly is 
> _inside_ your variable and testing it to make sure. Plus, boolean 
> values are un-perlish. Look at this for example:
>
> if ($var) {
>    print "Yep!";
> } else {
>    print "Nep!";
> }
>
> That is perlish, testing if $var is defined and doing some thing based 
> on that. You can of course make it clearer with
>
> if ( defined ($var))
>
> But to be really perly and terse, this is the idiom:
>
> print "Yep" if ($var);
>
>     Jeremiah
>

-- 
------------------------------------------------------------------------
*Michael Barto*
Software Architect

	LogiQwest Circle
LogiQwest Inc.
16458 Bolsa Chica Street, # 15
Huntington Beach, CA  92649
http://www.logiqwest.com/

	    	mbarto@[EMAIL PROTECTED]
 <mailto:mbarto@[EMAIL PROTECTED]
>
Tel:  714 377 3705
Fax: 714 840 3937
Cell: 714 883 1949

*'tis a gift to be simple*
------------------------------------------------------------------------
This e-mail may contain LogiQwest proprietary information and should be 
treated as confidential.


--------------040501080005010308020203
Content-Type: multipart/related;
 boundary="------------030503050008030404020003"


--------------030503050008030404020003
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
I think in the more newer languages, they have implemented true
booleans. Perl is kind of old school. Pascal defines them as a
grandfather of languages. Therefore as one migrates the languages to a
higher levels (e.g. Perl[n]), they all will end up with a boolean data
type. Therefore, I think the $true and $false is a more consistent
method in a multiple languages environments (particularly doing web
things [Java and Javascript] for a consistent set of rules across the
board. Thanks for your input.<br>
<br>
<a class="moz-txt-link-abbreviated"
href="mailto:jeremiah@[EMAIL PROTECTED]
">jeremiah@[EMAIL PROTECTED]
>
wrote:
<blockquote
 cite="mid:6139CF9C-BD8F-4E50-A62D-97C2315BDECB@[EMAIL PROTECTED]
"
 type="cite"><br>
On Oct 15, 2007, at 11:25 PM, Gary Blackburn wrote:
  <br>
  <br>
  <blockquote type="cite"><br>
On Oct 15, 2007, at 4:27 PM, Michael Barto wrote:
    <br>
    <br>
    <blockquote type="cite">As both Java and Javascript both have a
'true' and 'false' or Boolean data type, is there any interest in
evolution of Perl to have a true Boolean. Or what is the preferred
method to do this in Perl. The "C" programmers want me to use "0"'s and
"1"'s.
      <br>
    </blockquote>
    <br>
In my experience the most common convention is to use undef and 1 as
your boolean values, as in:
    <br>
    <br>
my $is_scared;&nbsp;&nbsp;&nbsp; # is_scared is initially set to undef,
which
evaluates as "false"
    <br>
    <br>
if ($monsters_under_my_bed) {
    <br>
&nbsp;&nbsp;&nbsp;&nbsp;$is_scared = 1;
    <br>
}
    <br>
    <br>
Yeah, it's probably bad karma to use "undef" when you mean "0" but this
approach is very perl-ish, easy to read, and even recommended by Damian
Conway in his "Perl Best Practices" book (page 40... just checked. :-D)
    <br>
  </blockquote>
  <br>
You can, if you really want to, do this:
  <br>
  <br>
my $true = 1;
  <br>
my $false;
  <br>
  <br>
Still, it is not much of a substitute for knowing what exactly is
_inside_ your variable and testing it to make sure. Plus, boolean
values are un-perlish. Look at this for example:
  <br>
  <br>
if ($var) {
  <br>
&nbsp;&nbsp; print "Yep!";
  <br>
} else {
  <br>
&nbsp;&nbsp; print "Nep!";
  <br>
}
  <br>
  <br>
That is perlish, testing if $var is defined and doing some thing based
on that. You can of course make it clearer with
  <br>
  <br>
if ( defined ($var))
  <br>
  <br>
But to be really perly and terse, this is the idiom:
  <br>
  <br>
print "Yep" if ($var);
  <br>
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;Jeremiah
  <br>
  <br>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<meta content="text/html;" http-equiv="Content-Type">
<title></title>
<div class="moz-signature">
<div class="moz-signature">
<table border="0" cellpadding="0" cellspacing="0" width="490">
  <tbody>
    <tr>
      <td colspan="4" width="490">
      <hr color="#cccccc"></td>
    </tr>
    <tr>
      <td colspan="3" align="left" valign="top" width="390"><font
 face="arial, helvetica, sans-serif"><font size="3"><b>Michael
Barto</b><br>
      </font><font size="2">Software Architect<br>
      <br>
      </font></font></td>
      <td rowspan="2" align="right" valign="middle" width="100"><img
 alt="LogiQwest Circle" src="cid:part1.08090901.08000909@[EMAIL PROTECTED]
"
 height="80" width="81"><br>
      </td>
    </tr>
    <tr>
      <td align="left" valign="top" width="220"><font
 face="arial, helvetica, sans-serif"> <font color="#003366"
size="2">LogiQwest
Inc.<br>
16458 Bolsa Chica Street, # 15<br>
Huntington Beach, CA&nbsp;&nbsp;92649<br>
      <a
href="http://www.logiqwest.com/">http://www.logiqwest.com/</a><br>
      <br>
      </font></font></td>
      <td width="10">&nbsp;&nbsp;&nbsp;</td>
      <td align="left" valign="top" width="160"><font
 face="arial, helvetica, sans-serif"><font color="#003366" size="2"><a
 href="mailto:mbarto@[EMAIL PROTECTED]
">mbarto@[EMAIL PROTECTED]
><br>
Tel:&nbsp;&nbsp;714 377 3705<br>
Fax:&nbsp;714 840 3937<br>
Cell: 714 883 1949<br>
      <br>
      </font></font></td>
    </tr>
    <tr>
      <td colspan="4" align="right" width="490"><font color="#ff6633"
 face="arial, helvetica, sans-serif" size="2"><strong>'tis a gift to be
simple</strong></font>
      <hr color="#cccccc"> </td>
    </tr>
    <tr>
      <td colspan="4" align="center" width="490"> <font
 face="arial, helvetica, sans-serif" size="1">This e-mail may contain
LogiQwest
proprietary information and should be treated as confidential.</font>
</td>
    </tr>
  </tbody>
</table>
</div>
</div>
</div>
</body>
</html>

--------------030503050008030404020003
Content-Type: image/gif; x-mac-type="47494666"; x-mac-creator="70727677";
 name="circle.gif"
Content-Transfer-Encoding: base64
Content-ID: <part1.08090901.08000909@[EMAIL PROTECTED]
>
Content-Disposition: inline;
 filename="circle.gif"

R0lGODlhUQBQAJEAAAAAAP////1HA////yH5BAEAAAMALAAAAABRAFAAAAL/jI+pyybSopy0
OvWy3bwfmGSPR5bMGIrmaqEhpqWgM7Ocii0uggexvdm9WrsfsCLk3VLHW43ZjCp5T6qsijSu
fiKt75qcdI/cMYzaI6ZLRvP54w56Pen4FI11eZPzRtwO9wYD0jcoh9OF5aN4UhOm89hoBtHH
KEWXeLFGo3PZkeg4xxcpZqmmtfkFhllIAbgYJvRa2hqRCRn7NCuRmvXaO2jqR0p7C1trBZlc
CgWGqJInvIxMM9MKesxIjAYnDdvNO7Z74jfkWhT+TN3t3WmTGlk0PrwuiRofCmyrX1zV68/P
Xjtnun4ZIhGQ3h6DQZrdCQSRYLBYTrjRAreo2p+E/1mWhbOoB1S+cg0vhcSG0R0eT43AGStU
kOM7ayg2ntpGhqZFdio14gTyqIcxj8cQGsVFaOgHcphYaJik1BNKJy+jqlKTrY3IZxLZUep5
jpNYK/KWOlsVbRWUkDIyRlS0JunVdBQvmJ3i7+7BpfWsPjQp61tLr6YGfnqq1hxPluc2imK8
ZahfyKwkAyJWU6dZN5nH4oH6r7Bcpno150LpV7SSghm/jkWMVNastKqgYbudGdjlf8rIZpsr
e/PFxK6Q0MEabLDiiHaZzU0Xey9z5rn3HF64sHcOiJOpan3MJu/2n1k/g23+cXnk76O0N6NN
Gnn57f30cofNivB55dOvrFzXTx9ReVBWzUr7KSMMeb60ZUIdABEIj3vPeUagT3xIGF9/UUxl
31qucfUbYJWQ81SJJmpiWFP7KVghhm6JsWKLtmQ4QigyluRQbX/dyItxE/LYIGspAknSjlEU
AAA7
--------------030503050008030404020003--

--------------040501080005010308020203--
 




 11 Posts in Topic:
Is there a True Boolean type in Perl?
mbarto@[EMAIL PROTECTED]   2007-10-15 13:27:26 
Re: Is there a True Boolean type in Perl?
chas.owens@[EMAIL PROTECT  2007-10-15 16:54:08 
Re: Is there a True Boolean type in Perl?
merlyn@[EMAIL PROTECTED]   2007-10-16 12:25:29 
Re: Is there a True Boolean type in Perl?
gblackburn@[EMAIL PROTECT  2007-10-15 17:25:23 
Re: Is there a True Boolean type in Perl?
jeremiah@[EMAIL PROTECTED  2007-10-15 23:59:55 
Re: Is there a True Boolean type in Perl?
mbarto@[EMAIL PROTECTED]   2007-10-15 18:20:22 
Re: Is there a True Boolean type in Perl?
douglist@[EMAIL PROTECTED  2007-10-15 19:40:19 
Re: Is there a True Boolean type in Perl?
trey@[EMAIL PROTECTED] (  2007-10-17 12:40:08 
Re: Is there a True Boolean type in Perl?
chas.owens@[EMAIL PROTECT  2007-10-16 05:55:15 
Re: Is there a True Boolean type in Perl?
chas.owens@[EMAIL PROTECT  2007-10-16 06:01:02 
Re: Is there a True Boolean type in Perl?
david@[EMAIL PROTECTED]   2007-10-16 16:19:28 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 9:55:15 CDT 2008.