#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    10
    Rep Power
    0

    Global symbol requires explicit package name


    this is the code i have so far but i keep getting error when declaring my varibles

    Code:
    use DBI;
    use strict;
    
    my $dbName = "firstry";
    my $dbHost = "localhost";
    my $dsn    = "dbi:mysql:host=$dbHost;database=$dbName";
    my $user   = 'username';
    my $pass   = 'password';
    
    my $Log = 'log'
    
    #################Main Menu#########
    
    print "\n";
    print "Welcome to my server log file application\n";
    print "\n";
    
    print "This application was design by matthew cripps\n";
    
    print "\n";
    
    print "Please select which process you wish to run\n";
    
    print "\n";
    print "          [1]-Run log transfer\n";
    print "          [2]-Quit application\n";
    print "          [3]-Log Hits data\n";
    print "          [4]-Help\n";
    print "\n";
    print STDOUT "Please Enter Choice Now.\n";
    $choice =<STDIN>;
    chomp($choice);
    print "\n";
    print STDOUT "You chose $choice\n";
    
    #Sub Routine to return to the menu#####
    
    sub menu {
    
    print "\n";
    print "You have chosen not to exit - What would you like to do?\n";
    print "\n";
    print "Please select which process you wish to run\n";
    print "\n";
    print "          [1]-Run log transfer\n";
    print "          [2]-Quit application\n";
    print "          [3]-Log Hits data\n";		
    print "          [4]-Help\n";
    print "\n";
    print STDOUT "Enter choice now\n";
    $choice =<STDIN>;
    chomp($choice);
    print "\n";
    print STDOUT "You chose $choice\n";
    
    }
    ##########Quit#############################
    
    if($choice == "2"){
    print "You have chosen to quit,\n";
    print "Are you sure (y/n)\n";
    print "[1]= Yes\n";
    print "[2]= No\n";
    $ans = <STDIN>;
    
    if ($ans == "1"){
    print "Goodbye ! \n";
    print "Thank you for using this software\n";
    print "For more information about this software visit www.csc.liv.ac.uk/~u2mjc2\n"; 
    } 
    elsif ($ans ="2"){
    &menu
     }
    }
    
    ##########RunProg##########################
    
    elsif ($choice == "1") {
    print "You have chosen to run log transfer\n";
    print "Please wait........\n";
    sleep2;
    print "This program will now insert the log file into the $dbname database\n";
    print "Please enter the path of the log files to be passed to the database\n";
    $Path = <STDIN>;
    print "\n";
    #Open the log file
    open (LOG, "<$Path") or die "File : $Path cannot be opened or does not exist. Please sure the path is 
    correct. ie: C: /Logs/log.txt\n";
    
    
    my $dbconn = DBI->connect( $dsn, $user, $pass ) or die $!;
    
    
    open (LOGFILE,$logfile) || "Error opening log file\n";
    
    while (<LOGFILE>)
    { 
    
    
    #Remove newline character
    chomp;
    
    # Split transaction by using the space as delimiter 
    
    $IP = @Trans [0] ;
    
    #Match upto 1st period. first part is computer name 2nd part
    
    $IP= ~ m/^(\w+)\.(.*)$/;
    $CompName = $1;
    $Domain = $2;
    
    #UserName & password if required 
    
    $RFC931_ID = @Trans [1];
    $AuthUser = @Trans [2];
    
    #Date and time 
    ($Date, $Time ) = split /:/ , @Trans [3], 2;
    $Date = ~m/^\[(.+) $/;     			#removes [ from end of string
    $Date = $1;
    $GMT = @Trans [4];
    $GMT =~m/^(.+)\]$/; # removes ] from end of string
    $GMT = $1;
    
    
    #HTTP string command issued by the client 
    $HTTPCom = @Trans [5];
    $HTTPCom = ~ m/^"(\w+)$/; 			# removes " from front of the string
    $HTTPCom = $1;
    
    #HTTP request string issued by client
    $HTTPReq = @Trans [6];
    
    #HTTP Version used by the client
    $HTTPVer = @Trans [7];
    $HTTPVer = ~ m/^(.+)"$/; 			#removes " from end of the string
    
    #Server response code (ie 200 - sucess , 404 file not found)
    $ServerResp = @Trans [8];
    
    
    #Amount of bytes transferred between server and client
    $TransVol = @Trans[9];
    
    #Url where client was situated when making the requests
    $RefURL =@Trans [10];
    $RefURL = ~ m/^"(\w+) $/; 			# removes " from front of string
    $RefURL = $1;
    
    #Browser name and version by the client 
    ($Browser , $BrowVer ) = split /\//, $Trans [11];
    $Browser = ~m/^"(\w+)$/; 			# removes " from end of string 
    $Browser = $1;
    
    #Clients Operating system
    $OS = @Trans[12] . @Trans[13] . @Trans[14];
    #print "$OS\n";
    $OS = ~ m/^(.+) "$/; 				#removes " from end of string
    $OS = $1;
    
    
    my $query = $dbconn->prepare( "INSERT INTO common_log_format (col_1, col_2, col_3, col_4, col_5, col_6, col_7,col_8 , col_9 , col_10 ,col_11, col_12, col_13 ) VALUES ( "(Trans[0], Trans[1] ,Trans[2], Trans[3], Trans[4], Trans[5] ,Trans[6], Trans[7], Trans[8], Trans[9] ,Trans[10], Trans[11], Trans[12], Trans[13]); 
    
    
    
    }
    }  
    
    
    ###########LoadCounter######################
    
    elsif ($choice == "3"){
    print "You have chosen to view information about the amount of hits per page\n";
    print "Please wait while this information loads \n";
    sleep2;
    }
    ##########LoadHelp#########################
    elsif ($choice == "4"){
    print "Please wait loading help.......\n";
    print "\n";
    
    # open file
    open(HELP, "help.txt") or die("Unable to open file");
    
    # read file into an array
    @data = <HELP>;
    
    # close file 
    close(HELP);
    
    # print file contents
    
    foreach $line (@data)
    {
      print $line;
    }
    }
    ############Return to menu##################
    else{ 
    print "You must chose either [1] , [2] or [3], PLEASE ENTER choice again\n";
    print "Please enter choice again\n";
    
    & menu
    
    }
    any ideas?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Israel, Arad
    Posts
    350
    Rep Power
    11
    are you sure you have written it by yourself ???? -_O'
    I know it's annoying... but please... use the great,
    search.cpan.org - all the modules you need
    perldoc.com - The perl tutorial !
    and ofcourse....
    google.com - what can i say here... ,
    first !!!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Israel, Arad
    Posts
    350
    Rep Power
    11
    sorry......typo......
    Last edited by freaker2k4; April 20th, 2005 at 04:32 PM.
    I know it's annoying... but please... use the great,
    search.cpan.org - all the modules you need
    perldoc.com - The perl tutorial !
    and ofcourse....
    google.com - what can i say here... ,
    first !!!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Israel, Arad
    Posts
    350
    Rep Power
    11
    Damn........ do you use -w ????
    that's the first error message's line :
    "Found = in conditional, should be == at test.pl line 73."

    the rest global errors are :
    "syntax error at test.pl line 16, near "print""
    "syntax error at test.pl line 165, near ""INSERT INTO common_log_format (col_1, col_2, col_3, col_4, col_5, col_6, col_7,col_8 , col_9 , col_10 ,col_11, col_12, col_13 ) VALUES ( "(""

    even perl is laughing at you right now...... "test.pl has too many errors."
    I know it's annoying... but please... use the great,
    search.cpan.org - all the modules you need
    perldoc.com - The perl tutorial !
    and ofcourse....
    google.com - what can i say here... ,
    first !!!
  8. #5
  9. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,264
    Rep Power
    1810
    Just as an example of what to look for:
    You say you are declaring your variables, and you started out good with :
    Code:
    my $dbName = "firstry";
    my $dbHost = "localhost";
    my $dsn    = "dbi:mysql:host=$dbHost;database=$dbName";
    my $user   = 'username';
    my $pass   = 'password';
    But just a few lines later you have the line:
    Code:
    $choice =<STDIN>;
    That's the first time $choice was used. It was never declared. Since you are using 'strict', it should read as:
    Code:
    my $choice =<STDIN>;
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    10
    Rep Power
    0
    yes i wrote it myself , do you really think i would have this many errors if i have copied it off someone.

    well anyway, if i remove the part of the code which is for running the transfer of the log files into the database it seem to work fine, it is the part wheni have to connect to the database that i am having real problems with

    Code:
    
    elsif ($choice == "1") {
    print "You have chosen to run log transfer\n";
    print "Please wait........\n";
    sleep2;
    print "This program will now insert the log file into the $dbname database\n";
    print "Please enter the path of the log files to be passed to the database\n";
    $Path = <STDIN>;
    print "\n";
    #Open the log file
    open (LOG, "<$Path") or die "File : $Path cannot be opened or does not exist. Please sure the path is 
    correct. ie: C: /Logs/log.txt\n";
    
    
    my $dbconn = DBI->connect( $dsn, $user, $pass ) or die $!;
    
    open (LOGFILE,$logfile) || "Error opening log file\n";
    
    while (<LOGFILE>)
    { 
    
    
    #Remove newline character
    chomp;
    
    # Split transaction by using the space as delimiter 
    
    $IP = @Trans [0] ;
    
    #Match upto 1st period. first part is computer name 2nd part
    
    $IP= ~ m/^(\w+)\.(.*)$/;
    $CompName = $1;
    $Domain = $2;
    
    #UserName & password if required 
    
    $RFC931_ID = @Trans [1];
    $AuthUser = @Trans [2];
    
    #Date and time 
    ($Date, $Time ) = split /:/ , @Trans [3], 2;
    $Date = ~m/^\[(.+) $/;     			#removes [ from end of string
    $Date = $1;
    $GMT = @Trans [4];
    $GMT =~m/^(.+)\]$/; # removes ] from end of string
    $GMT = $1;
    
    
    #HTTP string command issued by the client 
    $HTTPCom = @Trans [5];
    $HTTPCom = ~ m/^"(\w+)$/; 			# removes " from front of the string
    $HTTPCom = $1;
    
    #HTTP request string issued by client
    $HTTPReq = @Trans [6];
    
    #HTTP Version used by the client
    $HTTPVer = @Trans [7];
    $HTTPVer = ~ m/^(.+)"$/; 			#removes " from end of the string
    
    #Server response code (ie 200 - sucess , 404 file not found)
    $ServerResp = @Trans [8];
    
    
    #Amount of bytes transferred between server and client
    $TransVol = @Trans[9];
    
    #Url where client was situated when making the requests
    $RefURL =@Trans [10];
    $RefURL = ~ m/^"(\w+) $/; 			# removes " from front of string
    $RefURL = $1;
    
    #Browser name and version by the client 
    ($Browser , $BrowVer ) = split /\//, $Trans [11];
    $Browser = ~m/^"(\w+)$/; 			# removes " from end of string 
    $Browser = $1;
    
    #Clients Operating system
    $OS = @Trans[12] . @Trans[13] . @Trans[14];
    #print "$OS\n";
    $OS = ~ m/^(.+) "$/; 				#removes " from end of string
    $OS = $1;
    
    
    while( my @data = <LOG> )
    
    my $query = $dbconn->prepare("INSERT INTO common_log_format VALUES (@Trans[0], @Trans[1] ,@Trans[2], @Trans[3], @Trans[4], @Trans[5] ,@Trans[6], @Trans[7], @Trans[8], @Trans[9] ,@Trans[10], @Trans[11], @Trans[12], @Trans[13]); 
    }
    }



    could someone please give me a working example of inserting values into a access database, once i have that i think i will be able to work the rest out

    thanks
  12. #7
  13. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,264
    Rep Power
    1810
    Sorry if I'm missing it, but your first script attempts to log in to a mySQL database:
    Code:
    my $dsn = "dbi:mysql:host=$dbHost;database=$dbName";
    If you want to log on to a Microsoft Access database instead then I suggest searching Google for 'perl DBI Microsoft Access'.

    The first link seems pretty good.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    10
    Rep Power
    0
    oh sorry, i must have put on the wrong file

    I have read about the perl DBI ODBC but still cant seem to work it out

    I have copied the example from this page

    http://www.tek-tips.com/faqs.cfm?fid=1467

    word for word but i still get a error saying

    bad name after a

    I have set up the DBI ODBC for Ms Acess but stillit wont work

    how can it be so hard to simply input data from a file into a database using perl?
  16. #9
  17. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,264
    Rep Power
    1810
    It's not hard for most databases. Sorry but I can't speak for MS Access. I don't use it and I find most Microsoft products weren't made for interoperability with outsiders.

    Here's the article I mentioned:
    http://www.databasejournal.com/featu...le.php/1408481
    Hope it helps.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    10
    Rep Power
    0
    ok i will read that and let u know how i get on

    thanx
  20. #11
  21. Reinvent the Circle
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Jonesville, MI
    Posts
    218
    Rep Power
    16

    Using strict with my, local, package globals


    About your variable declaring problems, I'm not sure you understand the part with "use strict;". This will cause the interpreter to be really strict with how you use your variables. It won't let you have a global variable unless it has the package name specified, such as "$main::choice". If you don't want it global, it must be declared with "my" or "local". Anyway, just a note for you or any other searchers who find this thread.
    -Yanno

    "If it will have to be done more than once, don't do it. Make something that does it for you."

    "If you want to get out of the box, you must not think outside the box, you must think about the box. In fact, think about destroying the box."

IMN logo majestic logo threadwatch logo seochat tools logo