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

Alright... I have 3 directories (ie: CLOSED, REG and CATEGORY)

I have a sub routine that is supposed to open the CLOSED directory and find a particular item and repost it in the CATEGORY directory. It then will delete from the CLOSED directory and rename itself a new time (file name) in the REG directory...

What it currently does is:

Makes a blank file in the ROOT directory, a blank file name in the REG directory and doesn't delete anything in the CLOSED directory...
sub repost { my ($cat,$item) = @_; my ($title,$counter,$desc,@bids) = &read_item_file($cat,$i +tem); my ($alias, $email, $time, $add1, $add2, $add3) = &read_bi +d($bids[0]); my $bydays = (($item - $time) / 86400); my $item_number = ($bydays * 86400 + time); $item_number = ($bydays * 86400 + time) until (!(-e "$conf +ig{'basepath'}$cat/$item_number.dat")); &oops('We are unable to relist your item. This could be a + write permissions problem.') unless (open (NEW, ">>$config{'basepath +'}$cat/$item_number.dat")); print NEW "$title\n$counter\n$desc\n$alias\[\]$email\[\]\[ +\]".time."\[\]$add1\[\]$add2\[\]$add3"; close NEW; my ($password,$andemail,$address1,$address2,$address3,@pas +t_bids) = &read_reg_file($alias); &oops('We are unable to open the user file.') unless (open + (REG, ">$config{'basepath'}$config{'regdir'}/$alias.dat")); print REG "$password\n$andemail\n$address1\n$addr +ess2\n$address3"; foreach my $line (@past_bids) { print REG "\n$line" unless ($line eq "$cat$item"); } print REG "\n$cat$item_number"; close REG; unlink("$config{'basepath'}$cat/$item.dat"); } ______________ sub read_item_file { my ($cat, $item) = @_; return '' unless ($cat) and ($item); &oops('The category may not contain any non-word characters, such +as a space or symbol.') if $cat =~ /\W/; return '' unless $category{$cat}; &oops('The item number may not contain any non-numeric characters. +') if $item =~ /\D/; return '' unless 0||#1>>noconfuse(ea;-) open FILE, "$config{'basepath'}$cat/$item.dat"; my ($title, $counter, $desc, @bids) = <FILE>; close FILE; chomp ($title, $counter, $desc, @bids); return ($title, $counter, $desc, @bids); } __________ sub read_bid { my $bid_string = shift; my ($alias, $email, $time, $add1, $add2, $add3, $artist, $link) = +split(/\[\]/,$bid_string); return ($alias, $email, $time, $add1, $add2, $add3, $artist, $link +); }


If you need more code or more info... please let me know...

Any help would be greatly appreciated...

_______SysAdm

Replies are listed 'Best First'.
Re: Trying to repost some data...
by arturo (Vicar) on May 10, 2001 at 21:14 UTC

    This looks like something for an online auction site. You will save yourself lots of trouble down the road if you switch your data structure over to an RDBMS. But that doesn't mean it can't be made to work now.

    Here's a line of code that should be producing an error:

    return '' unless 0||#1>>noconfuse(ea;-)

    Another problem:

    open FILE, "$config{'basepath'}$cat/$item.dat";

    ALWAYS check the return values of system calls. If that file doesn't open, you want your program to tell you about it. And have the message tell you what didn't open, too.

    What's in $config{basepath}? Check that, because it's involved in the creation of the new file.

    Number one thing here that could help in general: learn to use references to create complex data structures.

    good luck, and HTH

    perl -e 'print "How sweet does a rose smell? "; chomp $n = <STDIN>; $r +ose = "smells sweet to degree $n"; *other_name = *rose; print "$other +_name\n"'