in reply to Re: Reading and writing to files
in thread Reading and writing to files

Merlyn, your code truely is beautiful. It is very simple, and effective.

I am stepping through it to make sure I understand everything. Are the text files read into the arrays in the second and third lines:
my @daily = do { local @ARGV = "daily.txt"; <> }; my @monthly = do { local @ARGV = "monthly.txt"; <> };
In the fourth line, you don't have to use #@daily (or whatever that operator is that returns the index of the last element)?

Again, wow!


v2: Thank you, Christian. Wow, very beautiful.

Replies are listed 'Best First'.
RE: Reading and writing to files: Debrief Question
by cmburns (Acolyte) on Aug 09, 2000 at 17:10 UTC
    Hi!

    I'll just answer that question, since merlyn has stated often enough that he doesn't have the time to answer all the "easy" questions.

    Lines 2 and 3 put those filenames into the @ARGV array, which has the same effect as putting those filenames in the commandline (@ARGV contains all words in the commandline after the name of the called script.) The operator <> reads from all the filenames on the commandline, or from STDIN if there are no filenames on the commandline. So line 2 and 3 actually do read those files into those arrays without needing an open statement. Beautiful!

    In line 4, the array @daily is used in a scaler context, since it is compared with a scalar (3). In a scalar context an array returns its length, in this case the number of lines in the file. So you don't need that # operator, although you could use it.

    I hope I got that all right, I'm pretty new to perl myself. My compliments to merlyn, that is very short yet very readable code. Perl is beautiful!

    Christian