Return values from methods on Classes/Objects

From: Michael Kraus (mkraus_at_wildtechnology.net)
Date: 11/29/04

  • Next message: John W. Krahn: "Re: sorting with Swartz Transform"
    Date: Mon, 29 Nov 2004 18:07:33 +1100
    To: <beginners@perl.org>
    
    

    G'day...

    One of my classes has a method called format_cost which takes a number
    (integer representing a monetory amount in cents) and pretties it up for
    display as a dollar amount. I.e. format_cost(120000) returns
    "$1,200.00".

    When I have the function stand-alone it behaves as it should, however
    when I have it as a method on a class, and make a call to it (external
    to the class/object), it returns the class or object itself.

    E.g.

    my @output = ();
    sub add_output {
            @output = (@output, @_);
    }

    add_output($q->h2("Cost per billing period: " .
    Super_DB_Object->format_cost($period_multiplier *
    $total_monthly_cost_in_cents)));
    add_output($q->h2("Cost per billing period: " .
    $customer->format_cost($period_multiplier *
    $total_monthly_cost_in_cents)));
    add_output($q->h2("Cost per billing period: " .
    format_cost($period_multiplier * $total_monthly_cost_in_cents)));
    add_output($q->h2("Cost per billing period: " . ($period_multiplier *
    $total_monthly_cost_in_cents)));

    print @output;

    displays:

    Cost per billing period: Super_DB_Object
    Cost per billing period: Customer=HASH(0x82ddef8)
    Cost per billing period: $2,277.00
    Cost per billing period: 227700

    Clearly, I'm missing something crucial here... :)

    (FWIW, $q is a CGI instance and output is to a browser)

    All help appreciated.

    Regards,
     

    Michael S. E. Kraus
    Software Developer
    Wild Technology Pty Ltd
    _______________________________
    ABN 98 091 470 692
    Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017, Australia
    Telephone 1300-13-9453 | Facsimile 1300-88-9453
    http://www.wildtechnology.net
     
    The information contained in this email message and any attachments may
    be confidential information and may also be the subject of client legal
    - legal professional privilege. If you are not the intended recipient,
    any use, interference with, disclosure or copying of this material is
    unauthorised and prohibited. This email and any attachments are also
    subject to copyright. No part of them may be reproduced, adapted or
    transmitted without the written permission of the copyright owner. If
    you have received this email in error, please immediately advise the
    sender by return email and delete the message from your system.


  • Next message: John W. Krahn: "Re: sorting with Swartz Transform"

    Relevant Pages

    • RE: Return values from methods on Classes/Objects
      ... number (integer representing a monetory amount in cents) and ... : Cost per billing period: Super_DB_Object ... sub format_cost { ...
      (perl.beginners)
    • OT: Free Ipod site that works!
      ... and cancel before the billing period starts. ... NO COST. ... know this works because I got one, I'm just trying to get one for my wife ...
      (alt.home.repair)
    • OT: Free Ipod site that works
      ... and cancel before the billing period starts. ... NO COST. ... know this works because I got one, I'm just trying to get one for my wife ...
      (alt.games.video.xbox)
    • OT: Free Ipod site that works
      ... and cancel before the billing period starts. ... NO COST. ... know this works because I got one, I'm just trying to get one for my wife ...
      (rec.sport.golf)
    • OT: Ipod site that works
      ... and cancel before the billing period starts. ... NO COST. ... know this works because I got one, I'm just trying to get one for my wife ...
      (alt.fan.howard-stern)