cored has asked for the wisdom of the Perl Monks concerning the following question:
the program is functional but i just think in this way#!/usr/bin/perl 2: 3: #this program prompts a user for the name of a source file 4: #and then reads from the file line by line. Once it is done 5: #reading the file it prints the lines of the file in reverse ord +er 6: 7: print "What is the name of the source file? "; 8: $file=<>; 9: chomp($file); 10: open FILE, "<$file"; 11: while(<FILE>){ 12: push @lines,$_; 13: } 14: foreach(reverse @lines){ 15: print $_; 16: } 17: close FILE;
i just want to know which is better is something like a perl golf :D, thx#!perl -w use strict; my $file; print "Enter a filename: "; chomp ( $file = <STDIN> ); open ( FILE, "$file" ); for (reverse (<FILE>)){ print; } close FILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Better Way to Do It
by broquaint (Abbot) on May 17, 2003 at 22:22 UTC | |
by Abigail-II (Bishop) on May 17, 2003 at 23:03 UTC | |
by broquaint (Abbot) on May 17, 2003 at 23:16 UTC | |
|
Re: Better Way to Do It
by Chady (Priest) on May 18, 2003 at 11:33 UTC |