I want to create string in perl with length, for example 7, but "visible" contents, for example "a".
my $test = ...;
print $test result: "a" print length($test) result: 7
You add null characters to the string. Why you want to this is beyond me, but how you do it is shown below.
{ow-loopkin:tmp:->perl
$string = "e\0\0\0\0";
print length $string;
[ctrl+d]
5
{ow-loopkin:tmp:->
You can also use pack() to pad it with nulls:
ow-loopkin:tmp:->perl
$string = pack("Z6", 42);
print length $string;
[ctrl+d]
6
{ow-loopkin:tmp:->
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With