Dear Monks, it's good to know we can still reach each other. Perlmonks was completely offline a couple days ago. I felt like someone had stabbed me in the shoulder blade.
So what I am doing this cold winter's eve is playing Mr. Helpful with someone else's code, again. Tonight, it's Proc-PID-File 1.29. In running the test suite I tripped several instances of the warning Use of uninitialized value in pattern match (m//) at blib/lib/Proc/PID/File.pm line 286. I will in the interests of convenience to the reader, show the subroutine (with inserted comment by me) below:
# Returns the process id currently stored in the file set. If the met +hod # is passed a file handle, it will return the value, leaving the file +handle # locked. This is useful for atomic operations where the caller needs + to # write to the file after the read without allowing other dirty writes +. # # Please note, when passing a file handle, caller is responsible for # closing it. Also, file handles must be passed by reference! sub read { my ($self, $fh) = @_; sysopen($fh, $self->{path}, O_RDWR|O_CREAT) || die qq/Cannot open pid file "$self->{path}": $!\n/; flock($fh, LOCK_EX | LOCK_NB) || die qq/pid "$self->{path}" already locked: $!\n/; # WARNING: Use of uninitialized value in pattern match (m//): my ($pid) = <$fh> =~ /^(\d+)/; close $fh if @_ == 1; $self->debug("read(\"$self->{path}\") = " . ($pid || "")); return $pid; }
Is readline really returning undefined? If so, under what conditions (aside from an empty file) would readline return undef? If it would do no harm, we could sort it by saying no warnings "undefined"; in the scope of the subroutine. Any observations, good monks?
Feb 17, 2025 at 03:30 UTCA just machine to make big decisions
Programmed by fellows (and gals) with compassion and vision
We'll be clean when their work is done
We'll be eternally free yes, and eternally young
Donald Fagen -> I.G.Y.
(Slightly modified for inclusiveness)
In reply to Undefined value returned on call to readline (<>)? by Intrepid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |