Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by kcott (Abbot)
on Aug 31, 2012 at 09:21 UTC ( #990958=note: print w/ replies, xml ) Need Help??


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

You probably have blank lines in your input.

In the split doco, under "As another special case, ...", you'll see how your pattern (' ') is handled specially.

Whenever $line equals "\n", split(' ',$line) will return (): all of those 10 variables ($site, ..., $length) will be undef (i.e. "uninitialized value").

If you want to ignore them, you can do something like this:

foreach my $line (<LOGFILE>) { next if $line =~ /\A\Z/; ($site, ... ... }

[Aside: $a and $b are not good choices for variable names as they have special meaning to Perl - see perlvar]

-- Ken


Comment on Re: Use of uninitialized value $site in concatenation (.) when excute the perl script
Select or Download Code
Re^2: Use of uninitialized value $site in concatenation (.) when excute the perl script
by Anonymous Monk on Sep 02, 2012 at 14:43 UTC

    And, foreach my $line (<LOGFILE>) reads the whole LOGFILE straight into memory before starting to enumerate through the lines. (Unless Perl has special-case handling for that case. Which I don't recall Perl having.) The OP should use the iterator form: while (my $line = <LOGFILE>) {

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990958]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-12-27 22:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls