-1

I have to make a modification to an existing PERL script. As I have no experience in PERL Scripting i googled and made a change but that's not working. So there is part that checks if a specific timestamp exists in the file. the code is

    while (<IN>) {
      if (/timestamp="(\w\w\w) (\d\d) \d\d:\d\d:\d\d (\d\d\d\d)"/ {
        $NowDate=$3.$Month{$1}.$2;
        if ( $NowDate > $StartDate ) {
          print OUT $_;
          while (1) {
            $regel=<IN>;
            if (! defined $regel) {last}
              print OUT $regel;
            }
          }
       }
  }
  • The timestamp in the log file = Feb 15 09:28:13 2017
  • but after upgrade the timestamp = 2017-02-15T10:26:14.858

i've updated the condition like this but it's not working.

if (/timestamp="(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)"/ 

Can anyone give me some advice here.

dNitro
  • 5,145
  • 2
  • 20
  • 45
Ilhan
  • 3
  • 1

1 Answers1

0
if ( /timestamp="(\d\d\d\d)-(\d\d)-(\d\d)T\d\d:\d\d:\d\d\.\d\d\d"/ ) {
    $NowDate = $1.$2.$3;
    ...
}
Borodin
  • 126,100
  • 9
  • 70
  • 144
  • The problem is I don't pass the if condition. the timestamp in the file is timestamp="2017-02-16T13:08:34.104" – Ilhan Feb 16 '17 at 12:24
  • You missed the fractional seconds from the pattern. Try now – Borodin Feb 16 '17 at 12:26
  • I've entered the if condition but get the following error "Use of uninitialized value in concatenation (.) or string at". Do I have to use the /. – Ilhan Feb 16 '17 at 12:30
  • Ilhan: If you have copied what I wrote then that can't happen. I don't know what you mean by *"Do I gave to use the /"* – Borodin Feb 16 '17 at 13:09
  • 2
    Whilst this code snippet is welcome, and may provide some help, it would be [greatly improved if it included an explanation](//meta.stackexchange.com/q/114762) of *how* and *why* this solves the problem. Remember that you are answering the question for readers in the future, not just the person asking now! Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Feb 16 '17 at 13:28