in reply to looking for a regex
To substitute a variable you could modify the above as follows:#!/usr/bin/perl -wl use strict; my $str = '{fred and barney} {bam bam} {pebbles} {} { }'; print $str; $str =~ s|({[^}]+})|(my $tmp = $1) =~ s/ /_/g; $tmp|eg; print $str; __END__ Prints: {fred and barney} {bam bam} {pebbles} {} { } {fred_and_barney} {bam_bam} {pebbles} {} {___}
my $str2 = '{fred and barney} {bam bam} {pebbles} {} { }'; print $str2; my $var = "xxxxx"; $str2 =~ s|({[^}]+})|{$var}|g; print $str2; __END__ Prints: {fred and barney} {bam bam} {pebbles} {} { } {xxxxx} {xxxxx} {xxxxx} {} {xxxxx}
If you have to deal with nested braces you should have a look at the Text::Balanced module.
--
John.
|
|---|