creating variables on the fly (newbie question)

Joshua Keroes jkeroes at eli.net
Thu Jan 11 19:17:39 CST 2001


I misread the first question. Here's one way you could parse 
that file and gen [and print] that AoA. I've used $/ to
read the filehandle F in paragraphs. Next, we turn each
paragraph into a subarray with one element/line:

__BEGIN__

#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my $AoA_ref = parse_file( "your_simple_file" );
print Data::Dumper->Dump( [$AoA_ref], ['AoA_ref'] );

sub parse_file {
        my $file = shift or die "Usage: parse_file( <path/to/file> )";
        my @AoA;

        local $/ = "\n\n";	# $INPUT_RECORD_SEPARATOR
        open F, "< $file" or die "Can't open '$file': $!";
        for ( <F> ) { push @AoA, [split /\n/] }
        close F or warn;

        return [@AoA];
}

__END__

+--------------------------------------------------------------------+
|   Joshua Keroes, Sr. Software Engineer,  Electric Lightwave, Inc   | 
+--------------------------------------------------------------------+
  "To be creative, it's not necessary that you're seeing a new thing,
       but that you're looking at the same things in a new way."
       Dieter Gruen, ultrananocrystalline diamond film inventor
TIMTOWTDI



More information about the Pdx-pm-list mailing list