CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Pattern Matching...UGG!

 



ACtheMadScripter
Deleted

Sep 8, 2000, 6:10 AM

Post #1 of 4 (617 views)
Pattern Matching...UGG! Can't Post

My problem is this:

I need to match any instances of the inputted data within each line of the file then output that line if the Match is true.

this is the code i wrote to do it. but i seem to get stuck. Not all the data is coming out. i dont know if my while statement has an error. Im looking for someone who has done this kind of thing before.
###########################################
sub display {
$user = $formdata{'user'};
$domain = $formdata{'domain'};

open(VIRT, "</etc/mail/virtusertable");
@VIRT = <VIRT>;
close (VIRT);

print "Content-type: text/html\n\n";
print "These are the current alias for your POP account:<br>\n\n";
$tempvar = 0;
$x = 0;
while ($tempvar == 0) {
if ($VIRT[$x] =~ /[$domain]/) { print "$VIRT[$x] $domain $x<BR>\n"; $x++; }
if ($VIRT[$x] =~ /[$user]/) { print "$VIRT[$x] $user $x<BR>\n"; $x++; }
if (eof(VIRT)) { print "Done!"; $tempvar = 1; }
}
print "done";
}
############################################

I've done alot of variations of this code ,from simple to complex, expecially where the patten matching is concerned. Im baffeled and flamboozeld!!
PLZ HELP THE MAD

------------------
AC the Mad Scripter
Script long and prosper!


japhy
Enthusiast

Sep 8, 2000, 6:31 AM

Post #2 of 4 (617 views)
Re: Pattern Matching...UGG! [In reply to] Can't Post

Your biggest problem is that [ and ] are regex metacharacters. Try backslashing them:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


if ($text =~ /\[$user\]/) { ... }
</pre><HR></BLOCKQUOTE>

And that while loop of yours is a bit silly-looking. You shouldn't check for eof(VIRT), especially since you CLOSED the filehandle. There's no need to store the file in an array. Just loop over it with while:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$x = 1;
open VIRT, "/etc/mail/virtusertable";
while (<VIRT> ) {
print "$_ $user $x<br>\n" if /\[$user\]/;
print "$_ $domain $x<br>\n" if /\[$domain\]/;
$x++;
}
close VIRT;
</pre><HR></BLOCKQUOTE>


------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher



ACtheMadScripter
Deleted

Sep 8, 2000, 7:13 AM

Post #3 of 4 (617 views)
Re: Pattern Matching...UGG! [In reply to] Can't Post

Yes i see..Maybe i should explain futher..

This is the contents of my file im reading.

####
@1punk.com %1@www.1punk.com
andy@thepunk.com
donnie@thepunk.com
@bellsouth.net %1@www.bellsouth.net
andy@bellsouth.net
donnie@bellsouth.net
####

The End user enters his Username and Domain name and submits... ie: andy and thepunk.com.
i need it to pull all thepunk.com's that have the word andy with it, ie. it should pulls andy@thepunk.com but not andy@bellsouth.net.

Yea, my code is a bit Novice. maybe i should post there Smile

HELP THE MAD!



ACtheMadScripter
Deleted

Sep 8, 2000, 7:49 AM

Post #4 of 4 (617 views)
Re: Pattern Matching...UGG! [In reply to] Can't Post

OHHHHHH, Sweet Revelation!

i see whats going on here!
nevermind my last post.. I will just be dealing with the Domain Name and thats all, So what u have given me works sweetly minus the username stuff, that will pull just what i need. Much Thanks JAPHY!!!



------------------
AC the Mad Scripter
Script long and prosper!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives