[24002] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6201 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 2 00:05:39 2004

Date: Mon, 1 Mar 2004 21:05:06 -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           Mon, 1 Mar 2004     Volume: 10 Number: 6201

Today's topics:
    Re: (newbie) How do I group a string for repetition cou <usenet@morrow.me.uk>
        DBI->connect fails with perl 5.8?   user@domain.invalid
    Re: Efficiency and scoping 'my' variables <mgjv@tradingpost.com.au>
    Re: how die in AUTOLOAD (Anno Siegel)
    Re: how die in AUTOLOAD <nospam-abuse@ilyaz.org>
    Re: how do I choose between an explicit file and standa <lkirsh@cs.ubc.ca>
    Re: Opening a unique dat file for each user <arthur0421@163.com>
    Re: OS Version (James Willmore)
    Re: perl implementation of rand() and srand() <usenet@morrow.me.uk>
    Re: perl implementation of rand() and srand() <mgjv@tradingpost.com.au>
        PLEASE HELP ABOUT HASH! <luke@program.com.tw>
    Re: PLEASE HELP ABOUT HASH! <tim@vegeta.ath.cx>
    Re: PLEASE HELP ABOUT HASH! <jwillmore@remove.adelphia.net>
        Problems with <olczyk2002@yahoo.com>
    Re: Regex comparison <usenet@morrow.me.uk>
    Re: Regex comparison <usenet@morrow.me.uk>
        Regexp: look ahead and match <jimwmct@yahoo.com>
    Re: Regexp: look ahead and match <matthew.garrish@sympatico.ca>
    Re: Regexp: look ahead and match (Jay Tilton)
    Re: Regexp: look ahead and match <matthew.garrish@sympatico.ca>
        Rounding Up/Down Numbers (aleatory)
    Re: Rounding Up/Down Numbers <beable+unsenet@beable.com.invalid>
    Re: Storing numbers in an array from files (aleatory)
    Re: Suggest a suitable image modifying CPAN module <nospam@bigpond.com>
    Re: Suggest a suitable image modifying CPAN module <mgjv@tradingpost.com.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 1 Mar 2004 23:09:16 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: (newbie) How do I group a string for repetition count?  {m,n}
Message-Id: <c20fqs$frg$1@wisteria.csv.warwick.ac.uk>


"gnari" <gnari@simnet.is> wrote:
> "gnari" <gnari@simnet.is> wrote in message
> >
> > or maybe you want to read perldoc perlre
> > in particular the bit about  zero-width positive look-behind assertions.
> > something like / (?<=turkey shoot).*(turkey shoot)/
> 
> ditto here: / (?<=turkey shoot).*?(turkey shoot)/

Except that what you actually mean is

/ (?<= turkey\ shoot .*? ) turkey\ shoot /x

which unfortunately doesn't work, so some other method must be
employed.

Ben

-- 
  The cosmos, at best, is like a rubbish heap scattered at random.
                                                         - Heraclitus
  ben@morrow.me.uk


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

Date: Tue, 02 Mar 2004 10:27:56 +0530
From:  user@domain.invalid
Subject: DBI->connect fails with perl 5.8? 
Message-Id: <%BU0c.36$u61.297@news.oracle.com>

Hi all,

I am using DBI to connect to an Oracle database.

The following is the simple code to test for the connection :

use strict;
use warnings;

use DBI ;
my $dbh;

