hilbert has asked for the wisdom of the Perl Monks concerning the following question:
Given the string: 'A B 1 2 3 4 5 6 7 8 9'
I want to put a semicolon between all the digits, replacing the space.
So, I want to get: 'A B 1;2;3;4;5;6;7;8;9'.
I coded in the file s.pl:
#!/usr/bin/perl -w use strict; while(<>) { my $row = $_; $row =~ s/(\d)\s+(\d)/$1;$2/g; print $row; } # while
then:
echo 'A B 1 2 3 4 5 6 7 8 9' | perl s.pl
returns:
A B 1;2 3;4 5;6 7;8 9
which is not what I expected...
Can somebody please tell me how to correct the s/// statement to get the expected result?
Thanks a lot.
Hilbert
|
|---|