Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics

Nobody in particular
rj [...]

(no value)
Broken in:
(no value)
Fixed in:
(no value)

Subject: false positive "unreachable code"
Date: Tue, 15 May 2007 13:05:25 +0200
From: Richard Jelinek <>
With the following code, perlcritic complains about "Unreachable code" at line 35 and line 51. I do not see any reason, why this should be so. Richard -------------------- package File2; use strict; use warnings; sub move_file { my $from = shift; # ARG1: get source filename (path) my $to = shift; # ARG2: get target filename (path) my $ret = 1; # return value for successfull(1 = default)/unsuccessfull operation return $ret if (rename($from, $to)); # return true, if on same filesystem (and moved) if (open my $FROM, '<:raw', $from)) { # if source opened successfully if (open my $TO, '>:raw', $to)) { # if target opened successfully while(<$FROM>) { # iterate source and get content print $TO; # write content to target } close $TO; # close target filehandle } else { # target file could not be opened $ret = 0; # indicate error } close $FROM; # close source filehandle } if ($ret # if success in move && (-s $from == -s $to)) { # and source & target of same size unlink($from); # remove source from filesystem } else { # something went wrong unlink $to; # remove target file $ret = 0; # set flag } return $ret; # indicate success/failure } <------------------------------- HERE ???? sub write_file { my $name = shift; # ARG1: get filename (path) my $content = shift; # ARG2: get content (reference) if (open my $DATA, '>:raw', $name) { # if open filename for writing ok print $DATA $$content; # save content close $DATA; # close filehandle return 1; # indicate success } return; # indicate failure } 1; <------------------------------- HERE ???? ---------------
Hi Richard- In your example code, there are some extra parens around the first to "open" functions. If you remove those, then you won't get the "unreachable code" violations. Perl::Critic doesn't compile your code, so it doesn't actually know if it is syntactically valid. The PPI engine just does its best to try and understand what you've written. Probably a good habit to do "perl -c" before using perlcritic. Hope that helps! -Jeff

This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with to