in reply to TIMTOWTDI Challenge: Open a file

Here's one:

unshift @ARGV, $rfile; while( <> ) { # .... }

Or how about this:

use Tie::File; tie my @array, 'Tie::File', $rfile or die;

Here's another variation on the @ARGV theme...

#!/usr/bin/perl -p BEGIN{ $rfile = 'myfile.txt'; unshift @ARGV, $rfile; }

Update:
By the way, I won't attempt to justify any of these abominations other than to state the obvious; they're just for fun.


Dave

Replies are listed 'Best First'.
Re^2: TIMTOWTDI Challenge: Open a file
by apotheon (Deacon) on Apr 19, 2006 at 06:24 UTC

    I'm pretty fond of the diamond operator and just feeding a filename to the script when it's called.

    #!/usr/bin/perl while (<>) { # do stuff }

    and . . .

    $ script.pl filename

    I guess it's the KISS principle applied to getting data from a file.

    print substr("Just another Perl hacker", 0, -2);
    - apotheon
    CopyWrite Chad Perrin