in reply to How to eval an array element in regex's substitution

In the scope/context provided, it doesn't make sense to use regex to achieve "Hello zy". If it's always going to be "Hello " followed by index 2 and index 1 of @a array, then just make it: my $s = 'Hello ' . $a[2] . $a[1]; which can be easily parametarised in that format. Or even use splice. why the regex?
the hardest line to type correctly is: stty erase ^H

Replies are listed 'Best First'.
Re^2: How to eval an array element in regex's substitution
by aquarium (Curate) on Oct 27, 2010 at 05:40 UTC
    oh i get it, i think...this is the continuing saga of a mail merge. in my own opinion, you need to learn a bit more about *nix utilities, networking protocols (smtp for a start), and programming (the design aspect). otherwise you'll end up throwing together "solutions" that hang by a thread. it's not a criticism of you or your knowledge, but you seem to have currently a level of knowledge where you could make something nice or a mess. you need (i think) a more rigorous structure/modularity in your code and overall approach. which means more thinking and less coding. like everything else here this is just an opinion and you can just ignore it.
    the hardest line to type correctly is: stty erase ^H
      Maybe you think it simply.
      The $s is dynamic.It is maybe  "[2][1]" or maybe "[9]  [8] [3]",
      . I only wanna to replace the  [xx]with a fix array's element.
      But the rule is , the  [xx] is index of the array!
        yes, i think in this case regex is too much, as it's only a fixed parameter substitution. regex can become easily overused. And when you use a regex you introduce pitfalls. I always go for simple substitution or other string operations first. substr and index functions come in very handy.
        regards testing smtp...just in case this is not common knowledge, you can telnet to port 25 on your smtp server and issue commands to send emails, just as a module would. it's great for testing the viability of a particular idea/method...and then you can see if a module can do it or needs some tweaking. For example, you would see that you can send multiple separate emails during one session/connection to smtp server. Mind you, setting up a massively parallel process to send emails isn't going to change much on the smtp server end, which serves a FIFO queue anyway. And using one connection/send/disconnection per email is useful as a unit of measure that one email send completed. I would argue that unless your program needs hours to complete (the bulk email send) that you should just send them one by one. it's also good not to hog/thrash the mail server.
        anyway, hope your project is progressing well.
        the hardest line to type correctly is: stty erase ^H