ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/XS.pm
(Generate patch)

Comparing CBOR-XS/XS.pm (file contents):
Revision 1.52 by root, Mon Apr 25 18:17:17 2016 UTC vs.
Revision 1.53 by root, Mon Apr 25 18:20:22 2016 UTC

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
593You can force whether a string ie encoded as byte or text string by using 593You can force whether a string is encoded as byte or text string by using
594C<utf8::upgrade> and C<utf8::downgrade>): 594C<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
599Perl doesn't define what operations up- and downgrade strings, so if the 599Perl doesn't define what operations up- and downgrade strings, so if the
600difference between byte and text is important, you should up- or downgrade 600difference between byte and text is important, you should up- or downgrade
601your string as late as possible before encoding. 601your string as late as possible before encoding. You can also force the
602use of CBOR text strings by using C<text_keys> or C<text_strings>.
602 603
603You can force the type to be a CBOR number by numifying it: 604You 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines