hi,
i wrote a
package Foo::Expression::Arithmetic, a
package Foo::Number and a
package Foo::Variable.
I used
overload to be able to do the following:
my $x1 = Foo::Number->new()->value( 10 );
my $x2 = Foo::Number->new()->value( 20 );
my $x3 = Foo::Number->new()->value( 30 );
my $x4 = Foo::Number->new()->value( 40 );
my $v1 = Foo::Variable->new()->name( 'a' )->value( 50 );
my $c1 = $v1 - $x1 + $x2 + $x3 - $x4;
my $c2 = $c1 * $v1;
$c1 and $c2 are now objects of type
Foo::Expression::Arithmetic.
Foo::Expression::Arithmetic has a output function, so outputing $c1 and $c2 gives me the following:
a - 10 + 20 + 30 - 40 # $c1
a - 10 + 20 + 30 - 40 * a # $c2
Now i want to be able to do the following:
my $c3 = ( $x1 + $x2 ) * $v1;
not achieve the following output:
( 10 + 20 ) * a # $c3
use overload
'(' => \&left_parenthesis,
')' => \&right_parenthesis,
is not working. :-(
Any ideas?
2006-02-07 Retitled by Arunbear, as per Monastery guidelines
Original title: 'overload'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.