V
Vumani Dlamini
I have data which is in this format:
### data ###
area=1101
home=003
mzer=00020
mzec=101
pmpr=00000
pmpc=102
bnsr=00000
bnsc=103
potr=00100
potc=104
swtr=00000
### end ####
and would like to produce the following data
area|home|amount|code
1101,003,00020,101
1101,003,00100,104
In short I would like to drop codes with a zero amount.
I am able to read in the file and produce the data, zero's included
using this code, but am unable to drop the lines corresponding to zero
amounts;
### code ####
my ($area , $home, $amount);
while (<DATA>){
if (/area=(\d+)/) {
$area = $1;
}
elsif (/home=(\d+)/) {
$home = $1;
}
elsif (/(\S+)r=(\d+)/) {
$home = $2;
}
elsif (/(\S+)c=(\d+)/) {
print <OUTFILE> "$area,$home,$amount,$2\"
}
}
I would also like to have my PERL programs in another directory rather
than in the one where the <DATA> file is. I also need help on how I
can change directory within the PERL program.
Thanks a lot.
Vumani
### data ###
area=1101
home=003
mzer=00020
mzec=101
pmpr=00000
pmpc=102
bnsr=00000
bnsc=103
potr=00100
potc=104
swtr=00000
### end ####
and would like to produce the following data
area|home|amount|code
1101,003,00020,101
1101,003,00100,104
In short I would like to drop codes with a zero amount.
I am able to read in the file and produce the data, zero's included
using this code, but am unable to drop the lines corresponding to zero
amounts;
### code ####
my ($area , $home, $amount);
while (<DATA>){
if (/area=(\d+)/) {
$area = $1;
}
elsif (/home=(\d+)/) {
$home = $1;
}
elsif (/(\S+)r=(\d+)/) {
$home = $2;
}
elsif (/(\S+)c=(\d+)/) {
print <OUTFILE> "$area,$home,$amount,$2\"
}
}
I would also like to have my PERL programs in another directory rather
than in the one where the <DATA> file is. I also need help on how I
can change directory within the PERL program.
Thanks a lot.
Vumani