1) They're called "carets". They're not edible.

2) "it will only work if I broaden the regex by removeing the carrot and the scalar" Not so:

$_ = ':Admin!Admin@leet-A0B340B0.host.com PRIVMSG #channel :!quit'; $channel = '#channel'; if($_ =~ /^:(.*)!(.*) PRIVMSG $channel :(.*)$/){ my $user = $1; my $host = $2; my $message = $3; if ($message =~ /^!quit$/){ die "Quiting!\n"; } } __END__ output ====== Quiting!

$_ is apparently not what you expect it to be.

3) Why use a regexp for to compare against a constant string?
$message =~ /^!quit$/
is not as good as
$message eq '!quit'

4) I bet
/^:(.*)!(.*) PRIVMSG (#\S+) :(.*)$/
is not as efficient as:
/^:([^!]*)!(\S*) PRIVMSG (#\S+) :(.*)$/

5) Why use $channel in the regexp? That's rather odd. I'd use:

if($_ =~ /^:([^!]*)!(\S*) PRIVMSG (#\S+) :(.*)$/){ my $user = $1; my $host = $2; my $chnl = $3; my $message = $4; if ($chnl eq $channel) { if ($message =~ /^!quit$/){ die "Quiting!\n"; } ... } }

In reply to Re: Regexp problem matching commands for IRC bot by ikegami
in thread Regexp problem matching commands for IRC bot by StrifeChild

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.