I have a perl variable that is being read in from another script's STDOUT:
$var = `someScript.sh`
print $var <---- Prints "somestring"
However, the variable contains more than "somestring". There are 15 more characters on the front of the variable (special and not-special but hidden) that don't show when I print.
length($var) <--- Returns a number 10-15 larger than "somestring" has chars
I can eliminate the special characters like so:
$var =~ s/[^[:print:]]+//g
But it appears that there are also non-special characters that are revealed once the special characters have been removed:
print $var <---- Displays "0;<hostname>somestring"
(where <hostname> is the system hostname)
Is there a way to eliminate both the special characters AND the non-special characters that were being hidden? I want to be able to use $var as the key of a hash, and then reference it by "somestring"
$hash{$var} = 123
print $hash{'somestring'}
Thoughts?
Can we assume that the characters you want to remove are before the non-printable characters ?
If so, maybe something like
$var =~ s/.*[^[:print:]]+//;
could work ?
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