HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl question
Operating System - HP-UX
1825801
Members
2223
Online
109687
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2002 10:30 AM
11-22-2002 10:30 AM
Perl question
Alright I give up. I seriously need some help with this perl script.
Firswt let me tell you what I want it to do. I have procmail rules that filter incoming emails based on keywords (commingly used in spam and porn spam) and it filters it to a mailbox which I then go and check. What I want is to look at the mailbox with this script and print the keyword that matched as well as the line in the email that matched. So far this is what I have:
#!/usr/bin/perl
open( WORDLIST, "dirtywordlist.lst") or die( "Couldn't open word list: $!");
@list =;
close( WORDLIST ) or die( "Couldn't close word list: $!");
open( EMAILFILE, "dirtytest") or die( "Couldn't open word list: $!");
@email =;
close( EMAILFILE ) or die( "Couldn't close word list: $!");
foreach( @list){
$matched = grep /$_/i, @email;
if( $matched ){
print "$_\n";
print "$matched\n\n";
}
}
I am fairly new to perl and would greatly appreciate any help that someone can lend.
dirtywordlist.lst is the list of keywords to grep for and dirtytest is a test message I greated to see if the script is working correctly.
When I run this it print every keyword for $_ and $matched prints as 3 for every keyword. The file only contains one word that should match.
Thanks in advance for your help.
Firswt let me tell you what I want it to do. I have procmail rules that filter incoming emails based on keywords (commingly used in spam and porn spam) and it filters it to a mailbox which I then go and check. What I want is to look at the mailbox with this script and print the keyword that matched as well as the line in the email that matched. So far this is what I have:
#!/usr/bin/perl
open( WORDLIST, "dirtywordlist.lst") or die( "Couldn't open word list: $!");
@list =
close( WORDLIST ) or die( "Couldn't close word list: $!");
open( EMAILFILE, "dirtytest") or die( "Couldn't open word list: $!");
@email =
close( EMAILFILE ) or die( "Couldn't close word list: $!");
foreach( @list){
$matched = grep /$_/i, @email;
if( $matched ){
print "$_\n";
print "$matched\n\n";
}
}
I am fairly new to perl and would greatly appreciate any help that someone can lend.
dirtywordlist.lst is the list of keywords to grep for and dirtytest is a test message I greated to see if the script is working correctly.
When I run this it print every keyword for $_ and $matched prints as 3 for every keyword. The file only contains one word that should match.
Thanks in advance for your help.
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2002 01:38 AM
11-23-2002 01:38 AM
Re: Perl question
Where's your chomp's? :) You are now matching *with* newlines. And for optimization of the process, use qr//
#!/usr/bin/perl
sub file2list ($)
{
my $file = shift;
open FILE, "< $file" or die "Couldn't open $file: $!");
chomp (@list =);
close LIST or die "Couldn't close $file: $!");
@list;
} # sub2list
my @list = map { qr/$_/i } file2list ("dirtywordlist.lst");
my @email = file2list ("dirtytest");
foreach (@list) {
my $matched = grep /$_/, @email or next;
print "$_\n";
print "$matched\n\n";
}
#!/usr/bin/perl
sub file2list ($)
{
my $file = shift;
open FILE, "< $file" or die "Couldn't open $file: $!");
chomp (@list =
close LIST or die "Couldn't close $file: $!");
@list;
} # sub2list
my @list = map { qr/$_/i } file2list ("dirtywordlist.lst");
my @email = file2list ("dirtytest");
foreach (@list) {
my $matched = grep /$_/, @email or next;
print "$_\n";
print "$matched\n\n";
}
Enjoy, Have FUN! H.Merijn
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP