V
Vumani Dlamini
I would like to extract properties of companies from a huge text data
set. The data is structured as follows;
##### data #########
Area=3706
Company=101
PROPdes1=1 # description/type of property
PROPpri1=2 # public/private
PROPemp1=54 # number of employees
PROPdes2=6
PROPpri2=2
PROPemp2=23
###################
I would like to create data like,
3706|101|1|1|2|54
3706|101|2|6|2|23
where column 3 corresponds to the property tag, attached to each
variable corresponding to a particular property.
There are a lot more properties per company in my data set and thus I
opted to loop over that tag; but my code gives errors where those tags
are. Am not sure what I am missing.
##### Perl script ######
use strict;
open DATA, "c:/../properties.txt" or die "Unable to open file:$\n";
my ($Area , $Comp, $i, $Pdes, $Ppri, $Pemp);
open PRIVATE, ">c:/.../private.txt";
while (<DATA>){
if (/Area=(\d+)/) {
$Area = $1;
}
elsif (/Company=(\d+)/) {
$Comp = $1;
}
# Loop over properties by the same company (not more than 5 in
this data set)
for ($i = 1; $i<= 5;$i++){
# Each of the variable has a postfix for the property
number
elsif (/PROPdes($i)=(\d+)/) { # ERROR OCCURS
$Pdes = $1;
}
elsif (/PROPpri($i)=(\d+)/) { # ERROR OCCURS
$Ppri = $1;
}
elsif (/PROPemp(\d+)c=(\d+)/) {
print PRIVATE "$Area$Comp$i$Pdes$Ppri$1\n";
}
}
}
##### Perl script ######
Thanks, Vumani
set. The data is structured as follows;
##### data #########
Area=3706
Company=101
PROPdes1=1 # description/type of property
PROPpri1=2 # public/private
PROPemp1=54 # number of employees
PROPdes2=6
PROPpri2=2
PROPemp2=23
###################
I would like to create data like,
3706|101|1|1|2|54
3706|101|2|6|2|23
where column 3 corresponds to the property tag, attached to each
variable corresponding to a particular property.
There are a lot more properties per company in my data set and thus I
opted to loop over that tag; but my code gives errors where those tags
are. Am not sure what I am missing.
##### Perl script ######
use strict;
open DATA, "c:/../properties.txt" or die "Unable to open file:$\n";
my ($Area , $Comp, $i, $Pdes, $Ppri, $Pemp);
open PRIVATE, ">c:/.../private.txt";
while (<DATA>){
if (/Area=(\d+)/) {
$Area = $1;
}
elsif (/Company=(\d+)/) {
$Comp = $1;
}
# Loop over properties by the same company (not more than 5 in
this data set)
for ($i = 1; $i<= 5;$i++){
# Each of the variable has a postfix for the property
number
elsif (/PROPdes($i)=(\d+)/) { # ERROR OCCURS
$Pdes = $1;
}
elsif (/PROPpri($i)=(\d+)/) { # ERROR OCCURS
$Ppri = $1;
}
elsif (/PROPemp(\d+)c=(\d+)/) {
print PRIVATE "$Area$Comp$i$Pdes$Ppri$1\n";
}
}
}
##### Perl script ######
Thanks, Vumani