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 3238916
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:54:32+00:00 2026-05-17T17:54:32+00:00

#!/usr/bin/perl -w use strict; open (EVENTLOGFILE, <eventlog.txt) || die(Could not open file eventlog file);

  • 0
#!/usr/bin/perl -w
use strict;

open (EVENTLOGFILE, "<eventlog.txt") || die("Could not open file eventlog file");
open (EVENTLOGFILE_NODATETIME, ">eventlog_nodatetime.txt") || die("Could not open new event log file");


my($line) = "";

while ($line = <EVENTLOGFILE>) {
 my @fields = split /[ \t]/, $line;
 my($newline) = "";
 my($i) = 1;

 foreach( @fields )
 {
  my($field) = $_;
  if( $i ne 3 )
  {
   $newline = $newline . $field;
  }

  $i++;
 }

 print EVENTLOGFILE_NODATETIME "$newline";
}

close(EVENTLOGFILE);
close(EVENTLOGFILE_NODATETIME); 

If I print out $line each time instead of $newline it can detect the encoding no problem. It’s only when I try to modify the lines that it gets messed up.

  • 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-05-17T17:54:33+00:00Added an answer on May 17, 2026 at 5:54 pm

    I guess it isn’t encoding (as in say ISO 8859-1 vs UTF-8) but line-endings (CR, LF vs LF).

    If you used chomp and printed “\n” you’d probably get line endings converted to platform native.

    I think your script might be better written something like this (Untested):

    #!/usr/bin/perl 
    use strict;
    use warnings;
    
    open ($old, '<', 'eventlog.txt') or die 'Could not open eventlog.txt';
    open ($new, '>', 'eventlog_nodatetime.txt') 
      or die 'Could not open eventlog.nodatetime.txt');
    
    $\ = "\n";
    
    while (<$old>) {
      chomp;
      s/^(\S+\s+\S+\s+)\S+\s+(.*)/$1$2/;
      print $new;
    }
    
    close $old;
    close $new; 
    

    Or

    perl -pe 's/^(\S+\s+\S+\s+)\S+\s+(.*)/$1$2/' eventlog.txt >eventlog.nodatetime.txt
    

    Or use a splice on a split?
    Or …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#!usr/bin/perl use strict; use warnings; my $file_name = rem.txt; open(FILE, $file_name); while (<FILE>) {
#!/usr/bin/perl use strict; use warnings; open(my $vmstat, /usr/bin/vmstat 1 2>&1 |); open(my $foo, >,
Consider the following code and its output: Code #!/usr/bin/perl -w use strict; use Data::Dumper;
I have this code: #!/usr/bin/perl use strict; use Tkx; my $mw = Tkx::widget->new('.'); $mw->g_wm_minsize(
I have this code #!/usr/bin/perl use strict; my @a = (b,a,d,c); my %h =
I am executing a diff command in perl . my @lines = `/usr/local/bin/diff -udr
ho-fe3fdd00-12:~ Sam$ easy_install BeautifulSoup Traceback (most recent call last): File /usr/bin/easy_install, line 8, in
can anybody explain me this print statement in the following perl program. #! /usr/bin/perl
I am converting a linux script from http://www.perlmonks.org/index.pl?node_id=217166 specifically this: #!/usr/bin/perl -w use strict;
The following test fails: #!/usr/bin/env python def f(*args): >>> t = 1, -1 >>>

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.