NiteOwl
09-04-2006, 11:10 PM
I need a way to maintain this nightmare.
I have a dozen scripts that have this code and whenever i add a new data field, say after $vt, i have to search a dozen scripts and change them all.
I need a way to make my record desc global and use the indivual fields as needed.
The data is stored in different txt files that use "|" as a delimitor.
All txt files have the same record structure.
$filename = "somefile.txt";
$idnum = param(listnum);
&readdata;
&processdata;
sub readdata {
open(INF,"$filename") or &dienice("Can't open $filename: $! \n");
flock(INF, LOCK_SH); # shared lock
seek(INF, 0, SEEK_SET); # rewind to beginning
my(@data) = <INF>;
close(INF);
@listingdata=@data;
}
sub processdata {
my @data = sort(@listingdata);
foreach my $i (@data) {
chomp($i);
my $city,$state,$price,$bed,$bath,$sqfeet,$title,$desc,$caption,$list,
$type,$status,$zip,$acre,$agent,$vt) = split(/\|/,$i);
if ($idnum eq $list) {
#Do Various prints and compares
print "Desc: $desc";
if ($status < 2) {
# do this
}
# End $list compare
}
# End Processdata
}
Thanks for looking..
:eek:
I have a dozen scripts that have this code and whenever i add a new data field, say after $vt, i have to search a dozen scripts and change them all.
I need a way to make my record desc global and use the indivual fields as needed.
The data is stored in different txt files that use "|" as a delimitor.
All txt files have the same record structure.
$filename = "somefile.txt";
$idnum = param(listnum);
&readdata;
&processdata;
sub readdata {
open(INF,"$filename") or &dienice("Can't open $filename: $! \n");
flock(INF, LOCK_SH); # shared lock
seek(INF, 0, SEEK_SET); # rewind to beginning
my(@data) = <INF>;
close(INF);
@listingdata=@data;
}
sub processdata {
my @data = sort(@listingdata);
foreach my $i (@data) {
chomp($i);
my $city,$state,$price,$bed,$bath,$sqfeet,$title,$desc,$caption,$list,
$type,$status,$zip,$acre,$agent,$vt) = split(/\|/,$i);
if ($idnum eq $list) {
#Do Various prints and compares
print "Desc: $desc";
if ($status < 2) {
# do this
}
# End $list compare
}
# End Processdata
}
Thanks for looking..
:eek: