473,396 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Use of uninitialised values error when values have been initialised :(

Hi, as a bit of background (and seeing as it is my first post :)) i am a complete newbie at perl. I literally picked it up a week ago to do this project as it seemed like the best choice for a language to connect to a SQL database in a Unix envirment as well as script parsing so there is more than likely a ton of things i could have done a better way.
I have been at this for 3 days now and cant for the life of me work out why the code is piping out errors

Th input into the code for sake of simplicity as i think the rest of my errors are essentially the same thing is:
Expand|Select|Wrap|Line Numbers
  1. Dec 16 07:50:22 xxxx-vpn-xxx 1765156 12/16/2007 07:50:21.110 SEV=6 IKEDBG/64 RPT=183939 10.100.250.100  IKE Peer included IKE fragmentation capability flags: Main Mode:        True Aggressive Mode:  False
The code works but the errors i am getting are:
Use of uninitialized value in concatenation (.) or string at parser.pl line 62.
at parser.pl line 62
Use of uninitialized value in concatenation (.) or string at parser.pl line 64.
at parser.pl line 64

Now i know this means that a value wasn't declared or explicitly stated but i cant see how this is possible as i give them all the value 'null' when i declare them and then these null values are changed where necessary,
Before in the
Expand|Select|Wrap|Line Numbers
  1. if ($currentIP eq $sessionIP){ }
