http://qs321.pair.com?node_id=653878


in reply to Re^2: How to expand a string
in thread How to expand a string

use strict; use warnings; use Data::Dumper; my %replace = ( R => '{A,G}', S => '{C,G}', K => '{G,T}', ' ' => '_', ); my $s = 'KAG GTR CAG CTG AAG SAG TCA GG'; my @results; for my $base (keys %replace) { $s =~ s/$base/$replace{$base}/g; } push @results, $_ while glob $s; @results = map { s/_/ /g; $_ } @results;
Update: BrowserUK's solution. Credits to him.

Replies are listed 'Best First'.
Re^4: How to expand a string
by Anonymous Monk on Nov 29, 2007 at 16:57 UTC
    Genius!! Anything I'd have written would have been considerably longer! Thanks very much.