in reply to Pick Up Files and put contents into variables
I have no idea how to do this, so help would be much appreciated.
:) The idea is to opendir, readdir,open,<>,split, close, closedir using some loops and usefull data strucures.
As data structure is propose a hash withe filenames as keys and arrayrefs as value.
--#!/usr/bin/perl use strict; use warnings; my %files; my $dir = shift || '.'; opendir DIR,$dir or die "error opeing directory $dir: $!"; while( defined( my $file = readdir DIR ) ){ my $path = "$dir/$file"; next unless -f $path; open my $fh , '<' , $path or do { warn "$file : $! skipping\n"; next }; $files{$file} = []; while(<$fh>){ push @{$files{$file}} , [ split ] } close $fh; } closedir DIR;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Pick Up Files and put contents into variables
by Anonymous Monk on Aug 30, 2002 at 11:27 UTC | |
by fruiture (Curate) on Aug 30, 2002 at 12:42 UTC |