Melly has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks
I'm trying to understand the different behaviour of file-handles and similar (e.g. '<DATA>').
I don't think I'd ever really thought about them - they just worked - but I ran into a problem with CSV_XS and getline. Basically, why does a FH variable work (e.g. $IN), but <IN> and <DATA> don't.
The following code is non-functional without commenting out stuff, but should illustrate what I mean.
use Text::CSV_XS; my $csv = Text::CSV_XS->new(); open(my $IN, '<', 'test.csv'); # ok open(IN, '<', 'test.csv'); # nope my $row = $csv->getline(<DATA>); # nope - Usage: Text::CSV_XS::getline +(self, io) at test_02.pl line 11, <IN> line 2. my $row = $csv->getline(<IN>); # nope - Usage: Text::CSV_XS::getline +(self, io) at test_02.pl line 11, <IN> line 2. my $row = $csv->getline($IN); # ok print ${$row}[0]; __DATA__ a,b,c d,e,f
So, what is the difference between "open(IN..." and "open($IN..."? (and is there a way to alias <DATA> to, e.g., $DATA?)
Ah - \*DATA or \*IN - err, what does '\*' imply?
Tom Melly, pm (at) cursingmaggot (stop) co (stop) ukmap{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Filehandles and CSV_XS (updated)
by haukex (Archbishop) on Sep 01, 2023 at 10:46 UTC | |
by Melly (Chaplain) on Sep 01, 2023 at 10:55 UTC | |
by eyepopslikeamosquito (Archbishop) on Sep 01, 2023 at 13:09 UTC | |
by NERDVANA (Priest) on Sep 02, 2023 at 06:50 UTC | |
Re: Filehandles and CSV_XS
by ikegami (Patriarch) on Sep 01, 2023 at 13:36 UTC |