http://qs321.pair.com?node_id=430557


in reply to Adding scalars but with a twist..

Put them in an array instead and use that. This is one of the reasons why everybody told you in your previous post that it's not a good thing to want to get at a variable through a second variable by its name.

Replies are listed 'Best First'.
Re^2: Adding scalars but with a twist..
by snappybo (Initiate) on Feb 13, 2005 at 15:12 UTC
    Ok i'd love to, except there's about 500,000 lines of code previously written by someone else. (badly). Trust me this is not the way i'd normal write things but am forced to..
    Unfortunately whoever wrote this previously was terrible and it's just easier to keep running along thier lines, the reasons i'm asking the questions is i would never write a program like this but have to as small additions are being made.

    I.e. everywhere through the code it has $Sel1Ttl + $Sel2Ttl......$Sel80Ttl already written..

    Now everyone in thier answers has concentrated on the addition of the values, where the real problem is the $SelMaking this number changeTtl part...

      I guess some heavy refactoring is needed then. Should not be that hard to search&replace all the /\$Sel(\d+)Ttl\b/ with "$SelTtl\[$1]". Of course you should then go and replace those insane $Sel1Ttl + $Sel2Ttl......$Sel80Ttl, by sum(@SetTtl) (from List::Util), but that's something that can wait if necessary.

      Jenda
      We'd like to help you learn to help yourself
      Look around you, all you see are sympathetic eyes
      Stroll around the grounds until you feel at home
         -- P. Simon in Mrs. Robinson

      except there's about 500,000 lines of code
      In a single script? Assuming an average length of 40 Bytes per line that would be 19 MB!


      holli, /regexed monk/
        about 12Mb, it's awful!