Well i was bore so i tryed to do the excersises on the tutorial section of perlmonks i found this one: Write a program that prompts the user for the name of a file to open and then reads in the file line by line. When it has finished reading the file it should print the lines in reverse order with this solution:
#!/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;
the program is functional but i just think in this way
#!perl -w use strict; my $file; print "Enter a filename: "; chomp ( $file = <STDIN> ); open ( FILE, "$file" ); for (reverse (<FILE>)){ print; } close FILE;
i just want to know which is better is something like a perl golf :D, thx

In reply to Better Way to Do It by cored

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.