Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

RE: File Input and Output

by Anonymous Monk
on May 03, 2000 at 04:57 UTC ( [id://10019]=note: print w/replies, xml ) Need Help??


in reply to File Input and Output

running this code: open(FILE, "data.txt"); #opens data.txt in read-mode while(<FILE>){ #reads line by line from FILE which is the filehandle for data.txt chomp; print "Saw $_ in data.txt\n"; #shows you what we have read } close FILE; #close the file. results in: # perl test1 syntax error at test1 line 5, near "<" syntax error at test1 line 5, near ">" Execution of test1 aborted due to compilation errors.

Replies are listed 'Best First'.
RE: RE: File Input and Output
by turnstep (Parson) on May 03, 2000 at 06:07 UTC
    root just forgot that you don't need to escape less-than and greater-than signs inside <CODE> tags. Obviously, it should read:
    while(<FILE>)
      So, in summary, here's how you deal with open():

      #!/usr/bin/perl print"Gimmie a filename to examine: "; $filename=<STDIN>; open(FILE,$filename); while(<FILE>) { chomp; print "Found $_ in $filename" } close FILEDESC;
        Actually, it should be:
        print "Gimme a filename to examine: "; chop($filename=<STDIN>); ## Not many filenames have a newline... open(FILE, $filename) || die "Could not open $filename: $!\n"; while(<FILE>) { chomp; print "Found $_ in $filename\n" ## Need a newline here! } close(FILE); ## not FILEDESC...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-18 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found