fritz@laptop:~/Documents$ ./4.getopt.pl --infile /home/fritz/Desktop/1.tran.txt --outfile /home/fritz/Desktop/1.enc_trans.txt --lang EL --verbose 1 /home/fritz/Desktop/1.tran.txt, /home/fritz/Desktop/1.enc_trans.txt, EL, 1 ... ./4.getopt.pl : sending above payload, of 574 bytes... ... ./4.getopt.pl : text=Scylla and Charybdis are the horns of a dilemma.&target_lang=EL ./4.getopt.pl : sending above payload, of 68 bytes..../4.getopt.pl : done, success. fritz@laptop:~/Documents$ #### #!/usr/bin/env perl use v5.030; # strictness implied use warnings; use utf8; use Getopt::Long; #use Net::API::DeepL qw/http_tiny/; # maybe someday... my ( $infile, $outfile, $lang, $verbose ); $verbose = 0; if ( !Getopt::Long::GetOptions( 'infile=s' => \$infile, 'outfile=s' => \$outfile, 'lang=s' => \$lang, 'verbose=i' => \$verbose, 'help' => sub { print STDERR "Usage : $0 --infile xx --outfile xx --lang xx [--verbose N]\n"; exit(0); }, ) ) { die "error, something wrong with the command-line parameters."; } die "parameters needed!" unless $infile and $outfile and $lang; say "$infile, $outfile, $lang, $verbose"; # at this point consider adding all your parameters into a hash and # pass that to http_tiny($options) instead of passing a long list which # may contain optional parameters. my %h; $h{infile} = $infile; $h{outfile} = $outfile; $h{lang} = $lang; $h{verbose} = $verbose; my $results = http_tiny( \%h ); die unless $results; print "$0 : done, success.\n"; sub http_tiny { my ($hr) = (shift); use Path::Tiny; use HTTP::Tiny; use JSON::MaybeXS; my %h = %$hr; my $file_in = path( $h{infile} ); my $file_out = path( $h{outfile} ); my $lang = $h{lang}; my $debug = $h{verbose}; # slurp file my $guts = $file_in->slurp_utf8; my @spl = split( '\n', $guts ); # get credentials my ( $url, $key ) = get_тайный(); #say "$url, $key"; my $ua = HTTP::Tiny->new( 'verify_SSL' => '1' ); for my $para (@spl) { say $para; my $payload = "text=$para&target_lang=$lang"; my $payloadlen = length($payload); my $response = $ua->request( 'POST' => $url, { headers => { 'Authorization' => "DeepL-Auth-Key $key", 'Content-Length' => $payloadlen, 'Accept' => '*/*', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'curl/7.55.1' }, content => $payload, }, ); die "Failed!\n" unless $response->{success}; if ( $debug > 0 ) { print "$0 : $payload\n$0 : sending above payload, of $payloadlen bytes..."; } #print $response->{content} if length $response->{content}; my $content = $response->{content}; #say "content is $content"; my $data = decode_json($content); #say "data is $data"; my $text1 = $data->{'translations'}->[0]->{'text'}; my $outstring = $para. "\n".$text1."\n"; $file_out->append_utf8( $outstring); } return $hr; } sub get_тайный { use Config::Tiny; my $ini_path = qw( 1.тайный.txt ); my $sub_hash = "deepl"; my $Config = Config::Tiny->new; $Config = Config::Tiny->read( $ini_path, 'utf8' ); # -> is optional between brackets my $url = $Config->{$sub_hash}{'url'}; my $key = $Config->{$sub_hash}{'key'}; return ( $url, $key ); } __END__