… | |
… | |
588 | my $x = 3.1; # some variable containing a number |
588 | my $x = 3.1; # some variable containing a number |
589 | "$x"; # stringified |
589 | "$x"; # stringified |
590 | $x .= ""; # another, more awkward way to stringify |
590 | $x .= ""; # another, more awkward way to stringify |
591 | print $x; # perl does it for you, too, quite often |
591 | print $x; # perl does it for you, too, quite often |
592 | |
592 | |
593 | You can force whether a string ie encoded as byte or text string by using |
593 | You can force whether a string is encoded as byte or text string by using |
594 | C<utf8::upgrade> and C<utf8::downgrade>): |
594 | C<utf8::upgrade> and C<utf8::downgrade> (if C<text_strings> is disabled): |
595 | |
595 | |
596 | utf8::upgrade $x; # encode $x as text string |
596 | utf8::upgrade $x; # encode $x as text string |
597 | utf8::downgrade $x; # encode $x as byte string |
597 | utf8::downgrade $x; # encode $x as byte string |
598 | |
598 | |
599 | Perl doesn't define what operations up- and downgrade strings, so if the |
599 | Perl doesn't define what operations up- and downgrade strings, so if the |
600 | difference between byte and text is important, you should up- or downgrade |
600 | difference between byte and text is important, you should up- or downgrade |
601 | your string as late as possible before encoding. |
601 | your string as late as possible before encoding. You can also force the |
|
|
602 | use of CBOR text strings by using C<text_keys> or C<text_strings>. |
602 | |
603 | |
603 | You can force the type to be a CBOR number by numifying it: |
604 | You can force the type to be a CBOR number by numifying it: |
604 | |
605 | |
605 | my $x = "3"; # some variable containing a string |
606 | my $x = "3"; # some variable containing a string |
606 | $x += 0; # numify it, ensuring it will be dumped as a number |
607 | $x += 0; # numify it, ensuring it will be dumped as a number |