All welcome. Here is the program code:

#!/usr/bin/perl -w print "Скрипт для загрузки программ через Wine\n"; %base = (); dbmopen (%base, "wine", 0744) || die "Ошибка обкрытия DBM файла: $!"; print "Программы, которые можно запустить:\n"; foreach ( @kluch = keys %base) {print $_,"\n"}; print "Введите название программы для ее запуска или клавишу 'Q' для заполнения базы данных\n"; chomp ($komanda = <STDIN>); if ($komanda eq 'Q' || $komanda eq 'q') {while (1) {print "Заполняем базу. Введите название программы: "; chomp ($imja_progr = <STDIN>); print "Программа - $imja_progr.\nТеперь введите адрес до исполняемого файла: "; chomp ($adress = <STDIN>); print "Пpограмма - $imja_progr.\nАдрес - $adress. Если все верно - нажмите клавишку 'Y' в противном случае 'N'\n"; chomp ($proverka = <STDIN>); if ($proverka eq 'Y' || $proverka eq 'y') { %base = ("imja_progr" => "$adress", %base); dbmclose (%base); print "Ввод данных закончен.\n"} elsif ($proverka eq 'N' || $proverka eq 'n') {next}}}; foreach ( @kluch ) {if ($_ eq $komanda) {system ("wine $base{$komanda}") && exit} else { print "Ошибка\n"; next}}; dbmclose (%base); 

The essence of everything is to simplify the launch of Windows programs through Wine on Linux. As planned, at the beginning of the execution of the program, all the keys to the programs go out, the set of which launches the corresponding programs. The problem is that it fails to increase the DBM-array: when you add a new element, the old (infection!) Is deleted !!!!! Please review the code, can anyone see where the error is and what the problem is ... Thanks in advance.

  • And what, the array should increase? And where is it written? In the line% base = ("imja_progr" => "$ adress",% base); The new value for the key imja_progr is entered. The paths for the appearance of other keys in% base are somehow not visible. - alexlz

1 answer 1

Row:

 %base = ("imja_progr" => "$adress", %base); 

replaced by:

 $base{$imja_progr} = $adress; 

UPD: Full Text:

 use strict; use warnings; print "Скрипт для загрузки программ через Wine\n"; dbmopen ( my %base, "wine", 0744) or die "Ошибка обкрытия DBM файла: $!"; print "Программы, которые можно запустить:\n"; printf "%s\n", $_ for keys %base; print "Введите название программы для ее запуска или клавишу 'Q' для заполнения базы данных\n"; chomp ( my $cmd = <STDIN>); if ( $cmd =~ /^q$/i ) { while ( 1 ) { print "Заполняем базу. Введите название программы или <Ввод>, если не хотите больше ничего добавлять: "; chomp ( my $progName = <STDIN> ); last unless $progName; print "Программа - $progName.\nТеперь введите адрес до исполняемого файла: "; chomp ( my $address = <STDIN> ); print "Пpограмма - $progName.\nАдрес - $address. Если все верно - нажмите клавишку 'Y'\n"; chomp ( my $key = <STDIN>); if ( $key =~ /^y$/i) { $base{$progName} = $address; print "Ввод данных закончен.\n"; } } } if ( my $path = $base{$cmd} ) { # system ("wine", $path); printf "wine %s\n", $path; } dbmclose (%base); 
  • Thanks, of course, but the effect is the same: the key and value entered earlier are replaced with a new one and the current element is still in the array ..... - Asid
  • Then (if you wrote the assignment correctly) try not to close% base while running (remove dbmclose after% base =). By the way, the proposed @ Kirill Novgorodtsev operator $base{$imja_progr}=$adress; looks much better than %base = ($imja_progr=>$adress, %base); - alexlz
  • Thanks dear Cyril Novgorodtsevu. Your code is working. - Asid