QB / QB64 Discussion Forum      Other Subforums, Links and Downloads      Archived Pascal Resources    Search
Respond to this messageReturn to Index
Original Message
  • Well,compiled languages just aren't as portable.
    • 10 (no login)
      Posted Jan 14, 2007 10:08 PM

      I like my exact order of numbers. I'll check out your version anyway.

      I am also learning some Perl since I read it's faster.

      This is a small Perl tutorial.

      Below is the first program. It has a comment that does nothing.
      It prints the excellent Hello World.

      All these examples worked on my abyss web server.

      print "Content-Type: text/html\n\n";
      # This is a comment!
      print 'Hello World';

      The way variables are treated depends on how you write them.

      0b0110010 binary
      062 octal
      0x32 hexadecimal
      50 decimal
      1.25 floating point
      'hello' string with ''
      "world" string with ""

      You can use _ in between digits of your integers.
      This is 1 of the surprisingly useful features of Perl.

      0b0111010110111100110100010101

      is cool,but

      0b0111_0101_1011_1100_1101_0001_0101

      Is easier to read.

      The print statement outputs decimal integers.



      There are also special regular expressions for strings.
      I got this list from
      http://search.cpan.org/dist/perl/pod/perlre.pod

      \t tab (HT, TAB)
      \n newline (LF, NL)
      \r return (CR)
      \f form feed (FF)
      \a alarm (bell) (BEL)
      \e escape (think troff) (ESC)
      \033 octal char (think of a PDP-11)
      \x1B hex char
      \x{263a} wide hex char (Unicode SMILEY)
      \c[ control char
      \N{name} named char
      \l lowercase next char (think vi)
      \u uppercase next char (think vi)
      \L lowercase till \E (think vi)
      \U uppercase till \E (think vi)
      \E end case modification (think vi)
      \Q quote (disable) pattern metacharacters till \E

      I rarely use these since on my server,everything is HTML.
      You would do a new line with <br> .

      print "Content-Type: text/html\n\n";
      print 'Hello <br> World';

      However,to do cooler things,you can use variables!
      Variables start with $.

      print "Content-Type: text/html\n\n";
      $n=256;
      $t='two five six';
      print $n . '<br>' . $t;

      As you can see, the . operator is used to print multiple things!

      Also,there is a list of operators at
      http://search.cpan.org/dist/perl/pod/perlop.pod

      The main use of operators is to do math of course!

      Here are those I use

      ++ increment
      -- decrement
      + addition
      - subtraction
      * multiplication
      / division
      % modulus
      << left shift
      >> right shift
      & AND
      | OR
      ^ XOR
      ~ NOT

      And there are conditional operators.

      "<" returns true if the left argument is numerically less than the right argument.
      ">" returns true if the left argument is numerically greater than the right argument.
      "<=" returns true if the left argument is numerically less than or equal to the right argument.
      ">=" returns true if the left argument is numerically greater than or equal to the right argument.
      "lt" returns true if the left argument is stringwise less than the right argument.
      "gt" returns true if the left argument is stringwise greater than the right argument.
      "le" returns true if the left argument is stringwise less than or equal to the right argument.
      "ge" returns true if the left argument is stringwise greater than or equal to the right argument.
      "==" returns true if the left argument is numerically equal to the right argument.
      "!=" returns true if the left argument is numerically not equal to the right argument.

      That's enough info for an if statement.

      print "Content-Type: text/html\n\n";
      $n=0;
      if($n==0){print 'n is zero';}
      else{print 'n is not zero';}

      Loops are of course the coolest way to save time!
      Here's a while loop.

      print "Content-Type: text/html\n\n";
      $n=0;
      while($n<16)
      {
      print $n . '<br>';
      $n++;
      }

      Here's a for loop.

      print "Content-Type: text/html\n\n";
      for($n=0;$n<16;$n++)
      {
      print $n . '<br>';
      }

      The final step in handling variables is arrays!

      print "Content-Type: text/html\n\n";
      for($x=0;$x<8;$x++)
      {
      $a[$x]=0;
      }

      $a[5]=7;
      $a[1]=3;

      for($x=0;$x<8;$x++)
      {
      print $a[$x];
      }

      You can actually use Perl to run system commands depending on your
      operating system!

      print "Content-Type: text/html\n\n";
      system "dir"; #DOS/Windows command

      I wrote this tutorial while I was learning. Although it's not a lot of detail,
      it's what I needed to know. Perl is pretty cool actually. It's very similar to PHP.
    Your Name
    Your Email
    (Optional)
    Message Title
    Message Text
    Options Also send responses to my email address