in reply to Perl doesn't read whole file

Could you perhaps post up your history.txt file? and the output from the 2nd part. Does it read to a certain line and then die? Or does it die at random times while reading?

Also, just a heads up. perl -w and the open are somewhat deprecated. Try use warnings; instead of the -w. And there is a 3 argument open to use instead of the older 2 argument style.

--
I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.

Replies are listed 'Best First'.
Re^2: Perl doesn't read whole file
by colonelcrayon (Novice) on Dec 02, 2007 at 23:47 UTC
    It's nice to see people willing to help a lost newbie :-) My history.txt file is on my public scratchpad but is ugly and hard to read (I didn't format it). The output is always "at thing line 8.ia MapationslER 6" where the 2nd part is made into a script called thing.
      While this doesn't address the mystery of a truncated file output - try the following with the history.txt file:
      perl -n00 -e 'print $1,"\n" if /Overall Grade.*?([\d.]+%)/ms' history. +txt

      That should produce

      95.9%

      i.e. the contents of line 32.

      See perlrun for command line switches, perlre for regular expressions.

      <update>

      Using a regular expression here is more reliable, since the line number where the sought information is stored arguably is more prone to changes than the format of the retrieved file.

      </update>

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        It works! I hope to get it all working in perl, but for now I'm happy with this shell script:
        #!/bin/bash perlgrade #perlgrade is the name of my grade downloading script perl -n00 -e 'print "French: $1","\n" if /Overall Grade.*?([\d.]+%)/ms +' /home/jesse/Desktop/grades/french.txt perl -n00 -e 'print "Math: $1","\n" if /Overall Grade.*?([\d.]+%)/ms' +/home/jesse/Desktop/grades/math.txt perl -n00 -e 'print "Biology: $1","\n" if /Overall Grade.*?([\d.]+%)/m +s' /home/jesse/Desktop/grades/biology.txt perl -n00 -e 'print "Band: $1","\n" if /Overall Grade.*?([\d.]+%)/ms' +/home/jesse/Desktop/grades/band.txt perl -n00 -e 'print "English: $1","\n" if /Overall Grade.*?([\d.]+%)/m +s' /home/jesse/Desktop/grades/english.txt perl -n00 -e 'print "World History: $1","\n" if /Overall Grade.*?([\d. +]+%)/ms' /home/jesse/Desktop/grades/history.txt

      Please post the file contents in this thread rather than on your scratch pad. Scratch pad contents are transient whereas thread contents may be useful to other people in the distant future.


      Perl is environmentally friendly - it saves trees
        I'll do that from now on. here it is:
        Student Report Current Grades 11/30/07 TERM 1: HONORS WORLD HISTORY PER 6 LEHMAN, JESSE Mrs. Williams South Anchorage High School Summary Item Points Grade Overall Grade 574.5/599 95.9% A - Category: Test/Quiz 190/200 95.0% A - Category: Homework 290.5/308 94.3% A - Category: Classwork 94/91 103.3% A+ - Completed Work Avg. 574.5/599 95.9% A - Missing Assignments 0 Term 1 Assignments # Date Category Assignment Score Points Grade 1 8/29/2007 Homework World Map 24/25 24/25 96.0% A 2 8/3/2007 Homework Greece Map 30/30 30/30 100.0% A+ 3 8/31/2007 Homework 5.2 quiz 10/10 10/10 100.0% A+ 4 9/4/2007 Classwork Homecoming Spirit Week Extra Credit 5 9/7/2007 Classwork Parthenon Video w/s 10/10 10/10 100.0% A+ 6 9/12/2007 Homework 5.3 outline 10/10 10/10 100.0% A+ 7 9/13/2007 Homework 5.4 quiz 10/10 10/10 100.0% A+ 8 9/21/2007 Classwork Greece Group Winners 5 5 Extra Credit 9 9/21/2007 Test/Quiz Greece Test Short Answer 96/100 96/100 96.0% A 10 9/20/2007 Classwork Greece Group Participation 24/25 24/25 96.0% A 11 9/27/2007 Homework Rome map 25/25 25/25 100.0% A+ 12 9/27/2007 Classwork Hannibal reading questions 6/6 6/6 100.0% A+ 13 10/4/2007 Homework Spartacus notes and research 10/10 10/10 100.0% A+ 14 10/5/2007 Homework 6.3 webnotes 10/10 10/10 100.0% A+ 15 9/27/2007 Homework 6.1 worksheet 13/13 13/13 100.0% A+ 16 10/9/2007 Homework chapter 6 crossword 8/8 8/8 100.0% A+ 17 10/9/2007 Homework 6.3 quiz 6/10 6/10 60.0% D 18 10/15/2007 Homework 6.4 quiz 10/10 10/10 100.0% A+ 19 10/18/2007 Homework chapter 6 review packet 17/17 17/17 100.0% A+ 20 10/18/2007 Test/Quiz ch 6 multiple choice test 94/100 94/100 94.0% A 21 10/18/2007 Classwork Rome board Game 29/30 29/30 96.7% A 22 10/17/2007 Classwork Board Game Group Scores 20/20 20/20 100.0% A+ 24 10/31/2007 Homework 10/31 spirit day Extra Credit 25 10/31/2007 Homework Chinese Dynasty Presenations 30/30 30/30 100.0% A+ 26 10/29/2007 Homework China Map 24.5/25 24.5/25 98.0% A+ 27 11/2/2007 Homework 8.1 quiz 8/10 8/10 80.0% B- 29 11/14/2007 Homework Krgyzstan Presentation Extra Credit 30 11/13/2007 Homework Japan/Korea/SEAsia Map 25/25 25/25 100.0% A+ 31 11/16/2007 Homework 11.3 Quiz 8/10 8/10 80.0% B- 32 11/13/2007 Homework 11.1 Quiz 4/10 4/10 40.0% F 33 11/28/2007 Homework 17.4 Quiz 8/10 8/10 80.0% B-