Skip to content

Instantly share code, notes, and snippets.

@jyotty
Created December 26, 2011 16:41
Show Gist options
  • Select an option

  • Save jyotty/1521579 to your computer and use it in GitHub Desktop.

Select an option

Save jyotty/1521579 to your computer and use it in GitHub Desktop.
This is why ‘use warnings' is important and ‘use diagnostics’ is helpful
$ perl -E'open my $fh, "test"; print {$fh} "butts"'
$ perl -Mwarnings -E'open my $fh, "test"; print {$fh} "butts"'
Filehandle $fh opened only for input at -e line 1.
$ perl -Mwarnings -Mdiagnostics -E'open my $fh, "test"; print {$fh} "butts"'
Filehandle $fh opened only for input at -e line 1 (#1)
(W io) You tried to write on a read-only filehandle. If you intended
it to be a read-write filehandle, you needed to open it with "+<" or
"+>" or "+>>" instead of with "<" or nothing. If you intended only to
write the file, use ">" or ">>". See "open" in perlfunc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment