Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: How to expand a string

by tcf03 (Deacon)
on Nov 29, 2007 at 15:46 UTC ( [id://653883] : note . print w/replies, xml ) Need Help??

in reply to How to expand a string

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $string = 'RAGGTS'; my @temp; my @wanted; if ( grep /R/, $string ) { my $orig = $string; $string =~ s/R/A/g; push @temp, $string; $string = $orig; $string =~ s/R/G/g; push @temp, $string; } for my $string_ (@temp) { if ( grep /S/, $string_ ) { my $orig = $string_; $string_ =~ s/S/C/g; push @wanted, $string_; $string_ = $orig; $string_ =~ s/S/G/g; push @wanted, $string_; } } print Dumper @itemb;

a recursive sub might make that a little cleaner though.


output is
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
  --Ralph Waldo Emerson