FAQ
Hello,

In the following script my goal is pull the date value each time an error value (hardcoded) is found in the specified log file. The script retrieves the error value without a problem but I cannot seem get the date value. Can anyone tell me what I need to do?

The error message when I run the script is:

Use of uninitialized value in concatenation (.) or string at script.pl line 32

where line 32 is where I am calling this:

"print $date";

Here is the script:

use warnings;
use strict;

#Specify the path to the log file you want to read, for ex. application log#

open (FILEHANDLE, 'd:/scripts/server2.log') or print "Can't Open File!!!";

while(( my $line = <FILEHANDLE>)) {

#Searching for keywords from application log#

if (($line =~ m/CQCommitException/i ) || ($line =~ m/Communication link failure/i)) {

my @fields = split '\|', $_;
my $date = $fields[1];

print $date;

#prints $line to file
open (my $outfile, ">>", "d:/scripts/loginfo.txt") or die "Can't open loginfo.txt: $!";

print $outfile "$date, $_\n";

#close $outfile or die "$outfile:$!";

}
}

my $outfile = 'd:/scripts/loginfo.txt';

#To send or not to send - file size check

#Delete file when done
#unlink 'd:\scripts\loginfo.txt';

-END-

Search Discussions

  • Mark Meyer at Jan 27, 2011 at 10:41 pm
    Can you send an example of the data in the log file?

    tm
  • Parag Kalra at Jan 27, 2011 at 10:46 pm
    When you are already storing the line under $line
    while(( my $line = <FILEHANDLE>)) {
    Then why are you using $_
    my @fields = split '\|', $_;
    Cheers,
    Parag


    On Thu, Jan 27, 2011 at 12:57 PM, CM Analyst wrote:

    Hello,

    In the following script my goal is pull the date value each time an error
    value (hardcoded) is found in the specified log file. The script retrieves
    the error value without a problem but I cannot seem get the date value. Can
    anyone tell me what I need to do?

    The error message when I run the script is:

    Use of uninitialized value in concatenation (.) or string at script.plline 32

    where line 32 is where I am calling this:

    "print $date";

    Here is the script:

    use warnings;
    use strict;

    #Specify the path to the log file you want to read, for ex. application
    log#

    open (FILEHANDLE, 'd:/scripts/server2.log') or print "Can't Open File!!!";

    while(( my $line = <FILEHANDLE>)) {

    #Searching for keywords from application log#

    if (($line =~ m/CQCommitException/i ) || ($line =~ m/Communication link
    failure/i)) {

    my @fields = split '\|', $_;
    my $date = $fields[1];

    print $date;

    #prints $line to file
    open (my $outfile, ">>", "d:/scripts/loginfo.txt") or die "Can't open
    loginfo.txt: $!";

    print $outfile "$date, $_\n";

    #close $outfile or die "$outfile:$!";

    }
    }

    my $outfile = 'd:/scripts/loginfo.txt';

    #To send or not to send - file size check

    #Delete file when done
    #unlink 'd:\scripts\loginfo.txt';

    -END-




    --
    To unsubscribe, e-mail: [email protected]
    For additional commands, e-mail: [email protected]
    http://learn.perl.org/

  • CM Analyst at Jan 28, 2011 at 12:25 am
    This is a sample of the data I am reading in:

    [#|2011-01-19T07:05:10.734-0800|WARNING|sun-appserver2.1|javax.enterprise.system.stream.err|_ThreadID=15;_ThreadName=httpSSLWorkerThread-8080-1;_RequestID=c5cefdc4-4651-4c77-b9e6-84f9e0f6609e;|]
    com.raec.cq.CQCommitException: You wanted to commit a modifyCR based record, but the record was not found in the ClearQuest Database.
    [#|2011-01-19T07:05:10.734-0800|WARNING|sun-appserver2.1|javax.enterprise.system.stream.err|_ThreadID=15;_ThreadName=httpSSLWorkerThread-8080-1;_RequestID=c5cefdc4-4651-4c77-b9e6-84f9e0f6609e;|]
    com.raec.cq.CQCommitException: You wanted to commit a modifyCR based record, but the record was not found in the ClearQuest Database.
    [#|2011-01-19T07:05:10.734-0800|WARNING|sun-appserver2.1|javax.enterprise.system.stream.err|_ThreadID=15;_ThreadName=httpSSLWorkerThread-8080-1;_RequestID=c5cefdc4-4651-4c77-b9e6-84f9e0f6609e;|]
    com.raec.cq.CQCommitException: You wanted to commit a modifyCR based record, but the record was
    not found in the ClearQuest Database.


    --- On Thu, 1/27/11, Parag Kalra wrote:


    From: Parag Kalra <[email protected]>
    Subject: Re: Need help with Use of uninitialized value in concatenation (.) or string
    To: "CM Analyst" <[email protected]>
    Date: Thursday, January 27, 2011, 6:03 PM


    Ok. Post sample from the log file to entire list. :)


    Cheers,
    Parag




    On Thu, Jan 27, 2011 at 4:02 PM, CM Analyst wrote:

    Yes, changiing to $line does not make a difference.

    On Thu Jan 27th, 2011 5:31 PM CST Parag Kalra wrote:

    No problem. :)

    But are you still facing the issue?

    Cheers,
    Parag


    On Thu, Jan 27, 2011 at 3:27 PM, CM Analyst wrote:

    Lack of experience :-(

    --- On *Thu, 1/27/11, Parag Kalra wrote:


    From: Parag Kalra <[email protected]>
    Subject: Re: Need help with Use of uninitialized value in concatenation (.)
    or string
    To: "CM Analyst" <[email protected]>
    Cc: [email protected]
    Date: Thursday, January 27, 2011, 4:45 PM


    When you are already storing the line under $line
    while(( my $line = <FILEHANDLE>)) {
    Then why are you using $_
    my @fields = split '\|', $_;
    Cheers,
    Parag


    On Thu, Jan 27, 2011 at 12:57 PM, CM Analyst <[email protected]<http://us.mc380.mail.yahoo.com/mc/[email protected]>
    wrote:
    Hello,

    In the following script my goal is pull the date value each time an error
    value (hardcoded) is found in the specified log file. The script retrieves
    the error value without a problem but I cannot seem get the date value. Can
    anyone tell me what I need to do?

    The error message when I run the script is:

    Use of uninitialized value in concatenation (.) or string at script.plline 32
    where line 32 is where I am calling this:

    "print $date";

    Here is the script:

    use warnings;
    use strict;

    #Specify the path to the log file you want to read, for ex. application
    log#

    open (FILEHANDLE, 'd:/scripts/server2.log') or print "Can't Open File!!!";

    while(( my $line = <FILEHANDLE>)) {

    #Searching for keywords from application log#

    if (($line =~ m/CQCommitException/i ) || ($line =~ m/Communication link
    failure/i)) {

    my @fields = split '\|', $_;
    my $date       = $fields[1];

    print $date;

    #prints $line to file
    open (my $outfile, ">>", "d:/scripts/loginfo.txt") or
    die "Can't open
    loginfo.txt: $!";

    print $outfile "$date, $_\n";

    #close $outfile or die "$outfile:$!";

    }
    }

    my $outfile = 'd:/scripts/loginfo.txt';

    #To send or not to send - file size check

    #Delete file when done
    #unlink 'd:\scripts\loginfo.txt';

    -END-




    --
    To unsubscribe, e-mail: [email protected]<http://us.mc380.mail.yahoo.com/mc/[email protected]>
    For additional commands, e-mail: [email protected]<http://us.mc380.mail.yahoo.com/mc/[email protected]>
    http://learn.perl.org/



  • Mark Meyer at Jan 28, 2011 at 1:00 am
    Ok

    I took your code and your "log" file and did some testing on my linux box.

    this small snippet of code seems to parse the lines (you actually want to grab) in a predictable manner.

    tm


    while(( my $line = <FILEHANDLE>)) {
    # print "my line is: >$line<", "\n";

    if ($line =~ /^\[/) {
    print "this is a line i need to keep: \n\n";
    print "$line\n\n";
    my @fields = split '\|', $line;
    my $date = $fields[1];
    print "my date is: $date", "\n";
    }
    }

    -----Original Message-----
    From: CM Analyst
    Sent: Thursday, January 27, 2011 6:25 PM
    To: Parag Kalra
    Cc: [email protected]
    Subject: Re: Need help with Use of uninitialized value in concatenation
    (.) or string

    This is a sample of the data I am reading in:

    [#|2011-01-19T07:05:10.734-0800|WARNING|sun-
    appserver2.1|javax.enterprise.system.stream.err|_ThreadID=15;_ThreadName=h
    ttpSSLWorkerThread-8080-1;_RequestID=c5cefdc4-4651-4c77-b9e6-
    84f9e0f6609e;|]
    com.raec.cq.CQCommitException: You wanted to commit a modifyCR based
    record, but the record was not found in the ClearQuest Database.
    [#|2011-01-19T07:05:10.734-0800|WARNING|sun-
    appserver2.1|javax.enterprise.system.stream.err|_ThreadID=15;_ThreadName=h
    ttpSSLWorkerThread-8080-1;_RequestID=c5cefdc4-4651-4c77-b9e6-
    84f9e0f6609e;|]
    com.raec.cq.CQCommitException: You wanted to commit a modifyCR based
    record, but the record was not found in the ClearQuest Database.
    [#|2011-01-19T07:05:10.734-0800|WARNING|sun-
    appserver2.1|javax.enterprise.system.stream.err|_ThreadID=15;_ThreadName=h
    ttpSSLWorkerThread-8080-1;_RequestID=c5cefdc4-4651-4c77-b9e6-
    84f9e0f6609e;|]
    com.raec.cq.CQCommitException: You wanted to commit a modifyCR based
    record, but the record was
    not found in the ClearQuest Database.


    --- On Thu, 1/27/11, Parag Kalra wrote:


    From: Parag Kalra <[email protected]>
    Subject: Re: Need help with Use of uninitialized value in concatenation
    (.) or string
    To: "CM Analyst" <[email protected]>
    Date: Thursday, January 27, 2011, 6:03 PM


    Ok. Post sample from the log file to entire list. :)


    Cheers,
    Parag




    On Thu, Jan 27, 2011 at 4:02 PM, CM Analyst wrote:

    Yes, changiing to $line does not make a difference.

    On Thu Jan 27th, 2011 5:31 PM CST Parag Kalra wrote:

    No problem. :)

    But are you still facing the issue?

    Cheers,
    Parag


    On Thu, Jan 27, 2011 at 3:27 PM, CM Analyst wrote:

    Lack of experience :-(

    --- On *Thu, 1/27/11, Parag Kalra wrote:


    From: Parag Kalra <[email protected]>
    Subject: Re: Need help with Use of uninitialized value in concatenation
    (.)
    or string
    To: "CM Analyst" <[email protected]>
    Cc: [email protected]
    Date: Thursday, January 27, 2011, 4:45 PM


    When you are already storing the line under $line
    while(( my $line = <FILEHANDLE>)) {
    Then why are you using $_
    my @fields = split '\|', $_;
    Cheers,
    Parag


    On Thu, Jan 27, 2011 at 12:57 PM, CM Analyst
    <[email protected]<http://us.mc380.mail.yahoo.com/mc/compose?to=cmanalys
    [email protected]>
    wrote:
    Hello,

    In the following script my goal is pull the date value each time an
    error
    value (hardcoded) is found in the specified log file. The script
    retrieves
    the error value without a problem but I cannot seem get the date value.
    Can
    anyone tell me what I need to do?

    The error message when I run the script is:

    Use of uninitialized value in concatenation (.) or string at
    script.plline 32


    where line 32 is where I am calling this:

    "print $date";

    Here is the script:

    use warnings;
    use strict;

    #Specify the path to the log file you want to read, for ex. application
    log#

    open (FILEHANDLE, 'd:/scripts/server2.log') or print "Can't Open
    File!!!";
    while(( my $line = <FILEHANDLE>)) {

    #Searching for keywords from application log#

    if (($line =~ m/CQCommitException/i ) || ($line =~ m/Communication link
    failure/i)) {

    my @fields = split '\|', $_;
    my $date       = $fields[1];

    print $date;

    #prints $line to file
    open (my $outfile, ">>", "d:/scripts/loginfo.txt") or
    die "Can't open
    loginfo.txt: $!";

    print $outfile "$date, $_\n";

    #close $outfile or die "$outfile:$!";

    }
    }

    my $outfile = 'd:/scripts/loginfo.txt';

    #To send or not to send - file size check

    #Delete file when done
    #unlink 'd:\scripts\loginfo.txt';

    -END-




    --
    To unsubscribe, e-mail: beginners-
    [email protected]<http://us.mc380.mail.yahoo.com/mc/compose?to=beginner
    [email protected]>
    For additional commands, e-mail: beginners-
    [email protected]<http://us.mc380.mail.yahoo.com/mc/compose?to=beginners-
    [email protected]>









    --
    To unsubscribe, e-mail: [email protected]
    For additional commands, e-mail: [email protected]
    http://learn.perl.org/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedJan 27, '11 at 8:57p
activeJan 28, '11 at 1:00a
posts5
users3
websiteperl.org

People

Translate

site design / logo © 2023 Grokbase