Papapep wrote:
> I've made a small program that tries to get all the files from a
> directory that's full of files that they have the name format :
> pepe-1_DDMMYYYY.txt or pepe-2_DDMMYYYY.txt.
> First, I am just trying to get them and print the array created.
> Afterwards, when this works I'll do more things with the data in them
> included, but for now I can't get though with the first objective :-/
> When I execute the program it makes NOTHING!!! At least, that's what
> it seems...
> I know its not a very good code, but it's my first one! :-D

We've all written naff code. Sometimes quite often! Welcome
to Perl.

> Can anybody give some advice about where's the bug?
> Thanks in advance.
>
> > #!perl
> > use strict;
> > use warnings;
> > my $program;
> > my @filenames;
> > opendir (FITXER,"c:/documents and
> > settings/administrador/escritorio/pepes") or
>  > die "no es pot llegir el directori: $!\n";

Leave Perl to put its own \n on the end of the die string. Then
it will also add the source line number being executed when
it dies.

> > @noms = readdir (FITXER) or die "no es poden agafar els noms dels fitxers \n"; 
> > foreach $program (@noms)

You haven't declared @noms. This will fail in compilation with 'use strict' in effect.

> >     {
> >     if ($program =~ m/^pepe-1_(\d[8])\.txt$/)

You need braces around the '8', not square brackets. Also you can search
for both the pepe-1 and pep-2 files with

    if ($program =~ m/^pepe-[12]_(\d{8})\.txt$/)

> >         {
> >         ### do stuff, given a filename
> >   print "$program \n";

This will work, rpviding you have fixed the other errors.

> >         }
> >     elsif( $program =~ m/^pepe-2_(\d[8])\.txt$/)

braces again!

> >         {
> >         ### do stuff, given a filename
> >         print $program <stdout>;

This will try to read from the <stdout> filehandle and try to
print each line to the filehandle specified by $program. Note
that <stdout> is case=sensitive, and isn't the same as <STDOUT>,
but either way it's not open for input and the read will fail.

What you probably mean is

    print STDOUT $program;

but STDOUT is selected by default anyway, so you may as well
just use

    print "$program\n";

as you did before.


I hope this helps. Come back if you need anything more.

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to