Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Use of uninitialized value $site in concatenation (.) when excute the perl script (an aside - code review)

by MidLifeXis (Monsignor)
on Aug 31, 2012 at 13:07 UTC ( #991003=note: print w/replies, xml ) Need Help??


in reply to Use of uninitialized value $site in concatenation (.) when excute the perl script

Take this or leave it, but there are some practices in your code that have a faint whiff of cargo culting or things that may cause problems later on. I understand that this code may just be an example.

#!/usr/bin/perl -w # MLX - Note that the above line also turns on warnings # MLX - in any other modules that you use or require. # MLX - The 'use warnings' pragma below may be more of # MLX - what you intended use strict; use warnings; my ($time, $site, $logName, $fullName, $date, $gmt, $req, $file, $prot +o, $status, $length); # # MLX - You may want to move as much of this declaration # MLX - into the foreach loop, unless you really need the # MLX - data from the last pass through the loop afterwards. # $site; # # MLX - Not sure what you want to do with this one. It # MLX - is a no-op. my $LOGFILE = "config.txt"; # open LOGFILE,"$LOGFILE" or die "cannot open file : $!"; # # MLX - Excellent use of 'open or die "foo: $!"'! # # MLX - If $LOGFILE is assigned from something you don't # MLX - have complete control over, it can be used in # MLX - the 2-argument version of open to overwrite # MLX - another file. Better would be: open LOGFILE,'<', $LOGFILE or die "cannot open file : $!"; # MLX - Another 'improvement' might be to use lexical # MLX - file handles: 'open my $log_fh, ... ' foreach my $line (<LOGFILE>) { ($site, $logName, $fullName, $date, $gmt, $req, $file, $proto, $status, $length) = split(' ',$line); # MLX - Add a 'my' to the beginning of this unless # MLX - you need to have the data from the last pass # MLX - after the loop has terminated. my $a = "$site\n"; print "--$a\n"; my $b = "$logName\n"; print "==$b\n"; } close(LOGFILE);

--MidLifeXis

  • Comment on Re: Use of uninitialized value $site in concatenation (.) when excute the perl script (an aside - code review)
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991003]
help
Chatterbox?
[Corion]: 1nickt: I imagine (heh) that Agile done somewhat right will make the process (and why we postpone things) somewhat more explicit to the outsider, or at least the "who do we ask to postpone X"

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2017-12-11 12:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (289 votes). Check out past polls.

    Notices?