File output using colour

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sarma19
    New Member
    • Apr 2007
    • 3

    File output using colour

    Hi Experts,

    I am interested in creating some Report files for that using below lines of perl
    code to display out put in colour to distinguish different types of Errors

    use Term::ANSIColor ;
    print color .........etc


    similary is there any possibility to dump the content to a file in UNIX platform using PERL so that when it is opened it should display information in colours

    Thanks & Regards
    Sarma
  • tifoso
    New Member
    • Apr 2007
    • 41

    #2
    Why not print to an html file that way the coloring is straighforward

    #...
    print "<html><body>.. ."; etc
    ...
    print "<font color=-red> Massive ERROR</font>";
    ....

    if the perl is run from a web-page you can pop-up a page
    with your results, don't forget to add
    print "Content-type: text/html \n\n";
    at the top

    Ciao

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      Originally posted by sarma19
      Hi Experts,

      I am interested in creating some Report files for that using below lines of perl
      code to display out put in colour to distinguish different types of Errors

      use Term::ANSIColor ;
      print color .........etc


      similary is there any possibility to dump the content to a file in UNIX platform using PERL so that when it is opened it should display information in colours

      Thanks & Regards
      Sarma
      You would have to decide what type of UNIX file format to use that understands color and write the file in that format so when it's opened the application that reads the file knows how to display the embedded markup instructions. Decide on a file format and search CPAN to see if there is a perl module that writes files in that format you decide to use.

      Comment

      • sarma19
        New Member
        • Apr 2007
        • 3

        #4
        Hi Kevin,

        how to use the CPAN modules the reason is some time back i wanted to create and dump data to excel sheet instead of normal UNIX file so i gone through the help information on how to use the CPAN modeules in the net but when i download i realize i don't have permissions to add that module to the perl installer so regarding this also this will not help me

        except this CPAN can u suggest me some other simple approach to dump into the file which i can open using vim or vi editors


        Best Regards
        Kiran Kumar

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Do you know how to print anything to a file? Thats all you need to do, then open the file with what ever editor you want. But you said you wanted colorized output. For that you have to know how to write the color information into the file. I don't know how off the top of my head. And it depends on the file format you will be using. If it's just plain text you can't include color information or any other stuff besides spaces, tabs, or newlines.

          Comment

          • miller
            Recognized Expert Top Contributor
            • Oct 2006
            • 1086

            #6
            Hello Kiran Kumar,

            The best advice that I can give you is to not try to do this.

            If you want to create reports that differentiate between different levels of errors, then give those errors different labels. For example the Apache::Log module has 8 sequential log levels: emerg, alert, crit, error, warn, notice, info, debug. It is possible to set the current log level of the server so that logs of a certain less critical level are not recorded. And in the log file, all messages of a specific type are prefixed with that type label.

            It is true that you can create pretty colours, but this requires specific knowledge on how to read them. It is a much better practice to stick with a standard file format such as plain text or html as new people will know how to read it. Besides, having color implies that you'll have to have some type of legend to translate what it means, where as having a label makes it more inherantly obvious.

            That's all my advice concerning this subject,
            - Miller

            Comment

            • KevinADC
              Recognized Expert Specialist
              • Jan 2007
              • 4092

              #7
              That's all my advice concerning this subject,
              - Miller


              heheheh.... you sound like Forrest Gump ;)

              Comment

              • miller
                Recognized Expert Top Contributor
                • Oct 2006
                • 1086

                #8
                Originally posted by KevinADC
                heheheh.... you sound like Forrest Gump ;)
                hehe :)

                Yeah, at one time (almost 7 years ago) I also looked into adding colour to some of my terminal scripts. I eventually figured out why this is a foolhardy thing to do. There are much better methods for making reporting easy on the eyes. Preferably ones that are less prone to errors of their own.

                - M

                Comment

                • sarma19
                  New Member
                  • Apr 2007
                  • 3

                  #9
                  Miller,
                  Thanks for your suggestion coming to this i am new to CPAN related stuff but anyway i got there is tar.gz kit available to install it , is it ok if i install only in local directory/path or has to be installed in root directrory where entire perl package installed , if it needs 2nd option then i don't have previliges so it will stop me using this package

                  the reason i asked colour dump into ASCII file is to distinguish various statements not only for displaying error data (let us say if it is not an error or warning from any output but wanted to distinguish the output information dumped into a normal ASCII file to be opened by vi editors based on some catogery )

                  It is great help if you can provide help information on installation or the link where can i get suc info
                  Thanks
                  Kiran

                  Comment

                  Working...