Loading ...
Sorry, an error occurred while loading the content.

Query related to "print"

Expand Messages
  • Sreeram B S
    Hi friends, I have a query related to print. In the web, I came across a program which does some terminal related functionalities, like clearing the screen,
    Message 1 of 2 , Sep 2, 2005
    View Source
    • 0 Attachment
      Hi friends,
      I have a query related to print.

      In the web, I came across a program which does some terminal related functionalities, like clearing the screen, making the font bold etc. I was analysing the program. The functionality is achieved with a hash and a print statement. I am unable to interpret the "print" statement correctly.

      For clearing the screen,the program looks like this:
      #!/usr/bin/perl
      # terminal controls
      %scr = (
      'f' => 3,
      'b' => 4,
      'black' => 0,
      'red' => 1,
      'green' => 2,
      'yellow' => 3,
      'blue' => 4,
      'magenta' => 5,
      'cyan' => 6,
      'white' => 7,
      'normal' => 0,
      'bold' => 1,
      'reverse' => 7,
      'invisible' => 8,
      'clear' => '2J',
      'clrline' => 'K',
      'savepos' => 's',
      'returnpos' => 'r',
      'mvup' => 'A',
      'mvdn' => 'B',
      'mvfr' => 'C',
      'mvbk' => 'D'
      );
      sub svid # clr,(f/b) or mode,x
      {
      print "\x1B[$scr{$_[1]}$scr{$_[0]}m"; ## I could not interpret this statement correctly.
      }
      svid(clear); ## Clears the screen.

      ----------------------------------
      I could not understand the print statement correctly. For "clear", the hash value is '2J' . So, finally, the print statement will be:

      print "\x1B[2Jm";

      How should I interpret this statement? [ Is this something related to ASCII values of keys ..etc].

      Kindly guide me.

      For the full program, the URL is http://www.zdo.com/articles/creating_text_mode_user_interfaces_with_perl.php

      Thanks,
      Sreeram



      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail.yahoo.com

      [Non-text portions of this message have been removed]
    • Shawn Corey
      ... You are correct, the sequence x1B[2J will clear the screen and then an m will appear in the upper-left corner. For a brief description of the ANSI
      Message 2 of 2 , Sep 2, 2005
      View Source
      • 0 Attachment
        Sreeram B S wrote:
        > I could not understand the print statement correctly. For "clear",
        > the hash value is '2J' . So, finally, the print statement will be:
        >
        > print "\x1B[2Jm";
        >
        > How should I interpret this statement? [ Is this something related to
        > ASCII values of keys ..etc].
        >
        > Kindly guide me.
        >
        > For the full program, the URL is
        > http://www.zdo.com/articles/creating_text_mode_user_interfaces_with_perl.php
        >
        > Thanks,
        > Sreeram

        You are correct, the sequence "\x1B[2J" will clear the screen and then
        an "m" will appear in the upper-left corner. For a brief description of
        the ANSI terminal codes see http://en.wikipedia.org/wiki/ANSI_escape_code


        --- Shawn
      Your message has been successfully submitted and would be delivered to recipients shortly.