in reply to [Perl 5.26][Linux LEAP] Array/List/Hash misunderstanding

G'day soundlord,

Here's a few tips for this, and all your other Perl scripts, on your current O/S with your stated Perl version. Change

use strict; use warnings;

to

use 5.026; use warnings; use autodie; use utf8;

use 5.026; gives you all the features of your Perl version and use strict; automatically. There's many you can use here, and in other scripts; one that stands out in your posted code is, instead of adding "\n" to the end of your print statements, you can use say: 'say "XYZ";' is the same as 'print "XYZ\n";'.

use warnings; -- no change; use it always.

The autodie pragma will handle your I/O exceptions for you. '... or die "$targetfile not found :{";' is a poor error message: you're guessing at "not found" but it could be, for instance, a permission problem ($! is typically used to get the reason open() failed). Just code "open my $descripteur, '<:encoding(UTF-8)', $targetfile;" and leave the rest up to autodie.

One of my $work machines is openSUSE Leap 15.2 with Perl v5.26.1 -- I assume the same, or very close, to what you have. I too can get away with using UTF-8 characters (e.g. é) in my source code without "use utf8;"; someone else using your code may not. Play it safe and use the utf8 pragma.

If your first line is

#!/usr/bin/env perl

you can run your script as "./script.pl", instead of "perl script.pl". See perlrun for more about that.

— Ken