Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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


In reply to Re: Use of uninitialized value $site in concatenation (.) when excute the perl script (an aside - code review) by MidLifeXis
in thread Use of uninitialized value $site in concatenation (.) when excute the perl script by laksh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (7)
    As of 2015-07-30 17:47 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (273 votes), past polls