$dbh = DBI->connect('dbi:Oracle:',"APPS","APPS") or die ("Cannot get 
handle to db");
print $dbh . "\n" ;

I have set all the environment variables (TWO_TASK, TNS_ADMIN, ORACLE_HOME).

The above works fine with perl 5.6.1, but exits with the following on 
perl 5.8 :

sh-2.05$ /local/perl5.8/bin/perl test1.pl
DBI->connect() failed: (UNKNOWN OCI STATUS 1804) OCIInitialize. Check 
ORACLE_HOME and NLS settings etc. at test1.pl line 14
Cannot get handle to db at test1.pl line 14.
sh-2.05$

Please let me know what I am doing wrong ....

Thanks and regards
Abhinav



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

Date: 02 Mar 2004 01:12:53 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Efficiency and scoping 'my' variables
Message-Id: <slrnc47nsk.8k7.mgjv@verbruggen.comdyn.com.au>

On Mon, 01 Mar 2004 22:33:41 +0000,
	david scholefield <david@emology.com> wrote:
> On 1/3/04 10:23 pm, in article c20d4k$es7$1@mamenchi.zrz.TU-Berlin.DE, "Anno
> Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote:
> 
>> In deciding the scope of a variable, efficiency stays out of the
>> consideration.  The rule is to put the variable in the smallest
>> possible scope.
>> 
> Good advice, generally...

Indeed.

>> Both space and time aren't issues here.  You start thinking about
>> efficiency when your program is too slow.  In that case, shuffling
>> loop variables around won't bring the breakthrough you need.
>> 
> 
> that's what I was asking... thanks for the answer... I guess that
> variable declaration isn't a time-intensive activity at run-time

There's a slight overhead, but it's something in the order of 10%.
Something like that, as Anno already said, won't generally give you
the savings you need when you think your program is too slow.

90% of slowness problems in code, irrespective of the language, can
really only be solved by changing the algorithm. The other 10% can
most often be fixed most easily by throwing more hardware at it. There
is a fraction that can be made to go faster by fiddling with the scope
of variables [1].

Martien

[1] some fiddles with the scope of variables should properly be seen
as algorithmic changes. For example, changing an OO program to not
instantiate an object in a tight loop, but instead to re-use an object
created outside of the loop, or to use a singleton, is not just a
scope change, even though it can often result in dramatic speed
differences.
-- 
                        | 
Martien Verbruggen      | In the fight between you and the world, back
Trading Post Australia  | the world - Franz Kafka
                        | 


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

Date: 1 Mar 2004 23:31:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how die in AUTOLOAD
Message-Id: <c20h51$hgk$1@mamenchi.zrz.TU-Berlin.DE>

Yuri Shtil  <yshtil@cisco.com> wrote in comp.lang.perl.misc:

> Ilya Zacharevitch suggested setting $DB:debugLevel to 5 which made the 
> die message magically appear. Obviously there was a way to provide help 
> without insulting.

I have no idea how Ilya divined a partial solution from what you
posted, but then, he's Ilya.

> I did not mean to appear obtuse or inflammatory but it ticks me when 
> people tell me to shut up without a reason other that I posted 
> incomplete code.

The code wasn't only incomplete, it was written so that it couldn't
show the problem, and when extended so that it could, it didn't show
the problem.  Nor did you *say* it was incomplete, you appeared to
refuse to add any useful information.  At that point I felt justified
to ask you to do so, *or* shut up.  It wasn't my intention to insult
you.

Anno


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

Date: Tue, 2 Mar 2004 04:27:40 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: how die in AUTOLOAD
Message-Id: <c212fs$q0f$1@agate.berkeley.edu>

[Please mark your Cc's as such; otherwise there is no way to
distinguish a Cc of a posting from a private mail.  Thanks.]

[A complimentary Cc of this posting was sent to
Yuri Shtil 
<yshtil@cisco.com>], who wrote in article <4043B0FB.20005@cisco.com>:
> > What happens with setting dieLevel=5 in debugger?  Giving `t'race
> > command may give more hints too.

> The die message appeared when I set dieLevel=5.

This means that your die() is executed inside `eval' (which was the
obvious guess from the start).  Set a breakpoint on the line of your
die(), and give 'T'raceback command to see the details.

Hope this helps,
Ilya


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

Date: Mon, 01 Mar 2004 16:47:27 -0800
From: Lowell Kirsh <lkirsh@cs.ubc.ca>
Subject: Re: how do I choose between an explicit file and standard input
Message-Id: <c20liv$pdv$1@mughi.cs.ubc.ca>

thanks.

Anno Siegel wrote:
> Lowell Kirsh  <lkirsh@cs.ubc.ca> wrote in comp.lang.perl.misc:
> 
>>I want to write a script that will take an optional filename as a 
>>command line argument and will use stdin if no parameter is supplied. 
>>What the script does is count the number of unique lines in a file. For 
>>example I want 'theScript foo' to act like:
>>
>>system "uniq < foo | wc -l"
>>
>>but if no parameter is supplied it should act like:
>>
>>system "uniq < {standard input} | wc -l"
>>
>>Does this make sense?
> 
> 
> It makes so much sense that Perl makes this the default behavior of
> the input operator "<>" if no file handle is given.  It even allows you
> to specify more than one file on the command line, which are read one
> after the other.  If none is given, it reads from STDIN.
> 
> So your program could be written like this:
> 
>     my %h;
>     @h{ <> } = ();
>     print scalar keys %h, "\n";
> 
> Anno



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

