if I remove square brackets around $user, the program will just output every line refusing to perform grep function.

This is because you need to force the evaluation of the $user variable. This is an example under the Perl debugger of one possible way to do it:

DB<1> @array = qw /foo foobar bar barfoo fobar foobaz /; DB<2> x @array; 0 'foo' 1 'foobar' 2 'bar' 3 'barfoo' 4 'fobar' 5 'foobaz' DB<3> $user = "foo"; DB<4> @a = grep /^\Q$user\E/, @array; DB<5> print "@a"; foo foobar foobaz DB<7> print join " ", grep !/^\Q$user\E/, @array; bar barfoo fobar
But using square brackets does not work as expected because it is defining a character class:
DB<8> print join " ", grep !/^[$user]/, @array; bar barfoo DB<9> print join " ", grep /^[$user]/, @array; foo foobar fobar foobaz
On the other hand, using ${user} instead of $user will be sufficient to get it to work properly:
DB<27> print join " ", grep /^${user}/, @array; foo foobar foobaz DB<28> print join " ", grep !/^${user}/, @array; bar barfoo fobar


In reply to Re^5: problem with deleting a row by Laurent_R
in thread problem with deleting a row by brianMonk

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.