in reply to Re^2: print() on closed filehandle WRITE_FH
in thread print() on closed filehandle WRITE_FH
Download and save this as demo.pl:
#!/usr/bin/perl use strict; use warnings; my $fn='lotr.txt'; open my $fh,'>',$fn or die "Could not open $fn: $!"; print "Three Rings for the Elven-kings under the sky,\n"; print $fh "The Road goes ever on and on\n"; print "Seven for the Dwarf-lords in their halls of stone,\n"; print $fh "Down from the door where it began.\n"; print "Nine for Mortal Men doomed to die,\n"; print $fh "Now far ahead the Road has gone,\n"; print "One for the Dark Lord on his dark throne\n"; print $fh "And I must follow, if I can,\n"; print "In the Land of Mordor where the Shadows lie.\n"; print $fh "Pursuing it with eager feet,\n"; print "One Ring to rule them all, One Ring to find them,\n"; print $fh "Until it joins some larger way\n"; print "One Ring to bring them all and in the darkness bind them\n"; print $fh "Where many paths and errands meet.\n"; print "In the Land of Mordor where the Shadows lie.\n"; print $fh "And whither then? I cannot say.\n"; close $fh;
Then run it:
X:\>perl demo.pl Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone, Nine for Mortal Men doomed to die, One for the Dark Lord on his dark throne In the Land of Mordor where the Shadows lie. One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them In the Land of Mordor where the Shadows lie. X:\>type lotr.txt The Road goes ever on and on Down from the door where it began. Now far ahead the Road has gone, And I must follow, if I can, Pursuing it with eager feet, Until it joins some larger way Where many paths and errands meet. And whither then? I cannot say. X:\>
/tmp>perl demo.pl Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone, Nine for Mortal Men doomed to die, One for the Dark Lord on his dark throne In the Land of Mordor where the Shadows lie. One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them In the Land of Mordor where the Shadows lie. /tmp>cat lotr.txt The Road goes ever on and on Down from the door where it began. Now far ahead the Road has gone, And I must follow, if I can, Pursuing it with eager feet, Until it joins some larger way Where many paths and errands meet. And whither then? I cannot say. /tmp>
(Both quotes from The Fellowship of the Ring by J. R. R. Tolkien)
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: print() on closed filehandle WRITE_FH
by TonyNY (Beadle) on Sep 26, 2018 at 12:28 UTC | |
by hippo (Archbishop) on Sep 26, 2018 at 13:14 UTC | |
by poj (Abbot) on Sep 26, 2018 at 12:58 UTC | |
by AnomalousMonk (Archbishop) on Sep 26, 2018 at 15:35 UTC |