jeudi 28 juillet 2016

(empty?) return of readline is not caught by control structure

I have a multidimensional hash containing opened file handles on SEEK_END with the intention to always read the latest line without getting to much I/O (what I would get with tail).

I'm now going through all of these handles with a for loop and calling readline on them.

It looks like this:

for $outer ( keys %config ) {

    my $line = readline($config{$outer}{"filehandle"});

    if (not defined $line || $line eq '' ){
        next;
    }
    else{
        print "\nLine: -->".$line."<--\n";
        $line =~ m/(:)(\d?\.?\d\d?\d?\d?\d?)/;
        $wert = $2;
    }
}

If new content is written into these files, my script reads it and behaves just as planned.

The problem is that readline will usually return nothing because there is currently nothing at the end of the file, but my if doesn't seem to identify the empty return of readline as undef as empty -- it just prints nothing, which is would be right because there is nothing in this string, but I don't want it to be processed at all.

Aucun commentaire:

Enregistrer un commentaire