Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Strange problem reading a text file

by tariqahsan (Beadle)
on Jun 13, 2003 at 20:05 UTC ( [id://265787]=perlquestion: print w/replies, xml ) Need Help??

tariqahsan has asked for the wisdom of the Perl Monks concerning the following question:

I am seeing this strange problem reading a file from an
user defined perl library module -- my.pm. Atleast the
problem is quite strange to me.
The footer information of a generated output text file
is getting cutoff while trying to read from this my.pm
But while I read the file from another script it prints
out fine. Some of the statements from script that
generates the output file - doReport.pl, the last few
lines from the output file - output.txt, and the my.pm

doReport.pl:

use my.pm; ... format FOOTER = @|||||||||||||||||||||||||||||||||| S = Scheduled R = Requested ... "MyCompany Information Systems" .

my.pm :

package my; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(print_report); sub print_report { $file = "output.txt"; open (FILE,"$file") || die "Can't open $file for reading: $!\n"; while ( defined($_ = <FILE>) ) { print $_; } }

output.txt:

The last line from the file before the footer note - WRITTEN-OFF EVENTS 20030614 Daily EN_US`AWS`20030613`20030613` +YES

prints with out the footer notes!
Any idea why this is happening?

20030614 Edit by Corion: Added formatting and CODE tags

Replies are listed 'Best First'.
Re: Strange problem reading a text file
by halley (Prior) on Jun 13, 2003 at 20:20 UTC
    (1) The word 'my' is a reserved keyword, so you may want to choose a different name for your module.

    (2) Module names which are not capitalized are traditionally "pragmatic" modules, involved in changing the behavior of the perl interpreter or interpretation of Perl code itself. You may want to capitalize your package name.

    (3) You may want to use a utility like perltidy to help you write code that's more clear for reading. And use <code> ... </code> tags on this site to retain all the source code in the simplest format. You won't have to type all those <br>'s and angle bracket codes.

    (4) Your question was why the last output didn't appear? Though I don't see anything wrong with your code as-is, I'm not very familiar with the old 'format' mechanism. It may be a simple problem with a missing newline at the end of your input. On some terminals, the last line of output will not appear if it was not followed with a newline (because the next command prompt erases it).

    --
    [ e d @ h a l l e y . c c ]

      Halley
      Firstly thanks for your reply
      . The actual pm library in use is "Atlys.pm"
      The strange thing I can get read the output file correctly
      without any problem if it is read out
      from another script other than the pm script
      I tried to put a newline character like doing -
       print "$_\n";
      But did'nt help
Re: Strange problem reading a text file
by converter (Priest) on Jun 13, 2003 at 21:08 UTC

    The answer to your question can be found in the first paragraph of the perlform man page. The command perldoc perlform at the prompt will display the information on most systems.

Re: Strange problem reading a text file
by Nkuvu (Priest) on Jun 13, 2003 at 20:37 UTC

    When using formats, don't you have to use the write command instead of print?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://265787]
Approved by Jazz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-25 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found