Reputation: 113
I'm trying to get white space and assign it to a string using perl
.
I have a string
$line = " Testing purpose"
I want to get the white space in that string and assign it to another string. Can any one help me here?
$line = " Testing purpose";
$space = " ";
( This space variable will have space from $line
.)
Upvotes: 0
Views: 62
Reputation: 511
Use regular expressions.
$line =~ m/^(\s*)/;
$space = $1;
This will match spaces and tabs, leaving original string unmodified. If you want to also remove space from original string, use this:
$line =~ s/^(\s*)//;
$space = $1;
Upvotes: 2