Leser: 27
1 2 3 4 5 6 7 8 9 10 11 12 13
#!perl use strict; use warnings; use utf8; use FileHandle; my $fh = FileHandle->new(*DATA, "r"); if( $fh ) { print $fh->getlines(); }else{ print "no fh"; }
1 2 3 4 5 6 7 8
my $fh = *DATA; if( $fh ) { print <$fh>; } else{ print "no fh"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/usr/bin/perl use strict; use warnings; readfh( *main::DATA ); sub readfh { my ($fh) = @_; while ( my $line = <$fh> ) { chomp $line; print ">>$line<<\n"; } } __DATA__ 1 2 3 5 72 13
1 2 3 4 5 6 7 8 9 10 11 12 13
use strict; use warnings; use IO::Handle; my $fh = \*DATA; print $fh->getlines; __DATA__ oans zwoa mehra
2011-03-31T10:45:59 murphyÜbrigens ist FileHandle soweit ich weiß veraltet und nurmehr ein Stub für IO::Handle.
1 2 3 4 5 6 7 8
use FileHandle; my $fh = \*DATA; bless $fh, 'FileHandle'; if( $fh ) { while ( my $line = $fh->getline ) { print $fh->tell . $line; } }
2011-03-31T11:02:36 Taulmarill[...]
Ganz veraltet ist FileHandle aber wohl nicht, es implementiert immerhin eigene Methoden, vor allem getline und getlines.
perldoc FileHandleNOTE: This class is now a front-end to the IO::* classes.
[...]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/usr/bin/perl use strict; use warnings; use utf8; use FileHandle; my $fh = *DATA; if( $fh ) { print $fh->getlines(); }else{ print "no fh"; } __DATA__ A B X Y Z