SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env perl
  2.  
  3. use warnings;
  4. use strict;
  5. use Data::Dumper;
  6. use DBI;
  7.  
  8. my $config = eval(join '' => <DATA>);
  9.  
  10. get_values($config);
  11.  
  12. sub get_values {
  13.   my $config   = shift;
  14.  
  15.   my $dname    = $config->{db_name};
  16.   my $dhost    = $config->{db_host};
  17.  
  18.   my $user     = $config->{db_user};
  19.   my $password = $config->{db_pass};
  20.  
  21.   my $dbh = DBI->connect("dbi:mysql:database=$dname;host=$dhost", $user, $password)  || die "Can't connect to mysql database!";
  22.  
  23.   # тут хирые выборки
  24.   # .....
  25.   #
  26.  
  27.   # возвращай указатель на нужную тебе структуру, или печатай прямом тут
  28.   return \@array
  29.   return \%hash
  30. }
  31.  
  32. __DATA__
  33. # этот файл можно будет сериализовать к примеру в JSON и хранить отдельно от скрипта
  34. {
  35.   db_name => 'DCVBase',
  36.   db_host => `host master.cluster.dcv asu-main.dcv | grep "has address" | cut -d " " -f 4`,
  37.  
  38.   db_user => 'username',
  39.   db_pass => 'password',
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top