#!/usr/bin/perl
use warnings;
use strict;
$\ = $/;
$_ = reverse "(a+b)*c"; # or some longer sequence
s/\)([^()]+)\(/]$1[/g;
print scalar reverse y/][/)(/r;
__END__
$ perl test.pl
Missing right curly or square bracket at test.pl line 10, within string
syntax error at test.pl line 10, at EOF
Execution of test.pl aborted due to compilation errors.
####
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
my $reversed = reverse "(a+b)*c"; # or some longer sequence
$reversed =~ tr/()/[]/;
my $str = reverse $reversed;
say $str;
__END__
$ perl test.pl
[a+b]*c
##
##
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
my $test = "(a+b)*c";
$test =~ tr/()/[]/;
say $test;
__END__
$ perl test.pl
[a+b]*c
##
##
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
sub replaceChar {
my ($str, $char, $replace) = @_;
substr($str, index($str, $char), length($char), $replace);
return $str;
}
my $s = "(a+b)*c";
my $leftParenthesis = "(";
my $rightParenthesis = ")";
my $leftCurlyBracket = "[";
my $rightCurlyBracket = "]";
my $str = replaceChar($s, $leftParenthesis, $leftCurlyBracket);
say $str;
say replaceChar($str, $rightParenthesis, $rightCurlyBracket);
__END__
$ perl test.pl
[a+b)*c
[a+b]*c