Your approach could be fine if you wanted to restrict the allowed functions only to simple replacements. With a few minor tweaks I get this:

use strict; my @views = ("ignore","ignore","dont\\ignore\\this.vms","ignore"); my %regex_hash = ( '\.vms' => [ qr/\\/ , '/' ], ); for my $data (@views) { for my $re_key ( grep { $data =~ /$_/ } keys %regex_hash ) { $data =~ s!$regex_hash{$re_key}[0]!$regex_hash{$re_key}[1]!g; } } print join "\n", @views;
and the result is:
ignore ignore dont/ignore/this.vms
In regex_hash the key is the regex (as a string) to match against the view data. The first entry in the value arrayref is the match portion of the substitution. The second entry in the value arrayref is the replace portion of the substitution.

You'd have to be careful of using ! (in this implementation) in the key or the second value because I used it for the substitution delimiter.

Becuase of this and the flexibility offered by a sub dispatch table you're probably better off going that way, but I thought I'd show you how close you were to making it work!

Update: Just realised that liverpole already pointed this out. Using qr as in my example is a good idea however - it is more efficient and will protect you against quoting issues. See perlre if you are unfamiliar with qr


In reply to Re: Using a regex function from a hash by aufflick
in thread Using a regex function from a hash by perlNinny

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.