Reputation: 2498
I'm trying to insert a space after every semicolon of a string in Perl.
#!/usr/bin/perl
use strict; use warnings;
my $string = "1234;5678;232;5774;9784";
$string =~ s/;/"; "/g;
my $matched = $1;
print $matched . "\n";
But it doesn't work. My string is 1234;5678;232;5774;9784
. I want to print 1234; 5678; 232; 5774; 9784
. thanks
Upvotes: 0
Views: 150
Reputation: 5279
You want to print $string
not $matched
. Also, you don't need the quotes in the regex, unless you want them in there as well.
#!/usr/bin/perl
use strict;
use warnings;
my $string = "1234;5678;232;5774;9784";
$string =~ s/;/; /g;
print "$string\n";
prints 1234; 5678; 232; 5774; 9784
Upvotes: 2