Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot, bind-address mysql multiple, sanibleone xxxx, ftp://192.168.100.100/, www.xxxcon, which comes first ob_start or session, wwwxxx/58/2010

Links

XODOX
Impressum

#1: Overloading a Perl Operator

Posted on 2011-10-05 23:40:06 by Phillip Richcreek

I'm going to use a package called Data::Money in place of a similar
module that I had previously used but is no longer available for
downloading/ installing. Data::Money does everything that the other
package does (as far as the features that I am using), and it would
pretty much be a drop-in replacement but for one difference:
Data::Money does not overload the == and != but instead overloads the
<=> operator. So where I'm using " if ($a==$b)" and if($A!=$b)" a lot
of places, I'd have to change these to " if (! ($a<=>$b)) ?" some
places and "if($a<=>$b) ?" other places. I think I might also be using
some < and >, which would require way beyond just find and replace.

So...
This might be an opportunity to do some OO programming. Can someone
point me to basic documentation for writing code to overload an
operator in perl? Like, does it have to be in a "package"? Can I just
piggy-back it onto the Data::Money class? etc. No doubt this approach
will take 10 times the effort of just going in and brute force
changing my existing code, but this will be a lot more fun. Or not :-)

TIA,
Phil
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Report this message

#2: Re: Overloading a Perl Operator

Posted on 2011-10-06 00:37:04 by Jenda Krynicky

From: Phillip Richcreek <pwrichcreek@gmail.com>

> I'm going to use a package called Data::Money in place of a similar
> module that I had previously used but is no longer available for
> downloading/ installing. Data::Money does everything that the other
> package does (as far as the features that I am using), and it would
> pretty much be a drop-in replacement but for one difference:
> Data::Money does not overload the == and != but instead overloads the
> <=> operator. So where I'm using " if ($a==$b)" and if($A!=$b)" a lot
> of places, I'd have to change these to " if (! ($a<=>$b)) ?" some
> places and "if($a<=>$b) ?" other places. I think I might also be using
> some < and >, which would require way beyond just find and replace.

I don't think you need to do any of this. According to the docs the
other comparison operators are autogenerated if the <=> is defined.

See
perldoc overload
section "MAGIC AUTOGENERATION".

Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Report this message

#3: Re: Overloading a Perl Operator

Posted on 2011-10-06 02:59:14 by Michael Zeng

--===============0700661209==
Content-Type: multipart/alternative; boundary=000e0cd6ec8e5a483a04ae96d591

--000e0cd6ec8e5a483a04ae96d591
Content-Type: text/plain; charset=ISO-8859-1

see programming perl book ---- overloading chapter ,




On Thu, Oct 6, 2011 at 6:37 AM, Jenda Krynicky <Jenda@krynicky.cz> wrote:

> From: Phillip Richcreek <pwrichcreek@gmail.com>
>
> > I'm going to use a package called Data::Money in place of a similar
> > module that I had previously used but is no longer available for
> > downloading/ installing. Data::Money does everything that the other
> > package does (as far as the features that I am using), and it would
> > pretty much be a drop-in replacement but for one difference:
> > Data::Money does not overload the == and != but instead overloads the
> > <=> operator. So where I'm using " if ($a==$b)" and if($A!=$b)" a lot
> > of places, I'd have to change these to " if (! ($a<=>$b)) ?" some
> > places and "if($a<=>$b) ?" other places. I think I might also be using
> > some < and >, which would require way beyond just find and replace.
>
> I don't think you need to do any of this. According to the docs the
> other comparison operators are autogenerated if the <=> is defined.
>
> See
> perldoc overload
> section "MAGIC AUTOGENERATION".
>
> Jenda
> ===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz<http://jenda.krynicky.cz/>=====
> When it comes to wine, women and song, wizards are allowed
> to get drunk and croon as much as they like.
> -- Terry Pratchett in Sourcery
>
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs<http://listserv.activestate.com/mailman/mysubs>
>



--
Yours Sincerely
Zeng Hong

--000e0cd6ec8e5a483a04ae96d591
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>see programming perl book ---- overloading chapter ,</div>
<div>=A0</div>
<div><br><br>=A0</div>
<div class=3D"gmail_quote">On Thu, Oct 6, 2011 at 6:37 AM, Jenda Krynicky <=
span dir=3D"ltr">&lt;<a href=3D"mailto:Jenda@krynicky.cz">Jenda@krynicky.cz=
</a>&gt;</span> wrote:<br>
<blockquote style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3D"gmail_quote">From: Phillip Richcreek &lt;<a h=
ref=3D"mailto:pwrichcreek@gmail.com">pwrichcreek@gmail.com</a>&gt;<br>
<div class=3D"im"><br>&gt; I&#39;m going to use a package called Data::Mone=
y in place of a similar<br>&gt; module that I had previously used but is no=
longer available for<br>&gt; downloading/ installing. Data::Money does eve=
rything that the other<br>
&gt; package does (as far as the features that I am using), and it would<br=
>&gt; pretty much be a drop-in replacement but for one difference:<br>&gt; =
Data::Money does not overload the == and !=3D but instead overloads the=
<br>
&gt; &lt;=3D&gt; operator. So where I&#39;m using &quot; if ($a==$b)&qu=
ot; and if($A!=3D$b)&quot; =A0a lot<br>&gt; of places, I&#39;d have to chan=
ge these to &quot; if (! ($a&lt;=3D&gt;$b)) ?&quot; some<br>&gt; places and=
&quot;if($a&lt;=3D&gt;$b) ?&quot; other places. I think I might also be us=
ing<br>
&gt; some &lt; and &gt;, which would require way beyond just find and repla=
ce.<br><br></div>I don&#39;t think you need to do any of this. According to=
the docs the<br>other comparison operators are autogenerated if the &lt;=
=3D&gt; is defined.<br>
<br>See<br>=A0perldoc overload<br>section &quot;MAGIC AUTOGENERATION&quot;.=
<br><br>Jenda<br>=====3D Jenda@Krynicky.cz ===3D <a href=3D"htt=
p://jenda.krynicky.cz/" target=3D"_blank">http://Jenda.Krynicky.cz</a> =3D=
====<br>When it comes to wine, women and song, wizards are allowed<=
br>
to get drunk and croon as much as they like.<br>=A0 =A0 =A0 =A0-- Terry Pra=
tchett in Sourcery<br>
<div>
<div></div>
<div class=3D"h5"><br>_______________________________________________<br>Ac=
tivePerl mailing list<br><a href=3D"mailto:ActivePerl@listserv.ActiveState.=
com">ActivePerl@listserv.ActiveState.com</a><br>To unsubscribe: <a href=3D"=
http://listserv.activestate.com/mailman/mysubs" target=3D"_blank">http://li=
stserv.ActiveState.com/mailman/mysubs</a><br>
</div></div></blockquote></div><br><br clear=3D"all"><br>-- <br>=A0 =A0 =A0=
=A0 =A0 =A0 Yours Sincerely<br>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Zen=
g Hong <br>

--000e0cd6ec8e5a483a04ae96d591--

--===============0700661209==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0700661209==--

Report this message