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:
Finding all strings containing similar name

 



Zamereon
New User

Feb 12, 2011, 6:42 PM

Post #1 of 4 (951 views)
Finding all strings containing similar name Can't Post

Basically I want to search through a data base and find all the strings that have like a .com or something like that. Basically *.com and listing them. Would it be some sort of compare function?

Thanks in advance

EDIT: I would also like to count the percentage of those files in the database. Would the code be similar to filling a counter with the number on files then dividing by the total number of sites?


(This post was edited by Zamereon on Feb 12, 2011, 6:46 PM)


budman
User

Feb 12, 2011, 11:02 PM

Post #2 of 4 (944 views)
Re: [Zamereon] Finding all strings containing similar name [In reply to] Can't Post

 
Percentage: my $pct = ( $items_found / $total_items )

For searching a database, look at a DBI module for your database type.
If you need the percentage, you'll need process the data using the fetchrow or similar function. Then have two counters, one to count total items and another to count .com sites.
if ( $col_data =~ /\.com/i ) { $items_found++ }
$total_items++


Zamereon
New User

Feb 14, 2011, 11:19 AM

Post #3 of 4 (924 views)
Re: [budman] Finding all strings containing similar name [In reply to] Can't Post

This works, however if there's a site such as www.command.com it also considers the .command part of it as a .com. Is there a way to filter that? And also what does the /i at the end stand for?

Thanks Again.


swanny99
New User

Feb 14, 2011, 5:16 PM

Post #4 of 4 (915 views)
Re: [Zamereon] Finding all strings containing similar name [In reply to] Can't Post

if ( $col_data =~ /\.com/i ) { $items_found++ }
$total_items++

The i means ignore case of data. SOMESITE.com someSiTE.cOm

You really need to look in to perl matching data. It could take quite a complicated match to get all the different types of url you may have in your data.

This page may help:- http://cs.uccs.edu/~cs301/perl/re.htm

If your data is just somesite.com and www.somesite.com , then change /\.com/i to /\.com$/i . The $ insists that the .com be at the end of the string $col_data. You may then need to make sure you have no trailing white spaces or new lines with $col_data =~ s/\s+$//; before the if (...


(This post was edited by swanny99 on Feb 14, 2011, 5:19 PM)

 
 


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

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