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

  • Home
  • SEARCH
  • 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 8045155
In Process

The Archive Base Latest Questions

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

Alright, so I’m back with another question. I know in Python there is a

  • 0

Alright, so I’m back with another question. I know in Python there is a way to read in a file without specifying which file it will be, until you are in the command prompt. So basically you can set the script up so that you can read in any file you want and don’t have to go back and change the coding every time. Is there a way to do this in Perl? If so, can you write files like that too? Thanks.

This is what I have:

open (LOGFILE, "UNSUCCESSFULOUTPUT.txt") or die "Can't find file";       
open FILE, ">", "output.txt" or die $!;

while(<LOGFILE>){
print FILE "ERROR in line $.\n" if (/Error/);
}






close FILE;
close LOGFILE;                  

This is what I have nome:

#!/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>){
print FILE "ERROR in line $.\n" if (/Error/);
}





close FILE;
close LOGFILE;

And it’s still not appending…

  • 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-05T05:27:22+00:00Added an answer on June 5, 2026 at 5:27 am

    This is what I believe you want:

    #!usr/bin/perl
    my $argument1 = $ARGV[0];
    
    open (LOGFILE, "<$argument1") or die "Can't find file";       
    open (FILE, ">output.txt") or die $!;
    
    while(<LOGFILE>){
    print FILE "ERROR in line $.\n" if (/Error/);
    }
    
    close FILE;
    close LOGFILE; 
    

    Ran as from the command line:

    > perl nameofpl.pl mytxt.txt
    

    For appending change this line:

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

    To the remarkably similar:

     open (FILE, ">>output.txt") or die $!;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, currently I have my SWF hitting a php file that will go and
Alright, I'm trying to read a comma delimited file and then put that into
Alright so i need to open a .txt file that will be created in
Alright, this problem seems to be way above my head! I have this code:
Alright, so we know functions in the STL like std::fill(boolContainer.begin(), boolContainer.end(), false); I'm working
Alright, i have read many different views on how to do this with no
Alright, I have tried a bunch of times the python setup.py install command from
Alright, I know I've asked similar questions, but I feel this is hopefully a
Alright... this seems complicated for me.. I don't know if it is. filename: add_types.js
Alright. Hopefully this will be my last post about the download manager I am

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.