in reply to Re^5: Split output by tabs
in thread Split output by tabs
I do understand the syntax of Perl filehandles. The ambiguity comes between printing to a filehandle and printing a variable to STDOUT. i.e.:
open my $f, '>out.txt' or die 'ouch!'; print $f 'foo'; ... my $f = 'bar'; print $f, 'foo';
These two similar looking print statements do something very different. It is not a big deal in this case, but when you replace 'foo' with an expression it can be hard to tell whether $f is a filehandle or a variable. In fact, sometimes even the interpreter can't tell, as the documentation you linked to points out:
(NOTE: If FILEHANDLE is a variable and the next token is a term, it may be misinterpreted as an operator unless you interpose a + or put parentheses around the arguments.)
Here is a simple example that the compiler can't correctly handle without braces:
use warnings; use strict; open my $f, '>out.txt' or die 'ouch!'; $_=' eeee'; my $e='e'; #supposed to be a pattern match, but interpreted as division. print $f / $e/ ? 'yes' : 'no';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Split output by tabs (bogus best practice)
by shmem (Chancellor) on Nov 13, 2012 at 14:48 UTC | |
by ColonelPanic (Friar) on Nov 13, 2012 at 15:36 UTC | |
by shmem (Chancellor) on Nov 13, 2012 at 16:03 UTC | |
by tye (Sage) on Nov 13, 2012 at 17:04 UTC | |
by shmem (Chancellor) on Nov 13, 2012 at 20:21 UTC | |
|
Re^7: Split output by tabs
by Anonymous Monk on Nov 13, 2012 at 15:01 UTC | |
by ColonelPanic (Friar) on Nov 13, 2012 at 15:19 UTC | |
by Anonymous Monk on Nov 13, 2012 at 15:33 UTC |