[Chicago-talk] scalar manipulation

Steven Lembark lembark at wrkhors.com
Fri Mar 31 12:38:56 PST 2006

 >  I need to turn
 >  $a = "now is a good time for a beer";
 >  to
 >  "nowisagoodtimeforabeer";

Depends on whether you want to modify the original
variable or not. You can remove anything with a
regex on the original:

     $phrase =~ s{ \s+ }{}gx;

will modify $phrase in place. You can also use a
regex on a copy or a join-and-split to make a new
copy of the variable:

     ( my $nospace = $phrase ) =~ s{ \s+ }{}gx;


     my $nospace = join '', split '', $phrase;

will give you a separate variable without the spaces.

Steven Lembark                                         85-09 90th Street
Workhorse Computing                                  Woodhaven, NY 11421
lembark at wrkhors.com                                      +1 888 359 3508

More information about the Chicago-talk mailing list