Your general coding style is reminiscent of Perl 4. So I hope you don't mind if I make a few general style suggestions.

$filename = @ARGV[0];

I think you meant to type $ARGV[0]. Writing @ARGV[0] is a slice and is almost never what you want.

open (FILE,"$filename") || die "Can't Open $filename: $!\n";

Prefer the low precedence or to ||. Also, you don't need the quotes around $filename. Finally, unless you are stuck with an ancient perl, employ the modern three argument form of open with a lexical file handle (see example code below).

Also, don't forget the option of slurping into a string rather than an array. Quite often, it's more convenient to process the file contents with regexes on a string, rather than line by line from an array. For example.

use strict; my $filename = shift; open(my $fh, '<', $filename) or die "Can't open $filename: $!"; my $text = do { local $/; <$fh> }; # slurping into a string # do something with $text here

Update: for more information on file slurping idioms, see Load file into a scalar without File::Slurp, especially merlyn's response.


In reply to Re: Slurping file into array VS Process file line-by-line by eyepopslikeamosquito
in thread Slurping file into array VS Process file line-by-line by monkfan

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.