Regex substitution on filehandle not giving warning

Viewed 83

Why is this not giving a warning (e.g. like "Regex substitution on a reference variable is illegal):

use strict;
use warnings;
my $fn = 'file.txt';
open ( my $fh, '>', $fn ) or die "Could not open file '$fn': $!";
print $fh "1,2,3,";
$fh =~ s/,$//;
print $fh "\n";
close $fh;
system "cat", $fn;

Output

1,2,3,

The same is true for any reference (not just GLOB references). Wouldn't it been better to print a warning in these cases, instead of silently ignoring the substitution operation?

0 Answers
Related