JP wrote:

$string =~ s/(\S{40}/\1 /g;

Only use \1 (and \2, \3, etc.) in regular expressions. Use $1 (and $2, $3, etc.) in double quoted strings.


$string =~ s/(\S{40})/$1 /g;


does exactly the trick I need.

now I wonder if it is possible to print the resulting spaced string without
changing $string itself?

Just copy the string to a new string.

( my $newstring = $string ) =~ s/(\S{40})/$1 /g;


do I really need a temporary variable or is it
possible to do something like:

print $string s/(\S{40}/\1 /g;

No, the substitution operator returns a numeric value, not the string. This will work:


print "@{[ $string =~ /\S{40}/g ]}";

Or this:

print join ' ', $string =~ /\S{40}/g;



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to