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


In reply to Re: [Perl 5.26][Linux LEAP] Array/List/Hash misunderstanding by kcott
in thread [Perl 5.26][Linux LEAP] Array/List/Hash misunderstanding by soundlord

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.