In trying to answer an old question in a clever way, I was going to attempt this, not knowing if it would succeed:
#!/usr/bin/env perl
use strict;
use warnings;
use Tie::File;
tie( my @data, 'Tie::File', \*DATA ) or die "Cannot tie DATA";
foreach ( @data ) {
print;
}
foreach ( @data ) {
print scalar reverse;
}
__DATA__
one
two
three
four
five
six
I expected it to either work, or die; what I got was unexpected:
#!/usr/bin/env perluse strict;use warnings;use Tie::File;tie( my @data, 'Tie::File', \*DATA ) or die "Cannot tie DATA";foreach ( @data ) { print;}foreach ( @data ) { print scalar reverse;}__DATA__onetwothreefourfivesixlrep vne/nib/rsu/!#;tcirts esu;sgninraw esu;eliF::eiT esu;"ATAD eit tonnaC" eid ro ) ATAD*\ ,'eliF::eiT' ,atad@ ym (eit{ ) atad@ ( hcaerof;tnirp }{ ) atad@ ( hcaerof;esrever ralacs tnirp }__ATAD__enoowteerhtruofevifxis
How on earth did attempting to tie __DATA__
into Tie::File
did it tie the script, and chomp
it too?!