breaking a long arithmetic statement into multiple line

Discussion in 'Perl Misc' started by Sean, Dec 5, 2006.

  1. Sean

    Sean Guest

    say I have a long expression:

    $abassd = ($abassd - $old_abassd) / 1000 * $time .... - $abassd;

    I want to write it into multiple lines (for readability), but it seems
    that
    perl interpretter does not recognize it as C++ compiler does.

    Sean
     
    Sean, Dec 5, 2006
    #1
    1. Advertising

  2. Sean

    Paul Lalli Guest

    Sean wrote:
    > say I have a long expression:
    >
    > $abassd = ($abassd - $old_abassd) / 1000 * $time .... - $abassd;
    >
    > I want to write it into multiple lines (for readability), but it seems
    > that
    > perl interpretter does not recognize it as C++ compiler does.


    Perl is not C++. Why are you expecting them to be interpreted/compiled
    the same way?

    Whitespace is irrelevant in Perl. You can put newlines (almost)
    anywhere you want. How were you breaking up the code? How is it not
    working the way you want?

    Why not show exactly what you were doing, so we can show you how you're
    doing it wrong?

    Paul Lalli
     
    Paul Lalli, Dec 5, 2006
    #2
    1. Advertising

  3. Sean <> wrote:
    > say I have a long expression:
    >
    > $abassd = ($abassd - $old_abassd) / 1000 * $time .... - $abassd;



    the .... is not Perl, so I'll ignore everything after that.


    > I want to write it into multiple lines (for readability),



    $abassd
    =
    (
    $abassd
    -
    $old_abassd
    )
    /
    1000
    *
    $time


    You can write that expression in anywhere from 1 to 11 non-empty lines.

    (15 lines if you also split after the sigils.)


    Choose the number that you like best.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Dec 5, 2006
    #3
  4. Sean wrote:
    > say I have a long expression:
    >
    > $abassd = ($abassd - $old_abassd) / 1000 * $time .... - $abassd;
    >
    > I want to write it into multiple lines (for readability),


    Nice idea. Why don't you do it?

    > that
    > perl interpretter does not recognize it as C++ compiler does.


    Why would you expect them to be the same?
    It would be a coincidence if Perl and C++ had the same behaviour.

    jue
     
    Jürgen Exner, Dec 5, 2006
    #4
  5. Sean

    Ala Qumsieh Guest

    Tad McClellan wrote:

    > Sean <> wrote:
    >
    >>say I have a long expression:
    >>
    >>$abassd = ($abassd - $old_abassd) / 1000 * $time .... - $abassd;

    >
    >
    >
    > the .... is not Perl, so I'll ignore everything after that.
    >
    >
    >
    >>I want to write it into multiple lines (for readability),

    >
    >
    >
    > $abassd
    > =
    > (
    > $abassd
    > -
    > $old_abassd
    > )
    > /
    > 1000
    > *
    > $time
    >
    >
    > You can write that expression in anywhere from 1 to 11 non-empty lines.
    >
    > (15 lines if you also split after the sigils.)
    >
    >
    > Choose the number that you like best.


    I can do better:

    $
    {
    abassd
    }

    etc... 23 lines total :)

    --Ala
     
    Ala Qumsieh, Dec 5, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amy
    Replies:
    0
    Views:
    538
  2. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    746
    Eric Sosman
    Jul 8, 2003
  3. joshc
    Replies:
    5
    Views:
    588
    Keith Thompson
    Mar 31, 2005
  4. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,244
    Peter Shaggy Haywood
    Sep 20, 2005
  5. Kevin
    Replies:
    1
    Views:
    554
    dorayme
    Apr 15, 2007
Loading...

Share This Page