New to PERL, hopefully this is simple.
If I have a text file with lots of lines of data broken up into say 25 columns or fields. The fields are seperated by spaces and are fixed length across the file but some of the fields are blank(spaces).
I need to write a PERL script that creates a report on ONLY specific fields (ex. fields 1,2,5, 7,17, 19,22). How best can I define the fields to scalars in order to print them ?
Example Input file:
Server Location BkUp Date time mbytes files
serv1 Atl yes 01/22/05 10:01 569333 5621
serv2 Chi no 23:00 3218 112
serv3 LA yes 01/22/05 34233 1231
Ideally I would like to identify each field as I read it. I used SPLIT to break the fields up after I opened up the file but then recognized the blank fields and had to come up with another solution. And being a newby, I am not sure what that might be. Here is the SPLIT code:
while($line = <INPUTFILE>){
@fields = split(' ',$line);
$field_serv = $fields [0];
$field_loc = $fields [1];
$field_bkup = $fields [2];
$field_date = $fields [3];
How do I break the fields up and assign them to variables as each line is read ? What is the best way of doing this as SPLIT doesnt appear to provide a solution because of the occasional blank fields.
Any feedback would be great. Thanks.
If I have a text file with lots of lines of data broken up into say 25 columns or fields. The fields are seperated by spaces and are fixed length across the file but some of the fields are blank(spaces).
I need to write a PERL script that creates a report on ONLY specific fields (ex. fields 1,2,5, 7,17, 19,22). How best can I define the fields to scalars in order to print them ?
Example Input file:
Server Location BkUp Date time mbytes files
serv1 Atl yes 01/22/05 10:01 569333 5621
serv2 Chi no 23:00 3218 112
serv3 LA yes 01/22/05 34233 1231
Ideally I would like to identify each field as I read it. I used SPLIT to break the fields up after I opened up the file but then recognized the blank fields and had to come up with another solution. And being a newby, I am not sure what that might be. Here is the SPLIT code:
while($line = <INPUTFILE>){
@fields = split(' ',$line);
$field_serv = $fields [0];
$field_loc = $fields [1];
$field_bkup = $fields [2];
$field_date = $fields [3];
How do I break the fields up and assign them to variables as each line is read ? What is the best way of doing this as SPLIT doesnt appear to provide a solution because of the occasional blank fields.
Any feedback would be great. Thanks.