Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: Re: I'm so confused

by jarich (Curate)
on Nov 24, 2001 at 11:21 UTC ( #127244=note: print w/replies, xml ) Need Help??


in reply to Re: Re: I'm so confused
in thread I'm so confused

You might want to be using the <> operator here. <> reads from the files passed in ARGV (if they exist) or from STDIN otherwise. This means that you can have this behaviour with no extra effort if you want it in the future.

It'll certainly save you from having to worry about opening each of those files and the like. So your code could simplify to:

#!/usr/bin/perl -w use strict; use diagnostics; if(-e "out.txt") { # complain about file. } my @out; while(<>) { chomp; push @out, lc($_); } # do stuff with @out: @out = sort @out; # print it (to STDOUT for the moment) print join("\n", @out);
I agree with everyone else here, that you probably don't want to be inserting the newline until you're ready to output the data. If you decide, for some reason, later to reverse all the characters on each of your lines or some such, that newline character can get in the way.

Good luck.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2021-10-23 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (88 votes). Check out past polls.

    Notices?