[25729] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7969 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 12 18:05:59 2005

Date: Tue, 12 Apr 2005 15:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 12 Apr 2005     Volume: 10 Number: 7969

Today's topics:
    Re: (the simplest question of the century ?)   Simple a <segraves_f13@mindspring.com>
        =?iso-8859-1?B?QVdFU09NRSBNT1ZJRSEgPDwgVGhpcyBmcmVlIG1v JavaDude_MSN233@yahoo.com
        Access... granted! <pkrupa@redwood.rsc.raytheon.com>
        Assistance with threading ...thread not returning c_campise@hotmail.com
    Re: Assistance with threading ...thread not returning <1usa@llenroc.ude.invalid>
    Re: Beginner Question #1 <tadmc@augustmail.com>
    Re: Client socket programming eating up CPU/memory <stryder22204@gmail.com>
        Creating o non-existing database <hackeras@gmail.com>
        File::Find - following s'linked directories? <nobody@bogus.com>
        Matching mixed up words (Michael T. Davis)
    Re: Matching mixed up words <1usa@llenroc.ude.invalid>
    Re: Matching mixed up words <thundergnat@hotmail.com>
    Re: Matching mixed up words xhoster@gmail.com
    Re: Matching mixed up words <1usa@llenroc.ude.invalid>
    Re: Matching mixed up words <tassilo.von.parseval@rwth-aachen.de>
    Re: Simple Encryption Script <hackeras@gmail.com>
    Re: Troubleshooting printing to file <matternc@comcast.net>
        Web Interface and index.pl separated?!? <hackeras@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 12 Apr 2005 18:26:23 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: (the simplest question of the century ?)   Simple access to ... ACCESS !
Message-Id: <jpU6e.8636$44.5606@newsread1.news.atl.earthlink.net>

"Milca" <Milca@laposte.net> wrote in message
news:d3gtgq$c3n$1@s1.news.oleane.net...
>
> Hi all,
>
> I'm a (or "one more") newcomer in Perl, and ask for very basic help.
>
> Despite some time spent to read all this forum and some CPAN docs, I've
> not found a simple explanation of my request however simple.
>
> I'd like to access - read only is sufficient for the beginning - to an
> MS ACCESS database from perls scripts. I'm on Win 2K.I'd like to make
> simple SQL or SQL-like queries (is that a pure dream ?) :seeing my
> tables, seeing the data of each table, bing able to select elementary
> data in tables, and even not necessarily with joining them. ... Truly a
> "basic access to ACCESS" !

Search Google Groups for "Access to MS-Access database with the Reader via
ODBC", where you'll find a thread with the same name. The link to Geoff Cox'
article has changed to http://www.micro-active.com/dbase.htm.

Search Google for "Dabbling in Live Databases Aaron Weiss" for a useful
tutorial. Another Google search for "Dabbling in Live Databases Aaron Weiss
GUFE" will show you the way to another useful tutorial.
--
Bill Segraves








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

Date: 12 Apr 2005 13:01:17 -0700
From: JavaDude_MSN233@yahoo.com
Subject: =?iso-8859-1?B?QVdFU09NRSBNT1ZJRSEgPDwgVGhpcyBmcmVlIG1vdmllIGlzIGFib3V0IHJlYWwgc2l0dWF0aW9ucyBhbmQgSSBnaXZlIGl0IGEgYmlnIHRodW1icy11cCEhILC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty5fLl8ut7qwYLC6ty4xMS63urBgsLq3Ll8uXy63urBgsLq3Ll8uXy63urBgsLq3Ll8uXy63?=
Message-Id: <1113336077.621577.14040@o13g2000cwo.googlegroups.com>

http://www.moviefever.com/movie121 << Awesome Movie!
You can reply with your comments
about the movie if you would like.



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

Date: Tue, 12 Apr 2005 20:52:41 +0000
From: "Peter A. Krupa" <pkrupa@redwood.rsc.raytheon.com>
Subject: Access... granted!
Message-Id: <tyW6e.4$N16.0@dfw-service2.ext.ray.com>

use Win32::ODBC;

## $db = new Win32::ODBC ( "DRIVER=Microsoft Access Driver 
(*.mdb);SystemDB=somedatabase.mdw;DBQ=somedatabase.mdb;UID=someusername;PWD=somepassword" 
) or die ( $! );  // all arguments

$db = new Win32::ODBC ( "DRIVER=Microsoft Access Driver 
(*.mdb);DBQ=c:\\Program Files\\Microsoft 
Office\\Office\\Samples\\Northwind.mdb" ) or die ( $! );

$sql = 'SELECT DISTINCTROW TOP 10 Products.ProductName AS 
TenMostExpensiveProducts, Products.UnitPrice FROM Products ORDER BY 
Products.UnitPrice DESC;';

die $db->Error ( ) if $db->Sql ( $sql );

while ( $db->FetchRow ( ) )
{
  print ( join ( "\t", $db->Data ( ) ), "\n" );
}

$db->Close ( );


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

Date: 12 Apr 2005 13:48:48 -0700
From: c_campise@hotmail.com
Subject: Assistance with threading ...thread not returning
Message-Id: <1113338928.811034.231500@l41g2000cwc.googlegroups.com>

Hello all-

I have a 'simple' application that creates a thread that calls an
external Windows program that runs for about 5 minutes or so.  The
problem is the routine that creates this thread is never returned
control after the join() has been called when the thread terminates.

Sample Code :

use threads;
$|++; # autoflush enabled

print "Calling GenerateThread()\n";
GenerateThread();
print "Exited GenerateThread()\n";
exit(1)


sub GenerateThread()
{
    my $thread1  = threads->create(\&ExecuteThread);
    my $val1 = $thread1->join;
    print "DONE with ExecuteThread()\n";
}

sub ExecuteThread()
{
    # sit and wait for command to finish....
    $szResult = `MyWindowsCommandLineProgram`;

    print "MyWindowsCommandLineProgram has COMPLETED\n";
}


----- actual program output ---------

Calling GenerateThread()
MyWindowsCommandLineProgram has COMPLETED
DONE with ExecuteThread()

------end actual output -------------

What I never see is control returned to where GenerateThread() was
called.  I expected to see :

----- expected program output ---------

Calling GenerateThread()
MyWindowsCommandLineProgram has COMPLETED
DONE with ExecuteThread()
Exited GenerateThread()               <<--- ????

-------end expected ouput -------------

Any ideas what I'm doing wrong?

Thanks in advance!

Chris



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

Date: Tue, 12 Apr 2005 21:09:14 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Assistance with threading ...thread not returning
Message-Id: <Xns9636AE6B1799Casu1cornelledu@127.0.0.1>

c_campise@hotmail.com wrote in news:1113338928.811034.231500
@l41g2000cwc.googlegroups.com:

> I have a 'simple' application that creates a thread that calls an
> external Windows program that runs for about 5 minutes or so.  The
> problem is the routine that creates this thread is never returned
> control after the join() has been called when the thread terminates.
> 
> Sample Code :

use strict;
use warnings;

missing. Please do read the posting guidelines for this group. They 
contain valuable information on how to help others help you.
 
> use threads;
> $|++; # autoflush enabled

This is better written as 

$| = 1;

> print "Calling GenerateThread()\n";
> GenerateThread();
> print "Exited GenerateThread()\n";
> exit(1)

Please post real code. This code contains a syntax error, which means 
this is not the code that you ran.

> sub GenerateThread()

Why the empty prototype?

> {
>     my $thread1  = threads->create(\&ExecuteThread);
>     my $val1 = $thread1->join;
>     print "DONE with ExecuteThread()\n";
> }
> 
> sub ExecuteThread()

Why the empty prototype?

> {
>     # sit and wait for command to finish....
>     $szResult = `MyWindowsCommandLineProgram`;

Hungarian notation. Yuck!

>     print "MyWindowsCommandLineProgram has COMPLETED\n";
> }

> Any ideas what I'm doing wrong?

You have not read the posting guidelines.

You did not put together a short script that still exhibits the problem.

After fixing the errors that would have been obvious had you actually 
run this script before posting, here is what we have (on Windows XPP-
SP2, ActiveState Perl):
use strict;
use warnings;

use threads;
$| = 1;

print "Calling GenerateThread()\n";
GenerateThread();
print "Exited GenerateThread()\n";
exit 1;

sub GenerateThread {
    my $thread1  = threads->create(\&ExecuteThread);
    my $val1 = $thread1->join;
    print "DONE with ExecuteThread()\n";
}

sub ExecuteThread {
    my $output = `ls`;
    print "MyWindowsCommandLineProgram has COMPLETED\n";
}

__END__

D:\Home\asu1\UseNet\clpmisc> t
Calling GenerateThread()
MyWindowsCommandLineProgram has COMPLETED
DONE with ExecuteThread()
Exited GenerateThread()

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Tue, 12 Apr 2005 15:57:30 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Beginner Question #1
Message-Id: <slrnd5odhq.1vh.tadmc@magna.augustmail.com>

soup_or_power@yahoo.com <soup_or_power@yahoo.com> wrote:

> Subject: Beginner Question #1


Please put the subject of your article in the Subject of your article!


>   my $par1


Syntax error.

Code does not run, so on to helping the next person with 
a question instead, good luck.


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


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

Date: 12 Apr 2005 11:27:08 -0700
From: "Stryder" <stryder22204@gmail.com>
Subject: Re: Client socket programming eating up CPU/memory
Message-Id: <1113330428.064701.282200@f14g2000cwb.googlegroups.com>

Problem solved.  Read on if you're interested.

Thanks for the replys.

As I said in the original post, I tried creating sockets in a loop with
several sets of example code cut and pasted from perlipc, the Camel
book and other places, altered slightly to loop through my data.  I
also tried it on Solaris and Linux and against several different
servers.  The bottom line is it shouldn't have been happening.

I found another posting complaining about the same thing.  He said he
upgraded from Perl 5.8.0 to 5.8.2 and the problem went away.  So I
upgraded from 5.8.0 to 5.8.6 on Solaris and ran the exact same code,
and sure enough the problem went away.



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

Date: Wed, 13 Apr 2005 00:53:13 +0300
From: Nikos <hackeras@gmail.com>
Subject: Creating o non-existing database
Message-Id: <d3hg0g$ojj$1@nic.grnet.gr>

This is soem per of my make.pl
Its supposed to create first time the database nikos_db or if its 
already there to just delete it and recreate it.

$db = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net')
     ? DBI->connect('DBI:mysql:nikos_db', 'root', '')
     : DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db', '*****')
     or print font({-size=>5, -color=>'Lime'}, $DBI::errstr) and exit 0;

$db->do( "drop database if exists nikos_db" );
$db->do( "create database nikos_db" );
$db->do( "use nikos_db" );

If the database alrady exists no problem but if it want to be creates at 
the time then the first db gives an error when i run make.pl and i must 
then manually create it through mysql statemets in console.

What can i do so that Perl create the database nikos_db if it never benn 
created?


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

Date: Tue, 12 Apr 2005 13:19:29 -0500
From: Peter Ensch <nobody@bogus.com>
Subject: File::Find - following s'linked directories?
Message-Id: <d3h3fh$ngd$1@home.itg.ti.com>

It's been a while since I used File::Find and I was under the impression 
that it now supported traversal of symbolically linked directories; the
POD indicates that this is the case in the following warning:

"Be aware that the option to follow symbolic links can be dangerous.
Depending on the structure of the directory tree (including symbolic links
to directories) you..."

I cannot seem to make F::F follow links to directories however. Using 
find2perl to generate an example script from this find command:

find2perl /an/example/dir/tree -follow -print

I get this (comments, shebang Etc. removed):

###########
use File::Find ();

use vars qw/*name *dir *prune/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

sub wanted;

File::Find::find( {wanted => \&wanted, follow => 1},
'/an/example/dir/tree');
exit;

sub wanted {
    print("$name\n");
}
###########

Why doesn't this follow symbolically linked directories like the 
unix find command used to create it does?

Thanks,
Peter


-- 

^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
Peter Ensch,
pensch@ti.com           A-1140   (214) 480 2333
^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^


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

Date: 12 Apr 2005 19:25:50 GMT
From: DAVISM@ecr6.ohio-state.edu (Michael T. Davis)
Subject: Matching mixed up words
Message-Id: <d3h7bu$hbt$1@charm.magnus.acs.ohio-state.edu>

	Say I want to match "gremlin" or the letters that compose the word
"gremlin", but in any order.  Note that once "g" is consumed, the set of
available letters no longer includes "g".  (Also, "g" isn't necessarily
going to be the first letter.)  I would anticipate that a proper solution
for a word of <N> letters would approach a complexity (or "big O") of N!
(read "N factorial").  Is there a solution which could be implemented as
a single match, or would this require some extra code around a match?

Thanks,
Mike
--
                                         |    Systems Specialist: CBE,MSE
             Michael T. Davis            | Departmental Networking/Computing
 http://www.ecr6.ohio-state.edu/~davism/ |     The Ohio State University
                                         |     197 Watts, (614) 292-6928


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

Date: Tue, 12 Apr 2005 19:57:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Matching mixed up words
Message-Id: <Xns9636A23BF502Dasu1cornelledu@127.0.0.1>

DAVISM@ecr6.ohio-state.edu (Michael T. Davis) wrote in
news:d3h7bu$hbt$1@charm.magnus.acs.ohio-state.edu: 

> Say I want to match "gremlin" or the letters that compose the
>  word "gremlin", but in any order.  Note that once "g" is consumed, 
> the set of available letters no longer includes "g".  (Also, "g" isn't
> necessarily going to be the first letter.)  I would anticipate that a
> proper solution for a word of <N> letters would approach a complexity
> (or "big O") of N! (read "N factorial").  

You are too pessimistic :)

> Is there a solution which could be implemented as a single match, 
> or would this require some extra code around a match?

I don't see any mention of regexes in your post. I am not sure if that 
is what you are after. There is a simple solution to this that falls 
directly from your explanation of the problem:

use strict;
use warnings;

use Data::Dumper;

sub check {
    my ($orig, $target) = @_;
    
    my %c;
    
    use integer;
    my @l = split //, $orig;
    ++$c{$_} for @l;

    @l = split //, $target;
    for (@l) {
        if(exists($c{$_}) and $c{$_}) {
            --$c{$_};
        }
    }

    @l = grep { $_ > 0 } values %c;
    scalar @l ? 0 : 1;
}

my %check = (
    sinan   => [ 'nasin', 'nasina', 'lasin' ],
    gremlin => [ 'mergnil', 'mgrelanl', 'gremlin' ],
);

for my $k (keys %check) {
    for my $t (@{ $check{$k} }) {
        print "$k matches $t?: ";
        if(check($k, $t)) {
            print "Yes\n";
        } else {
            print "No\n";
        }
    }
}


__END__


I am sure someone will show a regex solution that I have overlooked.

By the way, your signature is not formatted properly:
 
> --

The proper signature marker is two dashes followed by a space and a 
newline. Please do use that.

Sinan


-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Tue, 12 Apr 2005 16:37:17 -0400
From: thundergnat <thundergnat@hotmail.com>
Subject: Re: Matching mixed up words
Message-Id: <R4KdnXOcsurkrMHfRVn-qA@rcn.net>

Michael T. Davis wrote:
> 	Say I want to match "gremlin" or the letters that compose the word
> "gremlin", but in any order.  Note that once "g" is consumed, the set of
> available letters no longer includes "g".  (Also, "g" isn't necessarily
> going to be the first letter.)  I would anticipate that a proper solution
> for a word of <N> letters would approach a complexity (or "big O") of N!
> (read "N factorial").  Is there a solution which could be implemented as
> a single match, or would this require some extra code around a match?
> 

I'm sure it could be done more efficiently but it was an interesting
little diversion. I wandered a little from the OPs spec since I am
ignoring spaces, punctuation and case, I guess.


use warnings;
use strict;

my $phrase = 'George W. Bush';

my %letters;

for (split//, $phrase){
    $letters{lc($_)}++ if /[a-zA-Z]/;
}

while (<DATA>){
    chomp (my $test_phrase = $_);
    my $no_match;
    my %testhash = %letters;
    for (split//, $test_phrase){
         if (/[a-zA-Z]/){
            if (--$testhash{lc($_)} < 0){
                $no_match++;
                last;
            }
         }
    }
    for (values %testhash){
    	last if $no_match;
        if ($_ < 0){
            $no_match++;
        }
    }
    print "Phrase \"$test_phrase\" ".($no_match ?
    'does not match' : 'matches')." $phrase.\n";
}

__DATA__
NOT A MATCH
SHRUB EGG WOE
BUG GORE HEWS
GOB SEWER HUG
WEB USER GOGH
RUBES EGG WHO
BUG GREW HOSE
WHOSE BUGGER
BEG WORSE UGH
A BOGUS ENTRY


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

Date: 12 Apr 2005 21:07:28 GMT
From: xhoster@gmail.com
Subject: Re: Matching mixed up words
Message-Id: <20050412170728.908$gZ@newsreader.com>

DAVISM@ecr6.ohio-state.edu (Michael T. Davis) wrote:
>         Say I want to match "gremlin" or the letters that compose the
> word "gremlin", but in any order.  Note that once "g" is consumed, the
> set of available letters no longer includes "g".  (Also, "g" isn't
> necessarily going to be the first letter.)  I would anticipate that a
> proper solution for a word of <N> letters would approach a complexity (or
> "big O") of N! (read "N factorial").  Is there a solution which could be
> implemented as a single match, or would this require some extra code
> around a match?

canon("gremlin") eq canon($foo) or die;

sub canon {
  join "", sort split //, $_[0];
};

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 12 Apr 2005 21:11:18 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Matching mixed up words
Message-Id: <Xns9636AEC4FA559asu1cornelledu@127.0.0.1>

xhoster@gmail.com wrote in news:20050412170728.908$gZ@newsreader.com:

> DAVISM@ecr6.ohio-state.edu (Michael T. Davis) wrote:
>>         Say I want to match "gremlin" or the letters that compose the
>> word "gremlin", but in any order match?

 ...

> canon("gremlin") eq canon($foo) or die;
> 
> sub canon {
>   join "", sort split //, $_[0];
> };

That's what I call the power of a clear mind :)

Simple and elegant.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Wed, 13 Apr 2005 00:04:30 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Matching mixed up words
Message-Id: <slrnd5ohfe.178.tassilo.von.parseval@localhost.localdomain>

Also sprach A. Sinan Unur:

> DAVISM@ecr6.ohio-state.edu (Michael T. Davis) wrote in
> news:d3h7bu$hbt$1@charm.magnus.acs.ohio-state.edu: 
>
>> Say I want to match "gremlin" or the letters that compose the
>>  word "gremlin", but in any order.  Note that once "g" is consumed, 
>> the set of available letters no longer includes "g".  (Also, "g" isn't
>> necessarily going to be the first letter.)  I would anticipate that a
>> proper solution for a word of <N> letters would approach a complexity
>> (or "big O") of N! (read "N factorial").  
>
> You are too pessimistic :)
>
>> Is there a solution which could be implemented as a single match, 
>> or would this require some extra code around a match?
>
> I don't see any mention of regexes in your post. I am not sure if that 
> is what you are after. There is a simple solution to this that falls 
> directly from your explanation of the problem:
>
> use strict;
> use warnings;
>
> use Data::Dumper;
>
> sub check {
>     my ($orig, $target) = @_;
>     
>     my %c;
>     
>     use integer;
>     my @l = split //, $orig;
>     ++$c{$_} for @l;
>
>     @l = split //, $target;
>     for (@l) {
>         if(exists($c{$_}) and $c{$_}) {
>             --$c{$_};
>         }
>     }
>
>     @l = grep { $_ > 0 } values %c;
>     scalar @l ? 0 : 1;
> }
>
> my %check = (
>     sinan   => [ 'nasin', 'nasina', 'lasin' ],
>     gremlin => [ 'mergnil', 'mgrelanl', 'gremlin' ],
> );
>
> for my $k (keys %check) {
>     for my $t (@{ $check{$k} }) {
>         print "$k matches $t?: ";
>         if(check($k, $t)) {
>             print "Yes\n";
>         } else {
>             print "No\n";
>         }
>     }
> }

A faster solution appears to involve sort(): split both strings, sort
them and compare for equality. According to a benchmark:

    use strict;
    use Benchmark qw/cmpthese/;

    sub check {
	my ($orig, $target) = @_;
	my %c;
	use integer;
	my @l = split //, $orig;
	++$c{$_} for @l;
	@l = split //, $target;
	for (@l) {
	    if(exists($c{$_}) and $c{$_}) {
		--$c{$_};
	    }
	}
	@l = grep { $_ > 0 } values %c;
	scalar @l ? 0 : 1;
    }

    sub check_sort {
	my ($orig, $target) = @_;
	my $o = join '', sort split //, $orig;
	my $t = join '', sort split //, $target;
	return $o eq $t;
    }

    my %check = (
	sinan   => [ 'nasin', 'nasina', 'lasin', ],
	gremlin => [ 'mergnil', 'mgrelanl', 'gremlin' ],
    );

    cmpthese(-2, {
	histo => sub {
	    for my $k (keys %check) {
		for my $t (@{ $check{$k} }) {
		    check($k, $t);
		}
	    }
	},
	sort => sub {
	    for my $k (keys %check) {
		for my $t (@{ $check{$k} }) {
		    check_sort($k, $t);
		}
	    }
	},
    });
    __END__
	    Rate histo  sort
    histo 2280/s    --  -43%
    sort  3992/s   75%    --

This might however be due to a denser implementation of check_sort()
avoiding temporary variables etc.

Also, check_sort() is more correct as it wont falsely report 'sinan' and
'nasina' as matching, which check() does. ;-) I'd write check() thusly:

    sub check {
	my ($orig, $target) = @_;
	my %c;
	++$c{$_} for split //, $orig;
	--$c{$_} for split //, $target;
	return ! grep $_, values %c;
    }

This is still slower by roughly 25% than using sort. The 'use integer'
appears to have no effect on the benchmark.
    
Tassilo
-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);


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

Date: Wed, 13 Apr 2005 00:23:25 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Simple Encryption Script
Message-Id: <d3he8m$nbk$1@nic.grnet.gr>

RedGrittyBrick wrote:

[snip]

Thank you very much!
Now its perfectly clear!


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

Date: Tue, 12 Apr 2005 14:14:16 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Troubleshooting printing to file
Message-Id: <nKSdnf1on5ZnksHfRVn-sg@comcast.com>

EmmettPower@gmail.com wrote:

> Hi,
> 
> I have a problem with what should be a simple issue. I am testing a
> number of files in a directory for a pattern using a regular
> expression. The successful matches are printed to the screen a file
> (Output.txt). I've set out the code below. The pattern matches across
> lines, hence the use of File::Slurp.
> 
> I'm using Perl on a Windows platform. The script works fine when I test
> it on one computer but when I migrate it across to the computer holding
> the files is fails to print the results to the Output file. It prints
> to screen fine. Both computers are using the same version of Windows
> and Perl.
> 
> It should be simple but I can't figure out what's wrong.
> 
> Any suggestions would be appreciated.
> 
> Regards
> 
> Emmett Power
> 
> 
> <--------------------------CODE-------------------------------->
> 
> use File::Slurp;
> 
Where's your

use strict;
use warnings;

?

> my $file;
> my $name;
> 
> my $FILELIST = "FileList.txt";
> open(LIST, "$FILELIST");
> 
> open (OUT,'>Output.txt');

Most likely, opening Output.txt failed.  Why?  No way to know,
because you didn't check.  Always, *always* check to make sure
open succeeds.

open(OUT, '>Output.txt') 
  or die("Opening Output.txt failed: $!, stopped");

You should also check your opening of the input file.  Checking
the close calls is a bit paranoid, but paranoia can be a good
habit for a programmer to get into.
> 
> while(<LIST>)
>     {
> chomp;
> $name = $_;
> $file = read_file($name);
> 
> while ($file =~ /test/gi){
> 
>  print "$&,$_\n";
>  print OUT "$&,$_\n";
> 
> }
> 
> }
> 
> close(OUT);
> close(LIST);

-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: Wed, 13 Apr 2005 01:00:57 +0300
From: Nikos <hackeras@gmail.com>
Subject: Web Interface and index.pl separated?!?
Message-Id: <d3hgf1$p2u$1@nic.grnet.gr>

Inside my webpage index.pl i ahve the Perl code and the interface of the 
page: Do you think that i must separate the page's interface in a file 
by itself and then in another index.pl make calculations and stuff with it:

i have i as follows to generate graphics. here is a asmall part:

print start_form(-action=>"show.pl");
print table( {-border=>1, -width=>"60%", -align=>"center", 
-style=>"border: ridge magenta; color: lime; font-family: Times; 
font-size: 18", -background=>"../data/images/swirl.jpg"},
       Tr( {-align=>'center'}, td( "Πώς σε λένε αδελφέ?" ), 
          td( textfield( 'onoma' ))),
       Tr( {-align=>'center'}, td( "Ποιά είναι η γνώμη σου για την ευχούλα
                                    \"Κύριε Ιησού Χριστέ Ελέησον Με\"?" 
),       td( textarea( -name=>'sxolio', -rows=>5, -columns=>30 ))),
       Tr( {-align=>'center'}, td( "Μοιράσου μαζί μας μία κατά τη γνώμη σου
                                    θαυμαστή προσωπική σου πνευματική 
εμπειρία
                                    από κάποιον γέροντα προς ώφελος των
                                    υπολοίπων αδελφών (αν φυσικά έχεις 
:-)" ),   td( textarea( -name=>'symvan', -rows=>7, -columns=>30 ))),
       Tr( {-align=>'center'}, td( "Ποιό είναι το e-mail σου?" ), 
          td( textfield( 'email' ))),
       Tr( {-align=>'center'}, td( submit( 'Εμφάνιση όλων των απόψεων' 
)),       td( submit( 'Αποστολή' ))));
print end_form(), br(), br();

also inside index.pl a have javascript embedded in a here document.

Is this wrong approach?

For example how could i rewrite the above script?
The funny stuff is actually Greek! :-)


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

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 7969
***************************************


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