Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8052213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:29:27+00:00 2026-06-05T07:29:27+00:00

Alright, so this is what I have: #!/usr/local/bin/perl my $argument1 = $ARGV[0]; open (LOGFILE,

  • 0

Alright, so this is what I have:

#!/usr/local/bin/perl


my $argument1 = $ARGV[0];
open (LOGFILE, "<$argument1") or die "Can't find file";

open FILE, ">>output.txt" or die $!;


while(<LOGFILE>){
if (/UNSUCCESSFUL/){
    print FILE "ERROR in line $.\n" if (/Error/);
    print "script unsuccessful \n";
    else:
print "script successful \n";   }

}

close FILE;
close LOGFILE;      

The problem, I think, is with my if else statement. If there is not the word “unsuccessful” in the text that is read in, it should simply print out “Script successful.” However, if the read in file does contain “unsuccessful,” then it should record where in the file the word “Error” appears and write this out to a file. Help?!

Sample input:

bar foo bar bar bar
error: will not compile
bar bar bar bar bar
attempt unsuccessful

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:29:29+00:00Added an answer on June 5, 2026 at 7:29 am

    I assume you do not wish to print "script successful" for all the lines in your input that does not contain the word "UNSUCCESSFUL". Instead, save the printing for last, and if you have no errors, print the success message.

    my @errors;
    while(<LOGFILE>) {
        if (/UNSUCCESSFUL/) {
            push(@errors, "ERROR in line $.\n") if (/Error/);
        }
    }
    
    if (@errors) {
        print for @errors;
    } else {
        print "script successful\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code, it looks alright and is really basic, but i can't
Alright, so I have this problem where you can glitch to get more than
I have this problem that I can't seem to find a solution for... I
Alright this is my first day with JQuery so have fun with these functions
Alright, I have this program to sparse code in Newick Format, which extracts both
Alright, so I have this collision detection code, and I'm trying to push the
Alright, so I have a block being drawn at 0,0,0 and I have this
Alright I know this is more than likely a amateur question but I have
Alright so I have no idea how to even begin doing this But basically
Alright, this one's interesting. I have a solution, but I don't like it. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.