Date: Tue, 02 Mar 2004 11:14:01 +0800
From: Regent <arthur0421@163.com>
Subject: Re: Opening a unique dat file for each user
Message-Id: <c20u7m$gra$1@mail.cn99.com>

Greg Klinedinst wrote:
> On Tue, 02 Mar 2004 00:33:49 +0800, Regent <arthur0421@163.com> wrote:
> 
> 
> 
>>Thanks really. In fact before being used as part of the filename, $uid 
>>is validated beforehand. So
>>
>>        $uid = $1 if $uid =~ /(.*)/;
>>
>>should be no problem. I tried this, and the script seems sound and safe. 
>>But is there any other potential danger in doing this? I see none at the 
>>moment now.
>>
>>Regent
> 
> 
> 
> I am not sure if you mean that you were validating $uid earlier in
> your Perl program or by some external means before it gets submitted
> such as with Javascript running client-side. I just wanted to point
> out that you should never trust data coming from the client, even if
> you check it with JS or something.
> 
> Anyone familiar with web programming at all could read the source of
> your front end(the HTML) and make their own version which sends back
> whatever they want, and call it uid(which you are trusting). There are
> even programs out there you can download which will automate this
> process of hacking web forms. I have even gone to a conference where
> they discussed how to hack web forms in detail. 
> 
> As I said, it wasn't clear to me if you were validating that variable
> in your Perl code or checking it before your Perl gets it but if it is
> the latter you should check it thoroughly in your Perl anyway.
> 
> -Greg
> 

I mean this: in the same script, $uid firstly goes through -T check, and 
then compared with the array of authenticated user names in a database. 
After all these have been done, what are other problems may the script have?

Cheers,
Regent


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

Date: 1 Mar 2004 15:58:36 -0800
From: jwillmore@myrealbox.com (James Willmore)
Subject: Re: OS Version
Message-Id: <d61170e5.0403011558.6657caf4@posting.google.com>

[a private response was sent - which you neglected to note here]
[don't top post - it's rude]
[reformated message follows]

Mark J Fenbers <Mark.Fenbers@noaa.gov> wrote in message news:<40436F5F.7D9FCB93@noaa.gov>...
> James Willmore wrote:
> 
> > On Mon, 01 Mar 2004 10:04:30 -0500, Mark J Fenbers wrote:
> >
> > > $^O gives the O/S name, in my case : 'linux', but I want to run my Perl script
> > > on RH 7.X and RH 9.x of Linux.  How can my script determine which version of the
> > > O/S it is running on?
> >
> > Why should your script care about the distro of Linux?
> >
> > More importantly, why are you coding to a certain distro of Linux?
> > That a little like making tall kitchen garbage bags to fit only a certain
> > vendor's tall kitchen garbage can :-)


> Well, because I have  third-party software that I call from my script and that
> software has to be called with different environmental settings on RH 9 than it does
> for RH 7.

Keep your eye on the prize - the environment variables, not the OS. 
If you code based upon the various distros of Linux, be prepared to
include some 50+ tests (one for each version of Red Hat, plus other
Linux distros).  Red Hat is not the only distro out there (I use SuSE
and have tried others, including Red Hat).

My guess is you're looking for, maybe, a language setting?  Or a
locale setting?  If so, test for the settings, not the distro.

Just a side note - what happens when you get people like me who
*change* the environment settings for one reason or another.  What
happens then?  From your logic, if I use RH7, and the script sets up
"stuff" based upon the OS, your script *may* fail because I changed an
environment setting you're depending upon being set properly (because
it's that way for RH7 out of the box).

Give some thought to the above statements.  Maybe this is all moot.  I
just would *not* test based upon a Linux distro.  Too many things can
go South real quick.

HTH

Jim
(jwillmore _at_ adelphia _dot_ net)


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

Date: Tue, 2 Mar 2004 00:04:07 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: perl implementation of rand() and srand()
Message-Id: <c20j1n$hu2$3@wisteria.csv.warwick.ac.uk>


Simon <simschla@freesurf.ch> wrote:
> On Mon, 1 Mar 2004 16:58:16 -0500, Paul Lalli wrote:
> > The right direction for the source code to perl?  Here:
> > http://www.cpan.org/src/
> 
> i've managed to find that link, too, but wasn't able to find anything about
> the implementation of srand() or rand() inside it. if it's in there, can
> someone tell me where to look for it?

In pp.c, the functions PP(pp_rand) and PP(pp_srand). Basically, they
just call whatever C-library implementation Configure found: I would
have thought that the usual Java random number function would do just
fine.

Ben

-- 
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk


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

Date: 02 Mar 2004 01:23:29 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: perl implementation of rand() and srand()
Message-Id: <slrnc47ogg.8k7.mgjv@verbruggen.comdyn.com.au>

On Mon, 1 Mar 2004 22:46:55 +0100,
	Simon <simschla@freesurf.ch> wrote:
> 
> I'm trying to implement a Java-version of the perl-based "razor"-client.

[snip]

> The client is able to choose random positions in a e-mail-message and
> computes these parts of the message to build an identifier (hash).
> 
> The positions are chosen according to the following system:
> 
> srand(<server specified seed-number>);
> 
> rand(<length of message>); several times to chose portions of the text.
> 
> all clients and all servers have to use the same positions in order to
> generate a comparable identifier for the message.

Perl's rand() just calls whatever rand() function the system it runs
on provides, and those are notoriously non-identical. In later
versions of Perl, the person compiling Perl can actually override what
pseudo-random generator they want to use.

In other words, rand() in Perl is not guaranteed to produce the same
results at all times.

Are you sure you interpreted the razor code correctly? I couldn't
actually find a document that describes the server-client exchange.

Martien
-- 
                        | 
Martien Verbruggen      | Useful Statistic: 75% of the people make up
Trading Post Australia  | 3/4 of the population.
                        | 


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

Date: Tue, 2 Mar 2004 10:57:54 +0800
From: "news.hinet.net" <luke@program.com.tw>
Subject: PLEASE HELP ABOUT HASH!
Message-Id: <c20t4k$9qg@netnews.hinet.net>

I have the vast data in mysql about (1.5G)
I got some data from machine and want to search some field
that does not exist in mysql. i just want to insert these data that
does not exist in mysql before.

I use hash to handle these data.

First i load data into hash from mysql and search  data if it is exist.
but i use the vast memory at the same time

how to solve this program??

if i insert all data by setup db field data is unique. this will spend a lot
of time.


give me some suggest!!
ps:the data is more than 500M one time insert process





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

Date: 2 Mar 2004 03:17:16 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: PLEASE HELP ABOUT HASH!
Message-Id: <slrnc47v5a.6ig.tim@vegeta.saiyix>

news.hinet.net <luke@program.com.tw> wrote:
>  I have the vast data in mysql about (1.5G) I got some data from
>  machine and want to search some field that does not exist in mysql.
>  i just want to insert these data that does not exist in mysql before.
>  
>  I use hash to handle these data.
>  
>  First i load data into hash from mysql and search  data if it is
>  exist.  but i use the vast memory at the same time
>  
>  how to solve this program??
>  
>  if i insert all data by setup db field data is unique. this will
>  spend a lot of time.
>  
>  give me some suggest!!
>  ps:the data is more than 500M one time insert process

Suggestion:

    Repost using both upper AND lower-case letters in the subject line.
    Many knowledgeable clpm posters will automatically delete any posts
    which contain only UPPER CASE LETTERS in the subject line.
    
    There are (at least) two reasons for this:

      - spam often uses ALL CAPS FOR SUBJECTS
      - it's rude, like yelling; and all the "PLEASE"es in the world
        won't pull your post out of someone's bitbucket

The body of your post was almost entirely lower-case, so we know it's
not because your CAPS LOCK KEY WAS STUCK, so please: help us help you.

HTH,
Tim Hammerquist


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

Date: Mon, 01 Mar 2004 23:36:39 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: PLEASE HELP ABOUT HASH!
Message-Id: <pan.2004.03.02.04.36.34.153267@remove.adelphia.net>

On Tue, 02 Mar 2004 10:57:54 +0800, news.hinet.net wrote:

> I have the vast data in mysql about (1.5G)
> I got some data from machine and want to search some field
> that does not exist in mysql. i just want to insert these data that
> does not exist in mysql before.
> 
> I use hash to handle these data.
> 
> First i load data into hash from mysql and search  data if it is exist.
> but i use the vast memory at the same time
> 
> how to solve this program??
> 
> if i insert all data by setup db field data is unique. this will spend a lot
> of time.
> 
> 
> give me some suggest!!
> ps:the data is more than 500M one time insert process

This is all very interesting, but where's the code you use at present?  
That *may* shed some light on this most wonderful issue.

Right now, the only thing I could suggest is write to a file instead of a
hash and then parse the file - one line at a time.  

OTOH, maybe you need to use SQL more efficently.

Don't know without the code.

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Pascal, n.:  A programming language named after a man who would
<turn over in his grave if he knew about it. 



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

Date: Mon, 01 Mar 2004 20:59:02 -0600
From: TLOlczyk <olczyk2002@yahoo.com>
Subject: Problems with
Message-Id: <j3u740d97ipptaamg92bpsv0p5f4n5o082@4ax.com>

Activestate Perl v 5.8.0
I was trying to compile a Perl extension and kept getting tons of
errors.

So in debugging i reduced everything to a file of a single line.

#include "win32.h"

I compiled this file with the command line:
>> cl.exe -IE:/Perl/lib/CORE/  test.c
cl.exe version is 12.00.8804 (VC++ 6.0 Sp2 ).
I get a ton of errors, the first of which is:

>>E:/Perl/lib/CORE/win32.h(313) : error C2143: syntax error : missing ')' before '*'

Line 313 of win32.h is
extern int		my_fstat(int fd, Stat_t *sbufptr);

Any ideas.
The reply-to email address is olczyk2002@yahoo.com.
This is an address I ignore.
To reply via email, remove 2002 and change yahoo to
interaccess,

**
Thaddeus L. Olczyk, PhD

There is a difference between
*thinking* you know something,
and *knowing* you know something.


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

Date: Mon, 1 Mar 2004 23:54:24 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Regex comparison
Message-Id: <c20ifg$hu2$1@wisteria.csv.warwick.ac.uk>


Les Peters <lpeters@aol.net> wrote:
> Ben Morrow wrote:
> > Les Peters <lpeters@aol.net> wrote:
> > 
> >>I am trying to properly order a series of regexen so that a general pattern
> >>will not match all the lines of a more specific pattern, as part of a log
> >>monitoring script.
> > 
> > This problem is not well-defined: which is the more specific of these
> > 
> > /[abc]/ and /[cd]/
> 
> Those two patterns would have equal specificity.
> 
> The problem lies with patterns like:
> 
> /abc/ and /abcde/
> 
> if /abc/ is reached first, it will match the lines that /abcde/ would match,
> therefore, /abcde/ should be used first, then /abc/.

I realise this. What you are attempting to do is make the choice of
pattern for a given string independant of the order of patterns in the
file, right? Consider the two patterns I gave you, and the string "c".
It matches both. Which should be chosen in this case?

> Here is an update to the routine (I will be collapsing some of
> this after it works for a significantly complex problem set):
> 
> sub pattern_check {
>     #my ($p1, $p2) = @_;
>     my ($p1) = @_;
> 
> # transform p1 into s1 that matches p1
> 
>     my $s1;
>     $s1 = $p1;
>     $s1 =~ s/^\^//;                       # replace ^

^ does not necessarily have to occur at the beginning of a pattern.
Consider /a|^b/.

>     if ($s1 =~ /\\d{(\d+)}/) {
>        my $patch = "0" x $1;
>        $s1 =~ s/\\d{(\d+)}/$patch/g;
>     }
>     $s1 =~ s/\\d[\+\*]?/0/g;              # replace \d, \d+, \d*

This is wrong. /\d/ is more specific than /\d+/ is more specific than
/\d*/, by any reasonable definition of 'specific'.

>     $s1 =~ s/\\\+/+/g;                    # replace \+
>     $s1 =~ s/\\\$/\$/g;                   # replace \$
>     $s1 =~ s/\\\*/*/g;                    # replace \*
>     $s1 =~ s/\\\././g;                    # replace \.
>     $s1 =~ s/\\</</g;                     # replace \<
>     $s1 =~ s/\\>/>/g;                     # replace \>

These are also wrong: you need to replace all \X with X unless \X is
significant in regexen. Note also that < and > are not special in a
regex[1], so there's no need to write them as \< and \>.

> At the moment, the code is tripping over this pattern:
> /login\[[\d]+\]: failed: ^C on /dev/ttyd\d|login\[[\d]+\]: failed:  on
> /dev/ttyd\d|login\[[\d]+\]: Locked ^C account|login\[[\d]+\]: Locked
> account/
> 
> Specifically, the first caret is giving it fits.

This isn't much of a problem, as this pattern won't match anything at
all: indeed, it isn't even valid Perl. The ^s and /s need escaping.

I think, as I said before, that your problem is either unsolvable or
*extremely* difficult. I would go with a heuristic approach: first,
split your pattern into its top-level alternatives: you will be best off
using Text::Balanced for this. Then split each alternative into atoms,
an atom being

1. a contiguous literal string, such as "login\[" at the start of the
pattern above; or

2. a zero-width metachar, such as ^ or $ or \b; or

3. a repeat, such as +, *, +? or {1,2}; or

4. a bracketed sub-expression.

Now calculate the 'complexity' of each alternative by some set of rules
like:

1. a literal or a zero-width metachar has a complexity of 1.

2. a bracketed sub-expression has the complexity of the pattern inside
it.

3. an atom with a {} or ? repeat count has its complexity doubled; with
+ or +?, trebled; with * or *?, quadrupled. This is obviously entirely
arbitrary, and may well need adjusting; but this order should be
preserved.

The complexity of the pattern as a whole is then the maximum complexity
of its alternatives (or some such: maybe the sum of the complexities
would be better?). Order the patterns by complexity.

This approach fails in many obvious ways, but may provide a reasonable
guess for sensibly written expressions.

Ben

[1] yet... :)

-- 
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk


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

Date: Mon, 1 Mar 2004 23:55:32 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Regex comparison
Message-Id: <c20ihk$hu2$2@wisteria.csv.warwick.ac.uk>


yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote:
> Les Peters (lpeters@aol.net) wrote:
> : Hey:
> 
> :     I am working on a bit of code that will compare two regexen
> : to see if one will match a superset of the other.  Trying to
> : take pattern-1 and transform it into a string, then try to match
> : it against pattern-2 is getting really hard... any better methods?
> 
> You build the directed graph that represents the first regular expression, 
> and then you build the directed graph that represents the second regular 
> expression.
> 
> Then you check if one graph is a subset of the other.
> 
> However, I have no suggestion on the perl code to do this, though it 
> sounds like an interesting problem.

I would start by writing a bit of XS to get at the compiled representation of
the pattern.

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


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

Date: Mon, 1 Mar 2004 15:17:55 -0800
From: "jm" <jimwmct@yahoo.com>
Subject: Regexp: look ahead and match
Message-Id: <4043c48b$0$3095$61fed72c@news.rcn.com>

I was using the following script to find two identical letters in a row,
and now would like to find two letters in a row that are in alphabetic
order,
e.g. ab, or mn, or yz, etc...        Haven't had any luck changing the
script
to do that.  I'm thinking that I should be able to look ahead to the next
letter.
Is there a way to increment a backreference to do that?
Thanks in advance.


use strict:
use warnings;

while (my $str = <> ){
chomp($str);
while($string =~ /([a-z])(?=\1)/cgi) {
   print "Match\n";
   }




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

Date: Mon, 1 Mar 2004 19:17:44 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Regexp: look ahead and match
Message-Id: <BoQ0c.2508$jw2.205364@news20.bellglobal.com>


"jm" <jimwmct@yahoo.com> wrote in message
news:4043c48b$0$3095$61fed72c@news.rcn.com...
> I was using the following script to find two identical letters in a row,
> and now would like to find two letters in a row that are in alphabetic
> order,
> e.g. ab, or mn, or yz, etc...        Haven't had any luck changing the
> script
> to do that.  I'm thinking that I should be able to look ahead to the next
> letter.
> Is there a way to increment a backreference to do that?
> Thanks in advance.
>
>
> use strict:
> use warnings;
>
> while (my $str = <> ){
> chomp($str);
> while($string =~ /([a-z])(?=\1)/cgi) {
>    print "Match\n";
>    }
>

I don't think it can be done from within a regex (at least I can't think of
a way that won't result in an eval error). Something simple like the
following should work, though:

while (my $str = <>) {

   my $lval = 0;

   foreach my $char ($str =~ /(.)/g) {

      my $ordval = ord($char);

      if ($char =~ /[A-Za-z]/) {
         if ($ordval == ($lval + 1)) {
            print chr($lval) . "$char\n";
         }
      }

      $lval = $ordval;

   }

}

Matt




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

Date: Tue, 02 Mar 2004 00:47:32 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Regexp: look ahead and match
Message-Id: <4043d8a1.268392831@news.erols.com>

"jm" <jimwmct@yahoo.com> wrote:

: I was using the following script to find two identical letters in a row,
: and now would like to find two letters in a row that are in alphabetic
: order,
: e.g. ab, or mn, or yz, etc...        Haven't had any luck changing the
: script
: to do that.  I'm thinking that I should be able to look ahead to the next
: letter.
: Is there a way to increment a backreference to do that?

    /([[:alpha:]])(??{ chr(ord($1)+1) })/

That assumes that alphabetical order and character code order are the same
thing, which isn't necessarily true.



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

Date: Mon, 1 Mar 2004 20:09:01 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Regexp: look ahead and match
Message-Id: <G8R0c.6411$qA2.415705@news20.bellglobal.com>


"Jay Tilton" <tiltonj@erols.com> wrote in message
news:4043d8a1.268392831@news.erols.com...
> "jm" <jimwmct@yahoo.com> wrote:
>
> : I was using the following script to find two identical letters in a row,
> : and now would like to find two letters in a row that are in alphabetic
> : order,
> : e.g. ab, or mn, or yz, etc...        Haven't had any luck changing the
> : script
> : to do that.  I'm thinking that I should be able to look ahead to the
next
> : letter.
> : Is there a way to increment a backreference to do that?
>
>     /([[:alpha:]])(??{ chr(ord($1)+1) })/
>

Brain not function good today. I was using (?{ }) and it just wouldn't work.
I should've gone back to perlre...

Is anyone aware of just how "experimental" these extended regexes are? I
know code can always be rewritten, but I don't like the thought of my
scripts breaking just because they're being run under a newer version of
perl (hence I would generally only use something like the above in a
throw-away script).

Matt




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

Date: 1 Mar 2004 19:22:29 -0800
From: aleatory@hotmail.com (aleatory)
Subject: Rounding Up/Down Numbers
Message-Id: <a68a4ee0.0403011922.519ff400@posting.google.com>

Good afternoon perl gurus,

Once again I have a question on perl.

How could I round up/down numbers? For
instance:

     | 2.456   <--original number
     | 3       <--rounding up
     | 2       <--rounding down
     | 2.46    <--rounding up but keeping
     |            the last two digits after
     |            the decimal point

After reading "Beginning Perl" by Simon
Cozens, I just don't find any information
regarding these.

As before any information is appreciated.

Many thanks in advance,

alea


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

Date: Tue, 02 Mar 2004 03:39:33 GMT
From: Beable van Polasm <beable+unsenet@beable.com.invalid>
Subject: Re: Rounding Up/Down Numbers
Message-Id: <6t65dn2a04.fsf@dingo.beable.com>

aleatory@hotmail.com (aleatory) writes:

> Good afternoon perl gurus,
> 
> Once again I have a question on perl.
> 
> How could I round up/down numbers? For

Try reading the FAQ:

    perldoc -q round


-- 
   


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

Date: 1 Mar 2004 17:56:36 -0800
From: aleatory@hotmail.com (aleatory)
Subject: Re: Storing numbers in an array from files
Message-Id: <a68a4ee0.0403011756.5d09d355@posting.google.com>

Hi Gunnar,

Thanks for the tips! In particular your recommendation
on the split function nicely has solved my problem. 
Even though I haven't tried the join function, I'm
quite sure it will work fine just considering your
perfect advice.

Thanks again for helping me out!

alea

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<c1vqhm$1n8oe0$1@ID-184292.news.uni-berlin.de>...
> aleatory wrote:
> > A file, for instance, contains a bunch of numbers:
> > 
> >      | 1218,  8, 29
> >      | 3211,  9, 15
> > 
> > I would like to first read in a line of numbers 
> > and then would like to uniquely store each number 
> > in an array as:
> > 
> >      For 1st loop
> >      | print "$my_array[0]";  <--displays 1218
> >      | print "$my_array[1]";  <--displays 8
> >      | print "$my_array[2]";  <--displays 29
> >     
> >      For 2nd loop
> >      | print "$my_array[0]";  <--displays 3211
> >      | print "$my_array[1]";  <--displays 9
> >      | print "$my_array[2]";  <--displays 15
> > 
> > However, I've been having difficulty uniquely 
> > storing each number in an array. The following
> > is my code:
> > 
> >      | #!/usr/bin/perl
> >      | use strict;
> >      | use warnings;
> >      |
> >      | open IN, 'infile' || die$!;
> >      | 
> >      | my @line;
> >      | my @my_array;
> >      |
> >      | while ( <IN> )
> >      | {
> >      |   @line = $_;       <--@line contains 1218, 8, 29
> >      |   @my_array = @line    How could I store each as:
> >      | }                      $my_array[0] = 1218
> >      |                        $my_array[1] = 8
> >      |                        $my_array[2] = 29
> 
>      perldoc -f split;
> 
> But if you just use @my_array, only the last line will be preserved. 
> You'd better use an array of arrays.
> 
>      perldoc perllol
>      perldoc perlreftut
> 
> > Then after separating each, how could I put
> > them together as a line of numbers separated 
> > by a comma?
> 
>      perldoc -f join
> 
> > I'm quite desperate and any information is
> > highly appreciated.
> 
> Happy reading. :)


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

Date: Tue, 02 Mar 2004 12:31:40 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Suggest a suitable image modifying CPAN module
Message-Id: <1395336.zDj2fo3EXN@GMT-hosting-and-pickle-farming>

Kasp wrote:

> Hello,
> 
> Problem: I need a module that will put a user specified string in the
> bottom right corner of an image (bmp, jpg, gif etc). Height of text will
> be 1/10 height of image.
> 
> I found Image::Size can help me determine the size of image. But what can
> I use to super-impose a string on the image so as to achieve the desired
> effect.
> 
> Thanks.

You can get the GD module to read in an image using newFromGif. Then append
text, and write out a new image.
There's a predetermined variety of text sizes GD uses, but I don't think GD
supports text scaling.

Maybe Image::Magick can do it too.

gtoomey


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

Date: 02 Mar 2004 03:51:45 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Suggest a suitable image modifying CPAN module
Message-Id: <slrnc4816g.8k7.mgjv@verbruggen.comdyn.com.au>

On Tue, 02 Mar 2004 12:31:40 +1000,
	Gregory Toomey <nospam@bigpond.com> wrote:
> Kasp wrote:
> 
>> Hello,
>> 
>> Problem: I need a module that will put a user specified string in the
>> bottom right corner of an image (bmp, jpg, gif etc). Height of text will
>> be 1/10 height of image.
>> 
>> I found Image::Size can help me determine the size of image. But what can
>> I use to super-impose a string on the image so as to achieve the desired
>> effect.
>> 
>> Thanks.
> 
> You can get the GD module to read in an image using newFromGif. Then append
> text, and write out a new image.
> There's a predetermined variety of text sizes GD uses, but I don't think GD
> supports text scaling.

It does, when you use a TrueType font.

> Maybe Image::Magick can do it too.

It can. Imager is another module that could do this.


One way with GD and GD::Text::Align could be:

#!/usr/local/bin/perl
use warnings;
use strict;

use GD;
use GD::Text::Align;

@ARGV or die "Need an image file\n";

for my $img_file (@ARGV)
{
    my $gd = GD::Image->new($img_file) or die;
    my ($w, $h) = $gd->getBounds();

    my $gdt = GD::Text::Align->new($gd,
	valign => 'bottom',
	halign => 'right',
	text   => 'Some Text',
	colour => $gd->colorResolve(0,0,0),
    ) or die;
    $gdt->set_font('arial', $h/10) or die;
    $gdt->draw($w, $h, 0) or die;

    open(GD, ">$img_file.out.png") or die;
    binmode GD;
    print GD $gd->png;
    close GD;
}


I'll leave it up to OP to put in sensible error checks and messages etc.

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | In a world without fences, who needs Gates?
                        | 


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

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


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