Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: File Input and Output

by Hofmator (Curate)
on Jul 24, 2001 at 14:39 UTC ( #99281=note: print w/ replies, xml ) Need Help??


in reply to What is the error in my script or file setup?
in thread File Input and Output

mmhhh, different possibilites that this doesn't work

  • try if this works:
    use strict; use warnings; my @list; while(<DATA>) { chomp; push @list, $_; } my $i="harv"; foreach my $list (@list) { if($i eq $list) { print "YES!\n"; } } __DATA__ fred 20.4 harv 5.6 tony 5.13 dennis 401.1
    The DATA section behaves exactly like a file - inside your file and you don't have to open it. If it does then
  • check if your file opened correctly (and specify the opening mode): open (FILE, "<", "input.dat") or die "Couldn't open input.dat: $!";
    The die will abort the program if 'input.dat' couldn't be opened. The $! variable contains an error message and is set automatically if an error during the open occured.
  • You should use strict; and use warnings; (equivalent to perl -w). It protects you from typing mistakes - there aren't any in your example, this is more general advice. And it shows useful warnings if you do some possibly 'stupid' things.

-- Hofmator


Comment on Re: Re: File Input and Output
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2015-07-28 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls