printing lines from a file

From: Christopher Spears (cspears2002_at_yahoo.com)
Date: 02/27/05

  • Next message: John W. Krahn: "Re: printing lines from a file"
    Date: Sat, 26 Feb 2005 18:57:52 -0800 (PST)
    To: beginners@perl.org
    
    

    Here is some code I am working on:

    #!/bin/perl -w
    use strict;

    my $number_of_args = @ARGV;

    open STDERR, ">./caught_errors" or die "Can't create
    caught_errors: $!";

    if ($number_of_args == 0) {
        print "Not enough arguments!\n";
        print "Usage: ./cedit somefile.C++\n";
        print "Usage (optional): ./cedit somefile.C++
    outputfile\n";
    } elsif ($number_of_args == 1) {
        system "g++", $ARGV[0];
        open CAUGHTERRORS, "caught_errors" or die "Can't
    open file: $!";
        chomp(my $line = <CAUGHTERRORS>);
        until (my $line =~ /^\s*$/) {
           chomp($line = <CAUGHTERRORS>);
           print $line."\n";
        }
        close CAUGHTERRORS;
    } elsif ($number_of_args == 2) {
        system "g++", $ARGV[0], "-o", $ARGV[1];
    } else {
        print "Too many arguments!\n";
        print "Usage: ./cedit somefile.C++\n";
        print "Usage (optional): ./cedit somefile.C++
    outputfile\n";
    }

    Basically, I am trying automate g++. However, I don't
    want any error messages printed to the screen. I want
    them saved in a text file called caught_errors. That
    part works. After g++ does its business, I want the
    script to open the text file and print out any
    messages that it sees in there. This is the part I am
    having trouble with! This is frustrating because I
    know I have done something like this before! Right
    now, in caught_errors, I am getting the following
    error messages:

    hello.c++: In function `int main()':
    hello.c++:7: error: syntax error before `return'
    Use of uninitialized value in pattern match (m//) at
    /home/Christstopher Spears/C++_code/tools/cedit line
    16, <CAUGHTERRORS> line 1.

    The first two are obviously from the C++ program I
    wrote incorrectly to test the script. I don't
    understand the third error message. Any hints?


  • Next message: John W. Krahn: "Re: printing lines from a file"

    Relevant Pages

    • Re: What is the need for @ symbol in php script
      ... The '@' just suppresses error messages, which is never a good idea ... A fatal error will ALWAYS stop your script from working - that's why ... Hardly cumbersome, compared to managing code with list, and ... extractfunction makes the process easier. ...
      (comp.lang.php)
    • Re: IE Wont Open
      ... notification about every script error." ... Open Internet Explorer. ... Two download versions are available for Windows Script 5.6. ... please post back to this thread with the details and any error messages. ...
      (microsoft.public.windows.inetexplorer.ie6.browser)
    • Re: IE Crashes when loading page with javascript
      ... See these articles for possible help w/ error messages in scripting: ... Error Message When You Browse the Web: An Error Has Occurred in the Script ... Windows Script 5.7 for Windows XP ... updates/security roll-ups, etc. from Windows Update. ...
      (microsoft.public.windows.inetexplorer.ie6.browser)
    • Re: IE Crashes when loading page with javascript
      ... See these articles for possible help w/ error messages in scripting: ... Error Message When You Browse the Web: An Error Has Occurred in the Script ... Windows Script 5.7 for Windows XP ... updates/security roll-ups, etc. from Windows Update. ...
      (microsoft.public.windows.inetexplorer.ie6.browser)
    • Re: Logon Scripts for Dept. and Printers based on Groups and IP
      ... I have a script that was put together by a several different scripts ... error messages and report them to me so I can fix them. ... Our logon script logs its proceedings and error messages into a file in the ... Having some drives pre-assigned is therefore not ...
      (microsoft.public.scripting.vbscript)