Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Problem in perl/tk

by choroba (Cardinal)
on Nov 28, 2015 at 20:03 UTC ( [id://1148777]=note: print w/replies, xml ) Need Help??


in reply to Problem in perl/tk

Hi Ammar, welcome to the Monastery. What exactly is your question? Your code is very long, but we can't run it directly, as we don't have the database. To get valuable answers, try to ask concrete questions about details you can't make work.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Problem in perl/tk
by Anonymous Monk on Nov 29, 2015 at 07:22 UTC

    I have six keys in my hash.I want that using tk interface when user enters the values of region,country and province then the value of our sixth key is extracted from these three values (i.e Sequence id is APAPU0000001 if user enters Asia and country Pakistan and Punjab and 1 is added at the end of seven digit identifier).code is given below.
    use strict; use DBI; use Tk; my $conn = DBI->connect ("DBI:mysql:pcr_experiment","root","password15") or die("Cannot connect: $DBI::errstr"); my ($sql, @keys, $record); my %fields = ('ID' => "ID: " , 'province'=> "Province: ",'country'=> "Country +: " 'region'=> "Region: " , 'sequence_id'=>"Sequence ID: ", 'sequence_file'=>"Sequence file: " ); my @order =qw(ID province country region sequence_id sequence_file ); Start_Tk_Interface(); exit; #----------------------------------------------------- # Database Routines sub Get_Record { my $ID = shift; my $sql = qq(SELECT * FROM university WHERE ID = $ID); my $hdl_search = $conn->prepare($sql); $hdl_search->execute; $record = $hdl_search->fetchrow_hashref; return($record); } sub Delete_Record { my $ID = shift; $sql = qq(DELETE FROM UNIVERSITY WHERE ID = '$ID'); my $query = $conn->prepare($sql); $query->execute or die("\nError executing SQL statement! $DBI::errstr"); return 1; } sub Update_Record { my $form = shift; my $caller = shift; $caller -> withdraw(); my $ID = $form->{'ID'}->get(); my @keys = keys %$form; my @vals = map { $$form{$_}->get() } @keys; my $counter = 0; $sql = qq{SELECT FROM UNVIVERSY }; foreach my $k (@keys){ $sql .= qq{$k = "$vals[$counter]", }; $counter++; } $sql =~ s/\, $//; $sql .= " WHERE ID = '$ID'"; my $query = $conn->prepare($sql); $query->execute or die("\nError executing SQL statement! $DBI::errstr"); return 1; } sub Add_Record { my $form = shift; my $caller = shift; $caller -> withdraw(); my @keys = keys %$form; my @vals = map { $conn->quote($$form{$_}->get()) } @keys; $sql = "INSERT INTO UNIVERSITY (" . join(", ", @keys) . ") VALUES (" . join(", ", @vals) . ")"; my $query = $conn->prepare($sql); $query->execute or die("\nError executing SQL statement! $DBI::errstr"); return 1; } #------------------------------------------------------ # Tk Interface Routines my $MainWin; sub Start_Tk_Interface { $MainWin = MainWindow->new(-title => "Choose a Database Action"); $MainWin->MoveToplevelWindow(100,100); my $button1 = $MainWin->Button(-text => 'Add Record', -command => [\&tk_Add_Record_Dialog, 'add']); my $button2 = $MainWin->Button(-text => 'View Record', -command => [\&tk_Choose_Dialog, 'View']); my $button3 = $MainWin->Button(-text => 'Delete Record', -command => [\&tk_Choose_Dialog, 'Delete']); my $button4 = $MainWin->Button(-text => 'Quit', -command => [$MainWin => 'destroy']); $button1 -> grid(-row => 0, -column => 0, -padx => 10, -sticky => 'w'); $button2 -> grid(-row => 0, -column => 1, -padx => 10, -pady => 40 ); $button3 -> grid(-row => 0, -column => 2, -padx => 10); $button4 -> grid(-row => 0, -column => 3, -padx => 10, -sticky => 'e'); MainLoop(); } sub tk_Choose_Dialog { my $type = shift; my $top_win = $MainWin->Toplevel(-title => "Choose Record"); $top_win->MoveToplevelWindow(110,110); $top_win->Label(-text => 'ID: ') -> grid(-row => 0, -column => 0, -sticky => 'w'); my $ID= $top_win->Entry(-width => 20) -> grid(-row => 0, -column => 1, -sticky => 'e'); my $button = $top_win->Button( -text => "$type Record", -command => [\&tk_Edit_or_Delete, $top_win, $type, $ID] ); $button-> grid(-row => 1, -column => 1); return 1; } sub tk_Edit_or_Delete { my $caller = shift; my $type = shift; my $ID = shift()->get(); $caller->withdraw(); Delete_Record($ID) if($type eq 'Delete'); tk_Add_Record_Dialog("edit", $ID) if($type eq 'View'); return 1; } sub tk_Add_Record_Dialog { my ($record, $ID, %form); my $type = shift; my $row = 0; my $top_win = $MainWin->Toplevel(-title => "Add/View a Record"); $top_win->MoveToplevelWindow(110,110); if($type =~ /edit/){ $ID = shift; $record = Get_Record($ID); } foreach my $field (@order){ my $text = $record->{$field}; $top_win->Label(-text => $fields{$field}) -> grid(-row => $row, -column => 0, -sticky => 'w'); $form{$field} = $top_win->Entry (-width => 50, -textvariable => \$text) -> grid(-row=> $row, -column=> 1, -sticky=> 'e'); $row++; } my $button; if($type =~ /edit/i){ $button = $top_win->Button( -text => 'Quit', #Third button in edit statement -command => [\&Update_Record,\%form, $top_win] ); } else { $button = $top_win->Button( -text => 'Add Record', -command => sub{ Add_Record(\%form, $top_win)} ); } $button-> grid(-row => $row, -column => 1); return 1; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1148777]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-25 14:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found