Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (1)

Powered by Vanilla. Made with Bootstrap.
Maths Machine Perl Ed [Basic!]
  • Sh3llc0d3
    Posts: 1,910
    Well I was insanely bored and was pissing about with Perl and thought i'd do a Perl version of the Math's Machine I did in C++. I've not done much Perl coding and it's probably highly offensive coding to a pro perl coder but hey :P... hope you learn something... I did! (I have way too much spare time today)

    #!/usr/bin/perl
    @header = (
    \" [+]----------------------------[+]\n\",
    \" [+] [+]\n\",
    \" [+] Semtex-Primed [+]\n\",
    \" [+] Maths Machine (Perl) [+]\n\",
    \" [+] V0.1a [+]\n\",
    \" [+] [+]\n\",
    \" [+]----------------------------[+]\n\"
    );
    @menu = (
    \" [+] [+]\n\",
    \" [+] 1. Basic Maths [+]\n\",
    \" [+] 2. Pythagoras [+]\n\",
    \" [+] 3. Area [+]\n\",
    \" [+] [+]\n\",
    \" [+]----------------------------[+]\n\"
    );
    $menuchoice = \"true\";
    while ($menuchoice eq \"true\") {
    system \"clear\";
    system \"cls\";
    print @header;
    print @menu;
    print \">>Choose an option \";
    $choice = <STDIN>;
    chomp ($choice);
    if ($choice eq \"1\") {
    system \"clear\";
    system \"cls\";
    print @header;
    print \" *** Welcome to Basic Maths ***\n\";
    print \">>Enter your first number \";
    $num1 = <STDIN>;
    chomp ($num1);
    print \">>Enter your operator \";
    $op = <STDIN>;
    chomp ($op);
    print \">>Enter your second number \";
    $num2 = <STDIN>;
    chomp ($num2);
    if ($op eq \"+\") {
    $answer = $num1 + $num2;
    print \"The answer to $num1 added to $num2 equals $answer\n\";
    }
    elsif ($op eq \"-\") {
    $answer = $num1 - $num2;
    print \"The answer to $num1 subtract $num2 equals $answer\n\";
    }
    elsif ($op eq \"/\") {
    $answer = $num1 / $num2;
    print \"The answer to $num1 divided by $num2 equals $answer\n\";
    }
    elsif ($op eq \"*\") {
    $answer = $num1 * $num2;
    print \"The answer to $num1 multiplied by $num2 is $answer\n\";
    } else {
    print \"Error - try again\n\";
    };
    };
    };


    Nowhere near finished by the way... only have the basic maths function working.
    S-P
  • sangf
    Posts: 203
    insanely bored you were. haha, nice though - every time i see chomp(), i think back to those 10p chocolate bars, damn they were awesome. mm~ are those semi-colons necessary on the closing braces? weird~
  • Sh3llc0d3
    Posts: 1,910
    I had one of them the other day as it happens from spar lol... the semi's after the last three brackets aren't needed (I don't think), the ones after normal statements and the original two arrays are. Just checked and it's me going over-crazed on the semi-colons. Like I said, it's probably shocking code to a pro perl coder but it does the job :D
  • i want to learn Perl. looks usefull :)
  • Sh3llc0d3
    Posts: 1,910
    said:


    i want to learn Perl. looks usefull :)



    Yeah it's really useful for Linux/Unix System Administration.