Perl metacharacters

2004-05-29 Thread JJB
I have problems with 2 different if statements that use
metacharacters.

if (/([EMAIL PROTECTED] )/)
 {
  $abuse_email = ${1};
 }

The data line it's reading looks like this,

remarks:  Please report all problems to [EMAIL PROTECTED] for
probes, port scans etc.

print($abuse_email) shows that it contains

[EMAIL PROTECTED] for probes, port scans etc.

The x.xxx can be any size, and any characters

How do I change the if statement so I only get the [EMAIL PROTECTED]
string?



Problem 2.

If (/(Net-.??-.??-.??-0-1)/)
 {
  $net_block = ${1};
 }


The data is (Net-xxx-xxx-xxx-0-1)
Each xxx group will all ways by 1 to 3 digits long and different
combinations every time.

When matched I want $net_block just to hold  Net-xxx-xxx-xxx-0-1

What is the correct syntax?

Thanks


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Perl metacharacters

2004-05-29 Thread Saint Aardvark the Carpeted
JJB disturbed my sleep to write:
 if (/([EMAIL PROTECTED] )/)
  {
   $abuse_email = ${1};
  }
[snip] 
 print($abuse_email) shows that it contains
 [EMAIL PROTECTED] for probes, port scans etc.
 How do I change the if statement so I only get the [EMAIL PROTECTED]
 string?

You want to minimize how much the bracket grabs.  Right now you're
telling it to grab as much as it can (.*); a better solution would
be

(/([EMAIL PROTECTED] )/)

which tells it to grab the smallest amount it can before the space.
Even better would be:

(/([EMAIL PROTECTED])\s/)

which grabs any word character, period, hyphen or underscore up to
a space.  Check your local listings to make sure I'm not leaving
out any characters legal for domain names.

 
 If (/(Net-.??-.??-.??-0-1)/)
  {
   $net_block = ${1};
  }
 
 The data is (Net-xxx-xxx-xxx-0-1)
 Each xxx group will all ways by 1 to 3 digits long and different
 combinations every time.
 When matched I want $net_block just to hold  Net-xxx-xxx-xxx-0-1
 What is the correct syntax?

Something like:

(/(Net-\d{1,3}-\d{1,3}-\d{1,3}-0-1)/

BTW, you'd be better off emailing Perl questions to a Perl-related
mailing list or newsgroup, or posting them to Perlmonks.org.

-- 
Saint Aardvark the Carpeted
[EMAIL PROTECTED]
Because the plural of Anecdote is Myth.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]