Most Borne-style shells (of which zsh, bash, and ksh are some) will let you define an environment variable for a single command by prefixing the command itself with something like:

ACTION_PATTERN='perl$' perl -ne '$count++ if m{$ENV{ACTION_PATTERN}};END{print $count, qq{\n};}' ~/.zsh_history.

You could do that here, but I'm wondering if there's not a bit of an XY problem in that you're wanting to use an arbitrary pattern in your search command and aren't sure how to pass that as an argument into your oneliner. If that were the case you could always do something like this and use shift to pull it out of @ARGV before the -n option starts iterating over things:

ROWS=$(perl -nE 'BEGIN{$PATTERN=shift();$PATTERN=qr/$PATTERN/;};$count +++ if m{$PATTERN};}{ say $count' 'perl$' ~/.zsh_history) echo "ROWS:$ROWS"

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re: Calling perl from zsh w/ vars by Fletch
in thread Calling perl from zsh w/ vars by k-man

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.