in reply to One liner: remove ssh keys with quotemeta

This is another case where Perl probably is not the right tool for the job and you would be better off using sed than bringing up an entire perl instance just for one exact match. Try something like:

exec { "/bin/sed -i -e '\\%${line}%d' '${file}'" : ... }

Your problem seems to be the presence of the regex delimiter in some of the data that you need to match. Try using a different delimiter — in Perl /$pat/ is shorthand for m/$pat/ and you can replace it with m[$pat]. See perlsyn and perlop for more details.

Replies are listed 'Best First'.
Re^2: One liner: remove ssh keys with quotemeta
by afoken (Chancellor) on Nov 29, 2019 at 12:35 UTC
    exec { "/bin/sed -i -e '\\%${line}%d' '${file}'" : ... }

    That would still suffer from the same problem as perl - the default shell. See Re^2: One liner: remove ssh keys with quotemeta.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      While you are correct that the default shell can be a strange critter, the questioner's existing code assumes Bourne-like shell quoting rules, so I offered an example that follows suit.

      A better answer would probably be to write the update routines entirely in Ruby instead of calling out to other programs, but this is PerlMonks, not RubyMonks. :-)

        A better answer would probably be to write the update routines entirely in Ruby instead of calling out to other programs

        You are right. A simple read-modify-write shouldn't be that hard in Ruby, making it atomar atomic by writing to a new file followed by a rename shouldn't be hard, either.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)