in reply to create clone script for utf8 encoding
G'day Aldebaran,
"All of my scripts have a taxonomy of a positive integer followed by a period, followed by a word."
I'd probably aim for something like this in Perl:
$ perl -E 'my $x = "2.X"; my ($y, $z) = ($x =~ /^(\d+)(.*)$/); say $x; + say ++$y . $z' 2.X 3.X
This allows leading zeros in your filenames to be retained when incremented:
$ perl -E 'my $x = "02.X"; my ($y, $z) = ($x =~ /^(\d+)(.*)$/); say $x +; say ++$y . $z' 02.X 03.X
Which you may want to consider for a future filename convention to facilitate sorting. Compare these:
$ perl -E 'say for sort qw{1.X 9.X}' 1.X 9.X $ perl -E 'say for sort qw{1.X 9.X 10.X}' 1.X 10.X 9.X $ perl -E 'say for sort qw{01.X 09.X 10.X}' 01.X 09.X 10.X
"I'd like to write a perl equivalent that would give me freedom to choose the underlying encoding."
There's a variety of ways to do this. You don't say how the encoding is chosen: the following is just general information. See the open pragma and the open function; both contain links to additional information. See any perluni* links in http://perldoc.perl.org/perl.html.
"Does ascii have a representation for Ü?"
I see that AM has answered this. In Unicode, that character is:
U+00DC LATIN CAPITAL LETTER U WITH DIAERESIS
You might want to look at the Unicode Code Charts. That particular character is in (PDF link) "C1 Controls and Latin-1 Supplement". You may find it useful to familiarise yourself with the blocks of characters you deal with most often, perhaps even download a copy for quick reference; alternatively, if this is something you'll only want occasionally, individual internet searches will find the same information (searching for just "Unicode Ü" worked for me).
"I'd show previous attempts, but they look awful."
Showing what you've tried, even unsuccessful attempts, will often help us to better help you. We can see where your thought process (via code logic) was heading and perhaps steer you on a better course. A few minor tweaks may turn "awful" into "awesome". It can also help future readers who might be trying similar things.
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: create clone script for utf8 encoding
by Aldebaran (Curate) on Dec 19, 2018 at 05:26 UTC | |
by kcott (Archbishop) on Dec 19, 2018 at 07:58 UTC | |
by choroba (Cardinal) on Dec 20, 2018 at 15:59 UTC | |
by kcott (Archbishop) on Dec 21, 2018 at 03:12 UTC | |
by Aldebaran (Curate) on Jan 03, 2019 at 08:11 UTC | |
by ikegami (Patriarch) on Dec 20, 2018 at 18:08 UTC |