Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^7: De-googleizing translation scripts

by bliako (Monsignor)
on Nov 29, 2022 at 10:13 UTC ( [id://11148432]=note: print w/replies, xml ) Need Help??


in reply to Re^6: De-googleizing translation scripts
in thread De-googleizing translation scripts

good start!

# at this point consider adding all your parameters into a hash and # pass that to http_tiny($options) instead of passing a long list whic +h # may contain optional parameters. my %h; $h{infile} = $infile; ...

Note that you can pack all into a hash from the beginning avoiding myriads of loose variables:

my %h; # or %params ... Getopt::Long::GetOptions( 'infile=s' => \$h{infile}, # or more flexible: 'outfile=s' => sub { $h{$_[0]} = $_[1] }, # the anonymous sub above will be called with 2 params # when --outfile is detected: the key (outfile) and its value ... }

Also, the sub get_... (secrets) is a good example where error checking is important. The sub itself does not check whether it found the secrets pair in the config file or whether it managed to open the file. It returns a pair of possibly undefined values (if it does not bomb midway because of IO errors). And you do not check its return value: it will be a pair but will it have defined values? Personally I prefer to pass into subs hash/array refs and return back hash/array refs. In this way if it returns undef then I know an error occured.

sub get_... { if( /error/ ){ print STDERR "errors"; return undef } return [$url, $key]; } # use it my $ret = get_...(); if( ! defined $ret ){ print STDERR "call to get_...() has failed"; exi +t(1) } my ($url, $key) = @$ret;

Apropos the translation, it is impressively good. The *$&?^%$^* will sell the rope with which to be "hanged" but with the current logistics standstill, keep spinning those yarns on the ol'spindle, with Perl, hehehe

bw, bliako

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-26 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found