silentbob343 has asked for the wisdom of the Perl Monks concerning the following question:
Hope you guys/gals can help me out with this one.
I am building an address string from disparate elements, i.e.
my $address = $strnum . $strname . $strtype . " " . $strdir;
I then use a regex to remove duplicate whitespace leaving only a single space between the values, i.e. "123 Main St NE".
$address =~ s/ +/ /g;But I need the $address string to be the same length among all the records, 37 bytes. Tacking on blank space to the end is an acceptable solution for my purposes, but I am unsure how to go about it as the number of spaces needed will vary from address to address. Is there a regex that will force a length while removing duplicate white space from within the string?
Thank in advance for any assistance you can provide. I feel like this should be a simple thing to do, but as Perl novice I am lost.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Remove whitespace in string and maintain overall length
by toolic (Bishop) on Nov 19, 2015 at 18:13 UTC | |
by silentbob343 (Initiate) on Nov 19, 2015 at 19:16 UTC | |
|
Re: Remove whitespace in string and maintain overall length
by BrowserUk (Patriarch) on Nov 19, 2015 at 19:28 UTC | |
|
Re: Remove whitespace in string and maintain overall length
by kennethk (Abbot) on Nov 19, 2015 at 19:12 UTC | |
by silentbob343 (Initiate) on Nov 19, 2015 at 19:25 UTC | |
|
Re: Remove whitespace in string and maintain overall length
by Anonymous Monk on Nov 19, 2015 at 20:19 UTC | |
|
Re: Remove whitespace in string and maintain overall length
by RonW (Parson) on Nov 21, 2015 at 03:59 UTC |