What "pattern" is that? Are you trying to build a regular expression to match each component there, so that you can pull out full names and e-mail addresses from text? Or are you trying to build a pattern out of $somename and $someaddress and match that against some known text to see if that combination exists? You'll need to be more descriptive with what you're trying to do.

If you're trying to see if a string matches your (simple) definitions of a full name and an e-mail address, you're going to have to define (in regex terms) what $somename and $someaddress really are. Perhaps something like this:

$somename = qr/[\w\.\s]+/; $someaddress = qr/[\w\.+]+@[\w\.]+/; if (/($somename) <($someaddress)>/) { print "Got a name of '$somename'\n"; print "Got address of '$someaddress'\n"; }
Note that this is generally not the best way of looking for e-mail addresses in plain text. The relevant RFC's describe very complex rules for valid SMTP addresses, and it is going to be very difficult for you to build a quality set of regular expressions that will be able to pull these out of text. You may be interested in Email::Find to locate e-mail addresses, and Email::Valid to validate a sample string as an e-mail address (does not search for it, just validates an assumed address).

On the other hand, if your intent is to build a pattern out of those two variables, to see if a particular line matches someone's name and e-mail address, you could easily do something like this:

$somename = 'David Nesting'; $someaddress = 'david@example.com'; $_ = 'David Nesting <david@example.com>'; if (/^$somename <$someaddress>$/) { print "Yep, this one is $somename!\n"; }
I hope this helps. Otherwise, please provide more information.

In reply to RE: Re: Building an SQL query by Fastolfe
in thread Building an SQL query by despair

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.