in reply to Array problem......PLEASE HELP!

Why must you use the array @files? This strikes me as a rather pointless constraint. What are you trying to do?

Dealing with your attempt to read the files in your directory: as said by moritz, use glob. It's what it's made for. Your first step would look something like this:

my $files = join(" ", (glob("0[89]-*.txt")));#I suffer from parentheti +caphilia. sorry
@files will now contain a blank-separated list of files which start with 08 or 09, followed by a hyphen and ending with '.txt'. You could then pass this to your ls -l command (the one in the backticks) and do the post-processing from your hash.pl routine.

Alternatively, you could use opendir, readdir, and grep, resulting in something like this:

opendir(my $DH, "."); # opens pwd @files = grep {/^0[89]-.+\.txt$} readdir($DH); closedir($DH);

But it would be a really good idea to tell the Monks–many of whom actually like explaining the nuances of Perl if the question is couched appropriately–what your goal is.


Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

Replies are listed 'Best First'.
Re^2: Array problem......PLEASE HELP!
by green_lakers (Novice) on Jan 05, 2009 at 22:15 UTC
    Hi there, I dont want to join 08 and 09 files together. At the first loop i need the 08 files where i will process only files and gererate a report. At the second loop i require the 09 files and output a report.
      Try this:
      #!/usr/bin/perl use warnings; use strict; use Data::Dumper; opendir(DIR, '.'); my @files = grep !/^\.{1,2}$/, readdir DIR; my @files8 = grep /08/, @files; my @files9 = grep /09/, @files; closedir DIR; print "@files\n"; my %commands; #maybe use a hash print "08 files\n"; foreach my $file (@files8){ $commands{'08'}{$file} = `ls -l|grep $file` } print "09 files\n"; foreach my $file (@files9){ $commands{'09'}{$file} = `ls -l|grep $file` } print Dumper([\%commands]);

      I'm not really a human, but I play one on earth Remember How Lucky You Are