Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: while loop returning numbers not strings

by jaffinito34 (Acolyte)
on Dec 05, 2012 at 18:20 UTC ( [id://1007358]=note: print w/replies, xml ) Need Help??


in reply to Re: while loop returning numbers not strings
in thread while loop returning numbers not strings

I'm trying to split the file.. each line is a new word

  • Comment on Re^2: while loop returning numbers not strings

Replies are listed 'Best First'.
Re^3: while loop returning numbers not strings
by Kenosis (Priest) on Dec 05, 2012 at 19:49 UTC

    ...I take in a text file (words.txt) where there is a new word each line.

    If each line is one word, splitting isn't necessary. Adapting your script, you can do the following:

    #!/usr/bin/env perl use strict; use warnings; open my $words, '<', 'words.txt' or die $!; while ( my $word = <$words> ) { print $word; } print "\n\n"; close $words;

    You may have noticed from the excellent responses that lexical variables (my) are used. It's best to follow this practice--even with file handles. Also, always use strict; and use warnings;. It's also best to handle open errors, in case there was a problem opening a file.

    Hope this helps!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-04-23 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found