Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

whitespace-squashing in scalars

Status
Not open for further replies.

DoraC

Programmer
Joined
May 7, 2002
Messages
98
Location
US
hi,

A variable I parse input into in one of my programs can (and will) in certain situations be fed pure whitespace. Non-whitespace situations aren't a problem, but if it happens to receive a space, I don't want to lose it. Here's an example:
Code:
    $var = " ";
    $var2 = length $var;
    print "length is: $var2\n";

and the output is: length is: 0

Is there any way to prevent this from happening? My guess is that this whitespace-squashing is an immutable aspect of Perl, but I'm not sure. There are, of course, ways i can get around this but the cleanest/neatest would be to (in this context) have the whitespace not get squashed.

Thanks!
dora
 
You must have a typo in your code, becuase spaces do count as characters, and thus, are considered by the length() function.

Could you copy and paste your affected code? Becuase the above actually doesn't produce the output you specified.

--jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top