Skip to content

Values from command-line switch -s are not in UTF-8 #23377

Closed

Description

@agguser
$ perl -CASD -e'
   print "$^V\n"
      , map { "$_ ".length."\n" } $a, $ARGV[0]
   ' -s -- -a=ก ข
v5.40.2
ภ3   # expect: ก 1
ข 1

Activity

  1. changed the title [-]Values from command-line switch `-s` is not in UTF-8[/-] [+]Values from command-line switch `-s` are not in UTF-8[/+] on Jun 19, 2025
  2. guest20 commented on Jun 19, 2025

    @guest20

    -s, wow. It's been a hot minute...

  3. Grinnz commented on Jun 19, 2025

    @Grinnz
    Contributor

    -s is discouraged in the docs and is extremely rudimentary. This could be considered a bug since -CA should interpret @ARGV in the internal upgraded encoding, but apparently that doesn't apply before -s. I would recommend using Getopt::Long instead, or an option parser that may be more oneliner friendly like https://metacpan.org/pod/Opt::Imistic.

    I also recommend https://metacpan.org/pod/Decode::ARGV instead of -CA and https://perldoc.perl.org/open or https://metacpan.org/pod/open::layers instead of -CSD in any serious code, because -C does not validate that the input is UTF-8 nor does it restrict its output to UTF-8, but instead assumes everything is in Perl's internal upgraded encoding which is a superset of UTF-8.

  4. agguser commented on Jun 19, 2025

    @agguser
    Author

    I think -s is good enough for one-liner code (like awk -v), so please fix it to be consistent with @ARGV.

    To ensure backward compatibility, s may be added to be a value for -C (e.g. -CsASD).

    Also, it would be great to have a hash variable (specified by -s:) containing all -s variables, e.g.:

    $ perl -E'
       say join ", ", map { "$_=$s{$_}" } keys %s
       ' -s:s -- -a=1 -b=2
    a=1, b=2
  5. added a commit that references this issue on Oct 11, 2025
    26ae0d6
  6. added a commit that references this issue on Oct 13, 2025
    597f346
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions