The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

mr_magoo (3) [Avatar] Offline
#1
If I run the following:

fgrep '@ARGV' preg
-or-
fgrep @ARGV preg

the proper output is observed.

If I run this:

./preg -f '@ARGV' preg
-or-
./preg -f @ARGV preg
-or-
./preg -f "@ARGV" preg

the entire "preg" file is listed.

What am I doing wrong?
mr_magoo (3) [Avatar] Offline
#2
Re: preg script question
If I change line 29 from this:

$f and $pattern='Q' . $pattern . 'E';

to this:

$f and $pattern = quotemeta $pattern;

then my example works properly!

Still trying to figure out how that "@" figures into the difficulty first mentioned.
mr_magoo (3) [Avatar] Offline
#3
Re: preg script question
OK - I think I understand now. The line:

$f and $pattern='Q' . $pattern . 'E';

is sticking Q and E on either end of the string, but this is not performing
the "quotemeta" functionality because of the single quotes. The "quotemeta"
is done only with "Q...E" inside double quoted strings.

Either of these should fix it:

$f and $pattern = "Q$patternE";

$f and $pattern = quotemeta $pattern;

Correct me if I am off base here...