JackTheRussel
Programmer
Hi.
I have a program which gets information into database and then the program writes it into a file.
In the beginning the program checks $option1 and $option2 values.
If $option1 == 0 then database query results could for example be something like this:
Def: 2
Aut: 2
Min: 3
Vid: 1
And if the $option1 == 1 then results could be something like this:
Def: 0
Aut: 0
Min: 4 // Def + Aut
Vid: 4 // Min + Vid
And $option2 works like $option1 but "titles" are different.
Yit:
Opt:
Hre:
Tre:
So I run two sql-querys:
$sqlQuery1 and $sql-query2
And I get results into tables:
@SqlQueryResults
@SqlQueryResults2
In this point I need some help. Now when I write query results into file I use Tie:File.
It's working, but It is really messy. I would like to do this a little bit smarter:
I know this is messy question, but ask more if you did't get it.
Thanks.
I have a program which gets information into database and then the program writes it into a file.
In the beginning the program checks $option1 and $option2 values.
If $option1 == 0 then database query results could for example be something like this:
Def: 2
Aut: 2
Min: 3
Vid: 1
And if the $option1 == 1 then results could be something like this:
Def: 0
Aut: 0
Min: 4 // Def + Aut
Vid: 4 // Min + Vid
And $option2 works like $option1 but "titles" are different.
Yit:
Opt:
Hre:
Tre:
So I run two sql-querys:
$sqlQuery1 and $sql-query2
And I get results into tables:
@SqlQueryResults
@SqlQueryResults2
In this point I need some help. Now when I write query results into file I use Tie:File.
It's working, but It is really messy. I would like to do this a little bit smarter:
Code:
tie @array, 'Tie::File', $file or die;
if ($option1 == 0){
$array[0] = "Def: $SqlQueryResults[0];
$array[1] = "Aut: $SqlQueryResults[1];
$array[2] = "Min: $SqlQueryResults[2];
$array[3] = "Vid: $SqlQueryResults[3];
}
elsif ($option1 == 1){
$array[0] = "Def: 0;
$array[1] = "Aut: 0;
$array[2] = "Min: $SqlQueryResults[0];
$array[3] = "Vid: $SqlQueryResults[1];
}
else { print "Something is wrong\n"; }
if ($option2 == 0){
$array[4] = "Yit: $SqlQueryResults2[0];
$array[5] = "Opt: $SqlQueryResults2[1];
$array[6] = "Hre: $SqlQueryResults2[2];
$array[7] = "Tre: $SqlQueryResults2[3];
}
elsif ($option2 == 1){
$array[4] = "Yit: 0;
$array[5] = "Opt: $SqlQueryResults2[0];
$array[6] = "Hre: 0;
$array[7] = "Tre: $SqlQueryResults2[1];
}
else { print "something is wrong\n"; }
I know this is messy question, but ask more if you did't get it.
Thanks.