in reply to Re^2: How would you rewrite this?
in thread How would you rewrite this?

Sure. Sorry I didn't put an explanation in the first post.

First, you are trying to get around the problem that you can't use s/// on a constant value (literal string "April 1, 2009"), so my first thought was this two-liner:

my $chosen_day = "April 1, 2009"; $chosen_day =~ s/\s\s/ /;

In case you haven't seen it, the =~ operator binds the string on the left to the pattern on the right (see perlop). But you asked for a one-liner, so I took advantage of the fact that the return value of an assignment can be bound to a pattern as well:

# Parenthesized assignment is bound to the substitution (my $c = "April 1, 2009") =~ s/\s\s/ /;
$,=' ';$\=',';$_=[qw,Just another Perl hacker,];print@$_;

Replies are listed 'Best First'.
Re^4: How would you rewrite this?
by Anonymous Monk on Aug 30, 2009 at 20:44 UTC
    Thanks. :-)