[26666] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8773 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 18 14:06:29 2005

Date: Sun, 18 Dec 2005 11:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 18 Dec 2005     Volume: 10 Number: 8773

Today's topics:
        "Close match" regex <t18_pilot@hotmail.com>
    Re: "Close match" regex <noreply@gunnar.cc>
    Re: "Close match" regex axel@white-eagle.invalid.uk
    Re: "Close match" regex <no@email.com>
    Re: "Close match" regex <no@email.com>
    Re: "Close match" regex <tadmc@augustmail.com>
        How to align printed elements in array? <itfred@cdw.com>
    Re: How to align printed elements in array? <noreply@gunnar.cc>
        Tie 2 Dimention Array to File <speediercoREMOVE_THIS@yahoo.com>
    Re: Tie 2 Dimention Array to File (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 18 Dec 2005 13:55:50 GMT
From: "William Hymen" <t18_pilot@hotmail.com>
Subject: "Close match" regex
Message-Id: <GTdpf.6804$Dd2.5572@newsread3.news.atl.earthlink.net>

I was wondering if there were a built-in
pattern finder to get a close match on strings.

Our users are constantly omitting dashes, dots,
and spaces from software release labels. And
when you look at the list with intelligent eyes,
you see it's obvious what they meant.

software_version-2.4.5 = = software-version_245

You get the idea.
Anyone have a regex solution?

Thanks in advance

Bill








------------------------------

Date: Sun, 18 Dec 2005 17:57:04 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: "Close match" regex
Message-Id: <40lim3F1ahb4vU1@individual.net>

William Hymen wrote:
> I was wondering if there were a built-in
> pattern finder to get a close match on strings.

I think there is some module that attempts to do it, but I don't know 
the name of it.

> Our users are constantly omitting dashes, dots,
> and spaces from software release labels. And
> when you look at the list with intelligent eyes,
> you see it's obvious what they meant.
> 
> software_version-2.4.5 = = software-version_245
> 
> You get the idea.

Actually, no. What problem are you trying to solve? Wouldn't it be 
better to let the users select from a list of items rather than type?

> Anyone have a regex solution?

To which problem? What did you try yourself? Have you read the posting 
guidelines yet?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Sun, 18 Dec 2005 17:21:33 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: "Close match" regex
Message-Id: <xUgpf.11143$iz3.2905@text.news.blueyonder.co.uk>

William Hymen <t18_pilot@hotmail.com> wrote:
> I was wondering if there were a built-in
> pattern finder to get a close match on strings.
 
> Our users are constantly omitting dashes, dots,
> and spaces from software release labels. And
> when you look at the list with intelligent eyes,
> you see it's obvious what they meant.
 
> software_version-2.4.5 = = software-version_245
 
> You get the idea.
> Anyone have a regex solution?

You could strip out all non-alphanumeric characters and compare
the strings.

#!/usr/local/bin/perl

use strict;
use warnings;

my $word1 = 'software_version-2.4.5';
my $word2 = 'software-version_245';

$word1 =~ s/[^a-zA-Z0-9]//g;	# Long winded pattern match
$word2 =~ s/[^a-zA-Z0-9]//g;	# as \w includes '_'.

print "Match\n" if $word1 eq $word2;

 
Axel


------------------------------

Date: Sun, 18 Dec 2005 17:22:35 +0000
From: Brian Wakem <no@email.com>
Subject: Re: "Close match" regex
Message-Id: <40lk6rF1ank49U1@individual.net>

William Hymen wrote:

> I was wondering if there were a built-in
> pattern finder to get a close match on strings.
> 
> Our users are constantly omitting dashes, dots,
> and spaces from software release labels. And
> when you look at the list with intelligent eyes,
> you see it's obvious what they meant.
> 
> software_version-2.4.5 = = software-version_245
> 
> You get the idea.
> Anyone have a regex solution?
> 
> Thanks in advance


How about removing all alphanumeric chars and then doing a string comparison
(after uc or lc'ing both strings).


-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


------------------------------

Date: Sun, 18 Dec 2005 17:23:19 +0000
From: Brian Wakem <no@email.com>
Subject: Re: "Close match" regex
Message-Id: <40lk87F1ank49U2@individual.net>

Brian Wakem wrote:

> How about removing all alphanumeric chars and then doing a string
                        ^ non

> comparison (after uc or lc'ing both strings).




-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


------------------------------

Date: Sun, 18 Dec 2005 11:27:26 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: "Close match" regex
Message-Id: <slrndqb6vu.118.tadmc@magna.augustmail.com>

William Hymen <t18_pilot@hotmail.com> wrote:

> I was wondering if there were a built-in
> pattern finder to get a close match on strings.


   perldoc -q match

       How can I do approximate matching?


> Anyone have a regex solution?


Why do you restrict the solution to implementation via a regex?

Would a solution to your problem that does not use regexes 
be unacceptable for some reason? 

If so, then why?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sun, 18 Dec 2005 09:31:34 -0500
From: Fred <itfred@cdw.com>
Subject: How to align printed elements in array?
Message-Id: <pan.2005.12.18.14.31.33.524474@cdw.com>

I'm pushing 3 variables into an array named 
@sorted_countries:

   push(@invalid_countries, "$country_code\t$country\t$ip\n");

This is then sorted by country code:

   @sorted_countries = sort @invalid_countries;

Now when I print @sorted_countries the output is
shifted, even though there is one tab between
each entry.  I've tried increasing tabs, trimming
whitespace, among other things, and the output
is always shifted.  Currently I'm playing with
the format/write commands.  Any ideas how to
align the output?

-Thanks


CN      China                   202.108.23.70
CN      China                   202.160.180.105
CN      China                   202.160.180.169
CN      China                   202.160.180.213
CN      China                   218.18.32.21
CN      China                   220.189.253.74
CY      Cyprus                  82.211.152.11
DE      Germany                 213.196.210.186
IL      Israel                  147.234.2.4
IL      Israel                  84.94.114.250
IN      India                   203.196.158.244
IN      India                   59.93.73.113
IT      Italy                   80.21.203.2
PH      Philippines                     58.69.216.245
RU      Russian Federation                      81.19.66.8
RU      Russian Federation                      82.179.108.6
SA      Saudi Arabia                    212.138.64.171
SA      Saudi Arabia                    212.138.64.172
SA      Saudi Arabia                    212.138.64.173
SA      Saudi Arabia                    212.138.64.174
SA      Saudi Arabia                    212.138.64.176
TW      Taiwan, Province of China                       221.169.56.134




------------------------------

Date: Sun, 18 Dec 2005 18:16:05 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to align printed elements in array?
Message-Id: <40ljpkF1an1kgU1@individual.net>

Fred wrote:
> I'm pushing 3 variables into an array named 
> @sorted_countries:
> 
>    push(@invalid_countries, "$country_code\t$country\t$ip\n");
> 
> This is then sorted by country code:
> 
>    @sorted_countries = sort @invalid_countries;
> 
> Now when I print @sorted_countries the output is
> shifted, even though there is one tab between
> each entry.  I've tried increasing tabs, trimming
> whitespace, among other things, and the output
> is always shifted.

     for ( @sorted_countries ) {
         printf '%-5s%-30s%s', split /\t/;
     }

perldoc -f printf
perldoc -f sprintf

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Sun, 18 Dec 2005 05:01:27 -0500
From: "OttawaTrade" <speediercoREMOVE_THIS@yahoo.com>
Subject: Tie 2 Dimention Array to File
Message-Id: <vbudnQD9Kr7mrjjeRVn-jQ@rogers.com>

here is the default form tie::file
        use Tie::File;

        tie @array, 'Tie::File', 'data.txt' or die ...;

my data.txt looks like this

ID|number|name|address|
a|a.number|a.name|a.address|
b|b.number|b.name|b.address|

this is basically a read only table.
i hope to be able to sort by name, number or address etc.

so i want to sort
$array[1][2]
$array[2][2]
$array[3][2]

etc

i have done the sort part in a 1D array. so the only problem i have is how
to tie a 2D arry to file.

how do i define @array 2D? how does Tie:File know what the seperator is?





------------------------------

Date: 18 Dec 2005 10:50:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Tie 2 Dimention Array to File
Message-Id: <do3eth$dd6$1@mamenchi.zrz.TU-Berlin.DE>

OttawaTrade <speediercoREMOVE_THIS@yahoo.com> wrote in comp.lang.perl.misc:
> here is the default form tie::file
>         use Tie::File;
> 
>         tie @array, 'Tie::File', 'data.txt' or die ...;
> 
> my data.txt looks like this
> 
> ID|number|name|address|
> a|a.number|a.name|a.address|
> b|b.number|b.name|b.address|
> 
> this is basically a read only table.
> i hope to be able to sort by name, number or address etc.
> 
> so i want to sort
> $array[1][2]
> $array[2][2]
> $array[3][2]
> 
> etc
> 
> i have done the sort part in a 1D array. so the only problem i have is how
> to tie a 2D arry to file.
> 
> how do i define @array 2D? how does Tie:File know what the seperator is?

You don't.  Tie::File ties an array so that its elements are lines of the
file.  The lines are strings, nothing else so the result will always
be a one-dimensional array.

The data you have is known as CSV (Comma Separated Values), though the
separator is "|", not ",".  A CPAN search for "Tie" and "CSV" yields
Tie::CSV_File, which ought to do what you want.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8773
***************************************


home help back first fref pref prev next nref lref last post