in reply to Re: Replace arrays in external file
in thread Replace arrays in external file

i may have forgotten to mention that the array indexes must match, lets say @a1 was changed to "@a3455" all @a1's should be changed to match that one. my original code doesnt like those dots in the eval statement.

Replies are listed 'Best First'.
Re^3: Replace arrays in external file
by CountZero (Bishop) on Apr 10, 2012 at 20:18 UTC
    I showed you an alternative way of writing your eval which does not need any "dots".

    To make the "random" values stick to the elements of the @a array, try this:

    use Modern::Perl; my @replace = map int(rand(99999)), (0 .. 10); while (<DATA>) { do {print; next} unless /^eval/; s/(?<=\[)(\d+)(?=])/$replace[$1]/ge; print; } __DATA__ @a = ("'hello world'",'print ', ';'); eval("$a[1]$a[0]$a[2]");

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics