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: Beginner:
a regex problem

 



uatt
User

Nov 9, 2002, 10:12 PM

Post #1 of 6 (925 views)
a regex problem Can't Post

I got a script that can get the index number out if the address is matching


Code
   

#!/usr/bin/perl
print "Content-type: text/html\n\n";

open(FILE, "ca.dat");
while (<FILE>) {
if($_ =~ /(new\s*york)|bost(a|e)n/gi){push(@a, $_);}
}
close(FILE);
print "index numbers are:<br>\n";
foreach(@a)
{$_ =~ s/^(\d+)\s.*/$1/g;
print "$_<br>\n";}



jryan
User

Nov 9, 2002, 11:02 PM

Post #2 of 6 (921 views)
Re: [uatt] a regex problem [In reply to] Can't Post

What exactly is your problem?


uatt
User

Nov 9, 2002, 11:13 PM

Post #3 of 6 (920 views)
Re: [jryan] a regex problem [In reply to] Can't Post

sorry My later part has been erased

Information on ca.dat is as follows

number1 address1 anotheraddress1

number2 address2 anotheraddress2

number3 address3 anotheraddress3

....

What I am going to do is design an form and I can paste all information in ca.dat into

textarea field i.e. $message = param('textarea');

I an stucking at the part of regex on a string ($message) as I want to do the same effect as file open in my previous code..


(This post was edited by uatt on Nov 9, 2002, 11:15 PM)


uatt
User

Nov 10, 2002, 12:40 AM

Post #4 of 6 (917 views)
Re: [uatt] a regex problem [In reply to] Can't Post

I think I solve the problem

$message=param('textarea');
@datas = split /\n/, $message;

@datas is equivalent to the array opened from a file


Paul
Enthusiast

Nov 10, 2002, 2:12 AM

Post #5 of 6 (915 views)
Re: [uatt] a regex problem [In reply to] Can't Post

You can leave out $_ =~ from both your regexs when using $_

Also change (a|e) to ([ae]) - it is quicker.


uatt
User

Nov 10, 2002, 5:07 AM

Post #6 of 6 (912 views)
Re: [RedRum] a regex problem [In reply to] Can't Post

yes, thats simpler...

 
 


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

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