in reply to Help with Regular Expressions and Perl

Here you go --
use strict; use warnings; my $variable = join("", <DATA>); my @num = qw|zero one two three four five six seven eight nine|; $variable =~ s/(\d)/$num[$1]/g; print "$variable"; __DATA__ This is 1 great time 2 have a 3 way 4some. When 5 and 6 together make 11. Some 8 or 9 of us will see that.
Output:
This is one great time two have a three way foursome. When five and six together make oneone. Some eight or nine of us will see that.
Update:Thanks JavaFan(++) for the heads-up on \d - My education continues.
cdarke (See his note below) - yes - I used join because the O.P did. As you point out, it is completely unnecessary.

     Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

Replies are listed 'Best First'.
Re^2: Help with Regular Expressions and Perl
by JavaFan (Canon) on Apr 01, 2010 at 08:27 UTC
    There are hundreds of characters on which your program will fail. Please do realize that /\d/ is not a short cut for /[0-9]/. In fact, /\d/ is a short cut (in 5.10.1, 5.12 is likely to have more characters) for:

    /[0123456789٠١٢٣٤٥٦٧٨٩۰۱۲۳۴۵۶۷۸۹߀߁߂߃߄߅߆߇߈߉०१२३४५६७८९০১২৩৪৫৬৭৮৯੦੧੨੩੪੫੬੭੮੯૦૧૨૩૪૫૬૭૮૯୦୧୨୩୪୫୬୭୮୯௦௧௨௩௪௫௬௭௮௯౦౧౨౩౪౫౬౭౮౯೦೧೨೩೪೫೬೭೮೯൦൧൨൩൪൫൬൭൮൯๐๑๒๓๔๕๖๗๘๙໐໑໒໓໔໕໖໗໘໙༠༡༢༣༤༥༦༧༨༩၀၁၂၃၄၅၆၇၈၉႐႑႒႓႔႕႖႗႘႙០១២៣៤៥៦៧៨៩᠐᠑᠒᠓᠔᠕᠖᠗᠘᠙᥆᥇᥈᥉᥊᥋᥌᥍᥎᥏᧐᧑᧒᧓᧔᧕᧖᧗᧘᧙᭐᭑᭒᭓᭔᭕᭖᭗᭘᭙᮰᮱᮲᮳᮴᮵᮶᮷᮸᮹᱀᱁᱂᱃᱄᱅᱆᱇᱈᱉᱐᱑᱒᱓᱔᱕᱖᱗᱘᱙꘠꘡꘢꘣꘤꘥꘦꘧꘨꘩꣐꣑꣒꣓꣔꣕꣖꣗꣘꣙꤀꤁꤂꤃꤄꤅꤆꤇꤈꤉꩐꩑꩒꩓꩔꩕꩖꩗꩘꩙0123456789𐒠𐒡𐒢𐒣𐒤𐒥𐒦𐒧𐒨𐒩𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗𝟘𝟙𝟚𝟛𝟜𝟝𝟞𝟟𝟠𝟡𝟢𝟣𝟤𝟥𝟦𝟧𝟨𝟩𝟪𝟫𝟬𝟭𝟮𝟯𝟰𝟱𝟲𝟳𝟴𝟵𝟶𝟷𝟸𝟹𝟺𝟻𝟼𝟽𝟾𝟿]/

Re^2: Help with Regular Expressions and Perl
by cdarke (Prior) on Apr 01, 2010 at 09:02 UTC
    Not quite sure why you are bothering with the join, maybe because the OP tried to use it:
    use warnings; use strict; my @num = qw(zero one two three four five six seven eight nine); while (<DATA>) { s/([0-9])/$num[$1]/g; print } __DATA__ This is 1 great time 2 have a 3 way 4some. When 5 and 6 together make 11. Some 8 or 9 of us will see that.