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

Use of uninitialized value $lines1 in substitution (s///) at

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; ++$n; $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); }e; my $backup = "$_.backup"; unlink $backup if -f $backup; rename $_, $backup; open my $out_fh, '>', $_; print $out_fh @lines; close $out_fh; } closedir DIR;

In reply to Error "Use of uninitialized value $lines[0] in substitution (s///) at " with below Code by Eric_h

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.