Thread CGI: tailor an existing programme (2 answers)
Opened by Crian at 2005-04-04 18:41

renee
 2005-04-04 20:15
#5470 #5470
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
You can open a Filehandle before you do your database queries. So you have only one textfile for all three tapes.

Within your loop, you have to print your results to the filehandle without opening a new filehandle!

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
open(OUT,">/path/to/file.txt") or die $!;
for(my $i=$tape;$i<=$tape1;$i++){

# issue query
$sth = $dbh->prepare("SELECT the_number,',',client_company_name,',',name,',',_Title,',',_Version,',',_PGM_Duration,',',_Tape_Format FROM tapes_2 WHERE the_number='$pref$i'");

$sth->execute ();

my $output = $sth->fetchall_arrayref;
my @output = @$output;

if($output[0]){
print OUT <<"end_txt";
end_txt

foreach my $row (@output){
print OUT $row->[0];
print OUT $row->[1];
print OUT $row->[2];
print OUT $row->[3];
print OUT $row->[4];
print OUT $row->[5];
print OUT $row->[6];
print OUT $row->[7];
print OUT $row->[8];
print OUT $row->[9];
print OUT $row->[10];
print OUT $row->[11];
print OUT $row->[12];
}

chmod(0777,$file);
# save tape number for later displaying
push(@work_done, "$pref$i");

}

}

close(OUT);


You should also read the documentation of CPAN:DBI... Use the ?-notation for your queries. This will avoid a lot of errors...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread CGI: tailor an existing programme