Re: opening a file



On Thu, 08 Jan 2009 10:52:23 -0800, Jürgen Exner wrote:

cartercc <cartercc@xxxxxxxxx> wrote:
On Jan 7, 9:50 pm, George <geo...@xxxxxxxxxxxxxxx> wrote:
I thought I would use perl instead of fortran to parse a text file, what
with the new m// s/// capabilities at my fingertips.

Easy, easy, easy ...

open INFILE, "<nameoffile.txt";

Most people would suggest to use the three-argument form of open:
open INFILE, '<', 'nameoffile.txt';

Almost all people would strongly suggest to test for failure:
open INFILE, '<', 'nameoffile.txt' or
die "Cannot open nameoffile.txt because $!\n";

jue

Apparently, going out and getting drunk was exactly what this script
needed, as well as comments that helped.

open(50, '<eph4.txt');
DO:
{ my $line = readline(*50);
if(eof != 0) { exit }
print $line; # no 'write' here
redo DO } # no 'end' possible
close(50)

# perl faulk4.pl

C:\MinGW\source>perl faulk4.pl
Sun 18h 41m 55s -23░ 5.4' 0.983 10.215 52.155 Up
Mercury 20h 2m 16s -22░ 12.5' 1.102 22.537 37.668 Up
Venus 21h 55m 33s -14░ 16.3' 0.795 39.872 11.703 Up
Moon 21h 17m 19s -15░ 2.4' 62.4 ER 36.796 22.871 Up
Mars 18h 11m 59s -24░ 6.1' 2.431 4.552 56.184 Up
Jupiter 20h 3m 35s -20░ 49.4' 6.034 23.867 38.203 Up
Saturn 11h 32m 59s +5░ 8.6' 9.018 -47.333 157.471 Set
Uranus 23h 21m 30s -4░ 57.9' 20.421 48.328 -18.527 Up
Neptune 21h 39m 30s -14░ 22.8' 30.748 38.963 16.599 Up

C:\MinGW\source>

Tja.
--
George

It's clearly a budget. It's got a lot of numbers in it.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
.



Relevant Pages

  • Re: opening a file
    ... George wrote: ... open INFILE, '<', 'nameoffile.txt'; ... again no test for failure (although it would ... have cought the misspelled file name as evidenced in a different post). ...
    (comp.lang.perl.misc)
  • Re: a simple control in an nntp client
    ... Picture of the Day http://apod.nasa.gov/apod/ ... Typical George W. Bush fan. ...
    (comp.lang.perl.misc)
  • Re: Inquiring minds want to know ...
    ... You can't put democracy and freedom back into a box. ... George W. Bush ... Picture of the Day http://apod.nasa.gov/apod/ ...
    (misc.news.internet.discuss)
  • Re: Quote...
    ... predecessors as well. ... George W. Bush ... Picture of the Day http://apod.nasa.gov/apod/ ...
    (misc.news.internet.discuss)
  • Re: White House Staff Takes Shape
    ... I will never relent in defending America - whatever it takes. ... George W. Bush ... Picture of the Day http://apod.nasa.gov/apod/ ...
    (misc.news.internet.discuss)