Thank You. Now I only get one error message:

C:\Src\pl>perl TTC.pl 33:[1] 33:[3] 33:[] print() on unopened filehandle PREVIOUSCHAPTERS at TTC.pl line 56. $Chapter[4]


Here is the revised code:
#!/usr/bin/perl use strict; use warnings; use constant MinChapter => 1; use constant MaxChapter => 4; $| = 1; use File::Basename; use Inline::Files -backup; my $MyName = (fileparse($0, '\..*'))[0]; my $Chapter; sub PickARandomChapter { my $Chapter; # # Get an Initial Random Chapter # $Chapter = int(rand(MaxChapter)) + MinChapter; # # Read in Previously Viewed Chapters # my $fh; my %PreviousChapters; while(<PREVIOUSCHAPTERS>) { chomp(); print(__LINE__ . ":\[$_\]\n"); if($_ ne '') { $PreviousChapters{$_} = 0; } } my $TriedChapters = 0; while($TriedChapters < MaxChapter) { if(exists($PreviousChapters{$Chapter})) { $TriedChapters++; $Chapter++; if($Chapter > MaxChapter) { $Chapter = MinChapter; } } else { $PreviousChapters{$Chapter} = 1; print PREVIOUSCHAPTERS "$Chapter\n"; return($Chapter); } } # # All Chapters have been read # Start Over # seek(PREVIOUSCHAPTERS, 0, 0); print PREVIOUSCHAPTERS "$Chapter\n"; return($Chapter); } if($ARGV[0]) { if(lc($ARGV[0]) eq 'next') { $Chapter = <LASTCHAPTER>; print("\$Chapter\[$Chapter\]\n"); $Chapter >= MaxChapter ? $Chapter = MinChapter : $Chapter++; print("\$Chapter\[$Chapter\]\n"); seek LASTCHAPTER, 0, 0; print LASTCHAPTER $Chapter . "\n"; close LASTCHAPTER; } elsif(($ARGV[0] =~ /\d+/) and $ARGV[0] > 0 and $ARGV[0] < 82) { $Chapter = $ARGV[0]; } else { print STDERR << "USAGE"; Usage: $MyName [ChapterNumber] [Next] $MyName - Prints a Random Chapter from the Tao Te Ching $MyName ChapterNumber - Prints ChapterNumber Chapter from the Tao Te C +hing $MyName Next - Prints the Next Chapter from the Tao Te Ching +Starting at Chapter 1 USAGE exit(1); } } else { $Chapter = PickARandomChapter(); } print("\$Chapter\[$Chapter\]\n"); __LASTCHAPTER__ 1 __PREVIOUSCHAPTERS__ 1 3 __CHAPTERS__ 1 foo foo bar foo bar baz 2 foo foo bar 3 foo foo bar baz 4 foo foo bar foo bar baz foo foo bar foo bar baz

In reply to Re^2: Inline::Files unopened filehandle errors (seek) by NateTut
in thread Inline::Files unopened filehandle errors by NateTut

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.