Announcement

Collapse
No announcement yet.

Script to replace "a^b" in an expression with "pow(a,b)"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Believe it or not, I can figure out how I would get it to do it in BBC Assembler (6502 processor) but not in some modern fancy language
    Speaking of Erith:

    "It's not twinned with anywhere, but it does have a suicide pact with Dagenham" - Linda Smith

    Comment


    • #32
      Originally posted by Provost Harrison
      Believe it or not, I can figure out how I would get it to do it in BBC Assembler (6502 processor) but not in some modern fancy language
      If you could do it on a Z80 running CPM, I maybe will have some respect for you
      With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

      Steven Weinberg

      Comment


      • #33
        Looks like a neat little problem for writing a clever regex.
        (\__/) 07/07/1937 - Never forget
        (='.'=) "Claims demand evidence; extraordinary claims demand extraordinary evidence." -- Carl Sagan
        (")_(") "Starting the fire from within."

        Comment


        • #34
          Originally posted by Ramo
          Mercator, I just installed Active Perl. Now, how would I run your script?
          I'm assuming your formulas are in a text file (or multiple files), with a formula preferably on one line (or at least not having a line break in between one such power construction)...

          The quickest way is to simply type it in on the command-line:

          Code:
          perl -pi.bak -e"s/(\w+(?:\([^()]*\))?)\^(\w*(?:\(.*?\))?)/pow($1,$2)/g;" your_formula_filename(s)
          That'll perform a global search/replace and will even create backups, with an added .bak extension.


          If you more conveniently want to save it as a perl script (which does exactly the same), so you can use it later. Create a file that looks like this:

          Code:
          #!/Perl/bin/perl.exe -pi.bak
          s/(\w+(?:\([^()]*\))?)\^(\w*(?:\(.*?\))?)/pow($1,$2)/g;
          Make sure the first line matches your actual Perl path.
          You'd call that script like this:
          Code:
          perl the_perl_script formula_file1 formula_file2
          *cough* And I'm a bit late with this, but you could achieve the same with a text editor supporting Perl regular expressions, like Arachnophilia. In that case you'd simply open the file and replace all:
          Code:
          (\w+(?:\([^()]*\))?)\^(\w*(?:\(.*?\))?)
          by:
          Code:
          pow($1,$2)
          Civilization II: maps, guides, links, scenarios, patches and utilities (+ Civ2Tech and CivEngineer)

          Comment


          • #35
            Originally posted by BlackCat
            Forget about doing that automaticlly - it's a waste of time. Also drop using MS tools - they sucks - use vi (no, this is not std MS bashing - I work on both unix and MS platforms, and vi is the winner).
            Bleh, Visual studio.

            And to think, that was going be the name of my next DL...




            I dare you.
            Is God willing to prevent evil, but not able? Then he is not omnipotent. Is he able, but not willing? Then he is malevolent. Is he both able and willing? Then whence cometh evil? Is he neither able nor willing?
            Then why call him God? - Epicurus

            Comment


            • #36
              Originally posted by BlackCat


              If you could do it on a Z80 running CPM, I maybe will have some respect for you
              I don't know the specific instruction set, but I know roughly how I would do it
              Speaking of Erith:

              "It's not twinned with anywhere, but it does have a suicide pact with Dagenham" - Linda Smith

              Comment

              Working...
              X