473,748 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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 3746
KevinADC
4,059 Recognized Expert Specialist
It appears that variables, like 'clientIPAddres s' => undef, are not initialized before you try printing a little bit later:

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

same with

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

there is no "authentication Date" 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
Chronictank
2 New Member
It appears that variables, like 'clientIPAddres s' => undef, are not initialized before you try printing a little bit later:

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

same with

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

there is no "authentication Date" 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 Recognized Expert Contributor
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 Recognized Expert Specialist
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 "uninitiali zed 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
3626
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 completed. Disconnected from Oracle9i Enterprise Edition Release 9.0.1.3.0 -
22
1901
by: Gene Wirchenko | last post by:
Is the following guaranteed safe? void InitInt(int & SomeInt) { SomeInt=3; return; } int main() {
8
10409
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 is not much help here either. Googling has given me a little help. This is my current understanding -- I would appreciate any comments or corrections... "" -- this means an empty string when applied to String data type, and also to Variant...
13
5017
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 pointer points to a valid block of allocated memory? Thanks for your time.
27
2809
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 recent thread. I want to know why this descrimination is in place. Can't all the variables be initialised to NULL automatically by the compiler? This would make programming a little easier.
23
7413
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 in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
2
277
by: geek.arnuld | last post by:
this is the programme: #include <iostream // std::cout int main() { int sum; std::cout << sum << "\n"; }
4
2608
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) - sizeof(byte) - sizeof(int)); bzero(key_list, sizeof(*key_list)); bp = key_list; memmove(bp, key, ID_LEN);
19
1616
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
8823
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9312
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.