Question: (Closed) Getting Error message "Use of uninitialized value $lines[0] in substitution" in Perl
gravatar for hemant.nitjsr
6.2 years ago by
hemant.nitjsr0 wrote:

Try to do manipulation in each file in incremental order. Below is my code n it's giving an error message.

Use of uninitialized value $lines[0] in substitution (s///) at ./ line 26.
Use of uninitialized value $lines[1] in substitution (s///) at ./ line 27.

As m new in Perl World kindly help.

#!/usr/bin/perl -w

use strict;
use warnings;
use 5.010;
use autodie;

use Time::Piece;
use Time::Seconds qw/ ONE_MINUTE /;

use constant DATE_FORMAT => '%Y%m%d%H%M%S';

my $n;

my $directory="/home/tt/Doc/Auto";
opendir(DIR, $directory) or die "couldn't open $directory: $!\n";
my @files = readdir DIR;

foreach (@files) {

  open my $in_fh, '<', $_;
  my @lines = <$in_fh>;
  close $in_fh;

  $lines[0] =~ s/4947000219\K(4947000219+)/$1+$n/e;
  $lines[1] =~ s{:20140924105028\K(\d+)}{
    my $tp = Time::Piece->strptime($1, DATE_FORMAT);
    ($tp + ONE_MINUTE * 2 * $n)->strftime(DATE_FORMAT);

  my $backup = "$_.backup";
  unlink $backup if -f $backup;
  rename $_, $backup;

  open my $out_fh, '>', $_;
  print $out_fh @lines;
  close $out_fh;
closedir DIR;

software error • 2.3k views
ADD COMMENTlink modified 6.2 years ago by Ram32k • written 6.2 years ago by hemant.nitjsr0

Hello hemant.nitjsr!

We believe that this post does not fit the main topic of this site.

This question is probably better for Stack Overflow

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.


ADD REPLYlink written 6.2 years ago by Alex Reynolds31k
Please log in to add an answer.
The thread is closed. No new answers may be added.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2141 users visited in the last hour