File: japh

package info (click to toggle)
libdbd-oracle-perl 1.83-3
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 1,724 kB
  • sloc: ansic: 8,354; perl: 7,868; makefile: 20
file content (52 lines) | stat: -rwxr-xr-x 1,264 bytes parent folder | download | duplicates (8)
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
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl -w
# This is an example of how we could code a JAPH using DBI and DBD::Oracle.
#
# Original oraperl script by Kevin Stock
# Date:     1st December 1992

use DBI;

use strict;

# Set trace level if '-# trace_level' option is given
DBI->trace( shift ) if 1 < @ARGV && $ARGV[0] =~ /^-#/ && shift;

die "syntax: $0 [-# trace] base user pass" if 3 > @ARGV;
my ( $inst, $user, $pass ) = @ARGV;

# Connect to database
my $dbh = DBI->connect( "dbi:Oracle:$inst", $user, $pass,
    { AutoCommit => 0, RaiseError => 1, PrintError => 0 } )
    or die $DBI::errstr;

# Create the sample table
$dbh->do( "CREATE TABLE japh ( word CHAR(7), posn NUMBER(1) )" );

# Loop to insert data into the table
my $sth = $dbh->prepare( "INSERT INTO japh VALUES ( ?, ? )" );
while ( <DATA> ) {
    chomp;
    $sth->execute( split ':',  $_ );
}

# Now retrieve the data, printing it word by word
$sth = $dbh->prepare( "SELECT word FROM japh ORDER BY posn" );
$sth->execute;
my $word;
$sth->bind_columns( {}, \$word );
$sth->{ChopBlanks} = 1; # Wouldn't you rather use VARCHAR2 instead of CHAR?
while ( $sth->fetch ) {
    print " $word";
}
$sth->finish;
print "\n";

# delete the table
$dbh->do( 'DROP TABLE japh' );
$dbh->disconnect;

__END__
DBI:3
another:2
hacker:4
just:1