statements, even though essentially the code wouldnt get that far because it would be caught by
Expand|Select|Wrap|Line Numbers
  1. if($currentCode=~ m/(IKEDBG\/64)|(IKE\/52)|.....|(IKE\/49)|(IKE\/75)/){
As being an invalid line adding a check to see if sessionIP contained something got rid of the error message

This is just a snippet so it probably wont compile if you would like more please dont hesitate to ask

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl-w
  2.                   #-w use warnings
  3.                   #-T use Taint to ensure program is secure
  4.  
  5. use strict;                     #Force variable declarations
  6. # Functions to locate errors
  7. use Carp ();
  8. local $SIG{__WARN__} = \&Carp::cluck;
  9.  
  10.  
  11. #=== Delcare Varibles ===#
  12. my $line = undef;               #Line to be processed
  13. my $file = 'testLog.txt';       #Path to log file
  14. my @log = undef;              #Stores lines from log file
  15.  
  16. # Session Data Array as global (to avoid un-neccesary processing when passed into function)
  17. our @sessions = (
  18.     # Session Data Holding Variables
  19.     {'clientIPAddress' => undef,    #Address assigned from IP pool
  20.      'currentCode' => 'Initialiser',#Current IKE code being processed
  21.      'connectDate' => 'null',        #Date of connection to access point
  22.      'connectTime' => 'null',        #Time of connection to access point
  23.      'userID' => 'null',             #Username unique to user
  24.      'authenticationTime' => 'null', #Time user's has been authenticated
  25.      'groupID' => 'null',            #VPN group user belongs to (usually Roamnet)
  26.      'platformType' => 'null',       #Platform user is running Windows, Unix etc..
  27.      'clientVersion' => 'null',      #Version of VPN client
  28.      'vpnPoolAddress' => 'null',     #IP address assigned from VPN pool
  29.      'disconnectTime' => 'null',     #Time session was disconnected
  30.      'duration' => 'null',           #Duration of session
  31.      'bytesTx' => 'null',            #Bytes Transmitted
  32.      'bytesRx' => 'null',            #Bytes Recieved
  33.      'reasonForDisconnect' => 'null',#Reason for connection termination
  34.      'errorMessages' => undef,      #Additional error messages
  35.      'state' => 'Disconnected'      #State of session
  36.    }
  37. );
  38.  
  39.  
  40. #=== Get data from file ===
  41. open(LOG, $file) or die "Cannot open $!";    #Open file under the handle LOG
  42.  
  43. for $line (<LOG>){      #Read file into @log
  44.   if($line){
  45.     chomp($line);       #Removes new line character from entry
  46.     process_log($line); #Call function to precess log line
  47.   } else {              #Check to see if line is empty
  48.     print 'Warning Line is Empty <BR>\n';
  49.   }
  50.  
  51. }
  52. close(LOG);             #Close the log file
  53.  
  54.  
  55.  ### =================== TESTING - REMOVE ME = =============================
  56.  my $totalSessions = scalar (@sessions);
  57.  print ':::';
  58.  for (my $n=0; $n < $totalSessions; $n++){
  59.        print 'currentcode = '.$sessions[$n]{"currentCode"}.'<br>';
  60.        print 'connectdate = '.$sessions[$n]{"connectDate"}.'<br>';
  61.        print 'connecttime = '.$sessions[$n]{"connectTime"}.'<br>';
  62.        print 'clientip = '.$sessions[$n]{"clientIPAddress"}.'<br>';
  63.        print 'state = '.$sessions[$n]{"state"}.'<br>';
  64.        print 'authentication date = '.$sessions[$n]{"authenticationDate"}.'<br>';
  65.        print 'authentication time = '.$sessions[$n]{"authenticationTime"}.'<br>';
  66.        print 'userID = '.$sessions[$n]{"userID"}.'<br>';
  67.        print 'groupID = '.$sessions[$n]{"groupID"}.'<br>';
  68.        print 'platformType = '.$sessions[$n]{"platformType"}.'<br>';
  69.        print 'clientVersion = '.$sessions[$n]{"clientVersion"}.'<br>';
  70.        print 'vpnPoolAddress = '.$sessions[$n]{"vpnPoolAddress"}.'<br>';
  71.        print 'disconnectTime = '.$sessions[$n]{"disconnectTime"}.'<br>';
  72.        print 'duration = '.$sessions[$n]{"duration"}.'<br>';
  73.        print 'bytesTx = '.$sessions[$n]{"bytesTx"}.'<br>';
  74.        print 'bytesRx = '.$sessions[$n]{"bytesRx"}.'<br>';
  75.        print 'reasonForDisconnect = '.$sessions[$n]{"reasonForDisconnect"}.'<br>';
  76.        print 'errorMessages = '.$sessions[$n]{"errorMessages"}.'<br>';
  77.        print '<br>';
  78.    }
  79.  ### =========== END TESTING ==============================================
  80.  
  81.  
  82.  #=== Sub Routines ===
  83.  
  84.  sub process_log { #Script to parse logs
  85.  
  86.  #== Parameters passed into function ==
  87.  #$line (@_) line being processed
  88.  
  89.  #== Declare Variables ==
  90.  my $currentCode = undef;                          #Code being processed
  91.  my $currentIP = undef;                            #IP of line being processed
  92.  my $currentUserID = undef;                        #UserID of line being processed
  93.  my $numberOfSessions = undef;                     #Number of sessions in the array
  94.  my $data = undef;                                 #Stores result of regex expressions
  95.  my $currentLine = undef;                          #Whole Line currently being processed
  96.  my $errors = undef;                               #Stores erorrs in log parsing
  97.  my $sessionIP = undef;                            #Used to store IP for session during search
  98.  my $sessionUserID = undef;                        #Used to store userID for session during search
  99.  #=== Store elements from line ===
  100.  
  101.  $currentLine = shift;                              #Get line passed into function
  102.  my @seperatedLine = split(/\s/, $currentLine);     #Split line based on empty space delimitation
  103.  $currentIP = $seperatedLine[10];                   #Get IP from line
  104.  $numberOfSessions = scalar (@sessions);            #Get number of elements sessions array
  105.  $currentLine =~ m/SEV=\d (.*) RPT/;                #Extract current code from line
  106.  $currentCode = $1;                                 #Get current code
  107.  
  108.  if($currentCode){                                  #Check if line contains a code
  109.   }else{
  110.    #no code found
  111.    next;
  112.  }
  113.  
  114.  #Check for an unknown error code and corrupted lines
  115.  if($currentCode=~ m/(IKEDBG\/64)|(IKE\/52)|(AUTH\/5)|(IKE\/22)|(IKE\/100)|(IKE\/98)|(AUTH\/9)|(IKE\/167)|(IKE\/184)|(AUTH\/22)|(IKE\/194)|(IKE\/119)|(IKE\/136)|
  116. (IKE\/25)|(IKE\/34)|(IKE\/50)|(AUTH\/28)|(IKE\/123)|(IKE\/66)|(IKE\/120)|(IKE\/49)|(IKE\/75)/){
  117.     #code found
  118. }else{
  119.   $errors = 'Log Error: \''.$currentLine.'\'<BR>';
  120.   #print $errors; #========================== Save error to log file/database =========================
  121.   next;
  122. }
  123.  
  124.  # IKE/DBG64
  125.  if ($currentCode eq 'IKEDBG/64'){
  126.       for (my $i=1; $i <= $numberOfSessions; $i++){                 #Check to see if session already exists
  127.         $sessionIP = $sessions[$i]{"clientIPAddress"};              #Get IP for selected session
  128.         if($sessionIP){                                             #Check if line contains a IP
  129.           if ($currentIP eq $sessionIP){                            #Compare IP
  130.             #-Session Exists-
  131.             #Check for illegal connections (session not terminated correctly)
  132.             my $sessionState = $sessions[$i]{"state"};              #Get current state of session
  133.             if ($sessionState eq 'Disconnected'){
  134.               #--Legal Session--
  135.               $sessions[$i]{"state"} = 'Connecting';                #Progress state to connecting
  136.               last;                                                 #Break out of loop
  137.               }else{
  138.               #--Illegal Session--
  139.               #Error Message
  140.               $sessions[$i]{"reasonForDisconnect"} = 'Session was not teminated correctly and has been termintated by parser';
  141.               save_session($i);                                     #Call save_session function
  142.               splice(@sessions,$i,1);                               #Delete the current session
  143.               #Create new session
  144.               create_new_session($i);
  145.               $sessions[$i]{"clientIPAddress"} = $seperatedLine[10];#Used as key for session
  146.               $sessions[$i]{'currentCode'} = $currentCode;          #Store current code for debugging
  147.               $sessions[$i]{"connectDate"} = $seperatedLine[5];
  148.               $sessions[$i]{"connectTime"} = $seperatedLine[6];
  149.               last;                                                 #Break out of loop
  150.             }
  151.           }
  152.         }else{
  153.           #-Session doesn't exist-
  154.           #Create new session
  155.           create_new_session($numberOfSessions);                                 #As the array starts from 0, $numberOfSessions will
  156.                                                                                  #always be greater than the index for the last session.
  157.           $sessions[$numberOfSessions]{"clientIPAddress"} =  $seperatedLine[10]; #Used as key for session
  158.           $sessions[$numberOfSessions]{'currentCode'} = $currentCode;            #Store current code
  159.           $sessions[$numberOfSessions]{"connectDate"} = $seperatedLine[5];
  160.           $sessions[$numberOfSessions]{"connectTime"} = $seperatedLine[6];
  161.         }
  162.       }
  163.  }
  164.  
Any help would be much appreciated

Thanks
Jan 12 '08 #1
4 3722
KevinADC
4,059 Expert 2GB
It appears that variables, like 'clientIPAddress' => undef, are not initialized before you try printing a little bit later:

print 'clientip = '.$sessions[$n]{"clientIPAddress"}.'<br>';

same with

print 'authentication date = '.$sessions[$n]{"authenticationDate"}.'<br>';

there is no "authenticationDate" in the initial data set @sessions. Why are you using an array that contains an annonymous hash? Are there more annonymous hashes in the array?
Jan 12 '08 #2
It appears that variables, like 'clientIPAddress' => undef, are not initialized before you try printing a little bit later:

print 'clientip = '.$sessions[$n]{"clientIPAddress"}.'<br>';

same with

print 'authentication date = '.$sessions[$n]{"authenticationDate"}.'<br>';

there is no "authenticationDate" in the initial data set @sessions.
Maybe it's me being dim I dont quite understand :s, surely the set is initialised when i make the template entry and put 'null' values into them from the get go

i use the same method to create a new "session" later on in the function create_session.(see below)
If anything shouldn't it just print 'null'?
I used undef for the client IP and other things so that i could do a check to see if there was anything in the variable, if there wasnt the loop would break and if there was it would continue to try avoid the uninitialised problems


Expand|Select|Wrap|Line Numbers
  1. sub create_new_session {            #Script to create a blank session
  2.  
  3.  my $sessionID = shift;                                  #Session ID
  4.  # Create empty session
  5.  $sessions[$sessionID]{'clientIPAddress'} = undef;    #Address assigned from IP pool
  6.  $sessions[$sessionID]{'currentCode'} = 'Initialiser';        #Current IKE code being processed
  7.  $sessions[$sessionID]{'connectDate'} = 'null';        #Date of connection to access point
  8.  $sessions[$sessionID]{'connectTime'} = 'null';        #Time of connection to access point
  9.  $sessions[$sessionID]{'userID'} = 'null';             #Username unique to user
  10.  $sessions[$sessionID]{'authenticationDate'} = 'null'; #Date user's has been authenticated
  11.  $sessions[$sessionID]{'authenticationTime'} = 'null'; #Time user's has been authenticated
  12.  $sessions[$sessionID]{'groupID'} = 'null';            #VPN group user belongs to (usually Roamnet)
  13.  $sessions[$sessionID]{'platformType'} = 'null';       #Platform user is running Windows, Unix etc..
  14.  $sessions[$sessionID]{'clientVersion'} = 'null';      #Version of VPN client
  15.  $sessions[$sessionID]{'vpnPoolAddress'} = 'null';     #IP address assigned from VPN pool
  16.  $sessions[$sessionID]{'disconnectTime'} = 'null';     #Time session was disconnected
  17.  $sessions[$sessionID]{'duration'} = 'null';           #Duration of session
  18.  $sessions[$sessionID]{'bytesTx'} = 'null';            #Bytes Transmitted
  19.  $sessions[$sessionID]{'bytesRx'} = 'null';            #Bytes Recieved
  20.  $sessions[$sessionID]{'reasonForDisconnect'} = undef;#Reason for connection termination
  21.  $sessions[$sessionID]{'errorMessages'} = undef;      #Additional error messages
  22.  $sessions[$sessionID]{'state'} = 'Disconnected';      #State of session
  23. } #End Create empty session
  24.  
Why are you using an array that contains an annonymous hash? Are there more annonymous hashes in the array?
It's because more than one session needs to be tracked at any one time as the script is intended to parse live logs, therefore needs to be done on a line by line basis rather than pull a session out the logs save it and move on.

I created the empty session at the top to make the code easier to read and so i could delcare and initialise all the variables to try avoid the error i am getting
Jan 12 '08 #3
eWish
971 Expert 512MB
If anything shouldn't it just print 'null'?
If you want insert a null value into the db you have to use 'undef'. Otherwise, you are just printing the word 'Null' which is not the same as a null/undefined value.

Here is an example where if $value is not defined, then it will use undef.
Expand|Select|Wrap|Line Numbers
  1. my $value = $some_other_value || undef;
Jan 13 '08 #4
KevinADC
4,059 Expert 2GB
the value of 'null' is a string, so those variables are defined, undef means undefined, so any value assigned the value of undef is undefined.

use warnings;
$foo = undef;
print $foo;

The above returns a warnings about "uninitialized value in print" which is essentially the same warning you are getting.
Jan 14 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tom | last post by:
Hi I am installing Oracle9ias onto a United Linux 1.0 and encountering the following error at "Single Sign On Configuration Assistant", any idea? .... PL/SQL procedure successfully...
22
by: Gene Wirchenko | last post by:
Is the following guaranteed safe? void InitInt(int & SomeInt) { SomeInt=3; return; } int main() {
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
13
by: santosh | last post by:
Hi, If I call free() with a uninitialised pointer, will the program state become undefined, or will free() return harmlessly? Incidentally, is there a way in Standard C to determine weather a...
27
by: Madhav | last post by:
Hi all, I did not understand why do the global vars are initialized to NULL where as the block level variables have random values? I know that the C standard requires this as was mentioned in a...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
by: geek.arnuld | last post by:
this is the programme: #include <iostream // std::cout int main() { int sum; std::cout << sum << "\n"; }
4
by: BlueJ | last post by:
My program is to send data using socket.. but I got the error message: "sendto(msg) points to uninitialised byte(s) " This is my source code 1. key_list = emalloc(BUFSIZE - sizeof(Key) -...
19
by: Ulrich Eckhardt | last post by:
Greetings! I was recently surprised by the compiler's warning concerning this code: struct text { char* s; size_t len; }; int main() { struct text t = {"hello world!"};
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.