lief has asked for the wisdom of the Perl Monks concerning the following question:

i have an auction script that stores its individual datafiles in a few directories in a larger directory inside of the cgi-bin folder

file > file type folder > auction data > cgi-bin

i am now trying to create a perl script to use as a ssi include file on my non-perl index page, to tell how many items are currently for auction. i have created the following script, yet something is malfunctioning, and i cannot put my finger on the problem... please just take a look and see if you can find the problem.
#!/usr/bin/perl use vars qw(%config %category); use strict; $config{'basepath'} = '/data/web/65682/auctiondata/'; %category = ( snow => 'snow', skate => 'skate', surf => 'surf', misc => 'misc', ); sub getnumber { my $key; foreach $key (sort keys %category) { umask(000); # UNIX file permission junk mkdir("$config{'basepath'}$key", 0777) unless (-d "$config{' +basepath'}$key"); opendir DIR, "$config{'basepath'}$key" or &oops("category di +rectory $key could not be opened"); my $numfiles = scalar(grep -T, map "$config{'basepath'}$key/ +$_", readdir DIR); my $totalfiles =+ $numfiles; closedir DIR; } print $totalfiles; }


lief

Edit Masem 2001-10-02 - Code tags and html-special-char edits

  • Comment on unix file permissions? or perhaps something that will make me look silly...
  • Download Code

Replies are listed 'Best First'.
Re: unix file permissions? or perhaps something that will make me look silly...
by VSarkiss (Monsignor) on Oct 02, 2001 at 20:48 UTC

    If this is an accurate copy-and-paste, you're replacing rather than adding to $totalfiles: my $totalfiles =+ $numfiles; Should be:    $totalfiles += $numfiles; Also, don't my it in the loop, do it beforehand.

    HTH

Re: unix file permissions? or perhaps something that will make me look silly...
by suaveant (Parson) on Oct 02, 2001 at 20:47 UTC
    I am not sure... but your map is extremely extraneous, I'm not sure if it is the problem, but try to change your grep line to...
    my $numfiles = grep { -T "$config{'basepath'}$key/$_" } readdir DIR;
    you also do not need the explicit scalar call

    Update oh yes.. I missed the =+.... VSarkiss++

                    - Ant
                    - Some of my best work - Fish Dinner

Re: unix file permissions? or perhaps something that will make me look silly...
by Fletch (Bishop) on Oct 02, 2001 at 22:17 UTC

    You might want to consider checking the return from mkdir():

    unless( -d "$config{basepath}/$key" ) { mkdir( "$config{basepath}$key", 0777 ) or oops( "can't make category directory $key: " . $! ); }