[19241] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1436 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 3 14:10:33 2001

Date: Fri, 3 Aug 2001 11:10:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <996862210-v10-i1436@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 3 Aug 2001     Volume: 10 Number: 1436

Today's topics:
    Re: Q:Of negative numbers and logical operations nobull@mail.com
    Re: Regex library? <yf32@cornell.edu>
    Re: Regex library? (Andrew Hutchinson)
    Re: Regex library? nobull@mail.com
    Re: Regular Expression <jlavine@mitre.org>
    Re: Regular Expression <jlavine@mitre.org>
    Re: Regular Expression (John J. Trammell)
    Re: Setting DOS Variables (Was: Matt Wrights formmail a <jcook@strobedata.com>
    Re: Strange behavior? (Yves Orton)
        Understanding parsers (David Wall)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 03 Aug 2001 17:14:29 +0100
From: nobull@mail.com
Subject: Re: Q:Of negative numbers and logical operations
Message-Id: <u94rrpxgre.fsf@wcl-l.bham.ac.uk>

"Rami Saarinen" <rs55862@nospamyahoo.com> writes:

> Subject: Q:Of negative numbers and logical operations

Excellent subject line!  Clear, concise, informative, keyword-rich.

> I'm converting an old C-code to perl and I ran to the following problem: 
> In one point I need to run three variables throught exclusive or (^) and in
> the process I end up having a wrong result if a negative (original) value
> was involved. I think this has something to do with the (bit) sizes of
> variables (i.e. in C the variable is long integer (32 bit) and something else
> in perl) thus instead of marking the negative number the first bit is
> translated as a number.  Or something...

Perl's bitwise integer operation use (by default) the unsigned version
of your architecture's integer type (as described in "perldoc perlop").

> Is there any easy way to correct this? Any kind of advice is appreciated.

use integer; # All arithmetic operations to use architecture's signed int

It's not explicitly mentioned in "perldoc integer" (it is in "perldoc
perlop"), but a side-effect of "use integer" is to change the bitwise
integer operations from unsigned to signed.

"use integer" can have nasty side effects if you give it two wide a
scope so limit its scope to just those statements where you are
performing bitwise operations that you require to be using signed
integers.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 3 Aug 2001 11:24:15 -0400
From: "Young C. Fan" <yf32@cornell.edu>
Subject: Re: Regex library?
Message-Id: <9kefne$s9a$1@news01.cit.cornell.edu>

"Mik Mifflin" <NOSPAM.dogansmoobs@ctel.net> wrote in message
news:tmlf9ssmdt26f@corp.supernews.com...
> Just be a smart ass and call the perl script from the c program.  That'll
> solve it.  I see no reason it would have to be in c/c++.  If speed really
> matters that much, then then you can turn your perl script into C source
> and compile it (I believe).  I have found that redoing something in C or
> C++ takes too much time and effort, and the rewards are not that great
> compared to Perl.

I guess I could call Perl from the C program. But I'm writing a Windows
program (yeah, I know) that has to talk to Internet Explorer, so I can't
expect users to have Perl on their machine -- which is why I can't just do
it in Perl. Also, I'm very new to Windows programming and know that there
are far more relevant C++ examples available than there are in Perl.

It would just be tidier (I'm in a rush) if I could use a regex library
written for C/C++ -- is there one that does what I need (substitutions
supporting backreferences, and /sgie modifers)? I've tried posting to
comp.lang.c++ but have not gotten replies yet.

>
>  - Mik Mifflin
> Dogansmoobs at ctel dot net
>
> Young C. Fan wrote:
>
> > Hi,
> >
> > I was writing a regex-heavy Perl script, but I've been told to rewrite
it
> > in C/C++. The problem is that I'm having a lot of trouble finding a
regex
> > library which supports regular expressions as well as Perl does.
> >
> > I need the library to support the following:
> >
> > - substitutions with the /s, /g, /i, and especially the /e modifiers,
with
> > support for backreferences.
> >
> > If anyone here knows of any such regex library, can you please let me
> > know? Thank you so much.
> >
> > Young
> >
> >
> >




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

Date: Fri, 03 Aug 2001 15:30:37 GMT
From: andrew.hutchinson@mcmail.vanderbilt.edu (Andrew Hutchinson)
Subject: Re: Regex library?
Message-Id: <3b6ac30c.85312406@news.vanderbilt.edu>

You could get the Perl Developer's Kit (PDK), which has a utility that
will convert a Perl script to a Win32 .exe (with the interpreter
wrapped up in the executable) that can be run on any Windows machine.
I would also point out to the c/c++ proponent that the Perl's regex
engine is faster even than egrep, which is compiled c.  

On Fri, 3 Aug 2001 11:24:15 -0400, "Young C. Fan" <yf32@cornell.edu>
wrote:

>"Mik Mifflin" <NOSPAM.dogansmoobs@ctel.net> wrote in message
>news:tmlf9ssmdt26f@corp.supernews.com...
>> Just be a smart ass and call the perl script from the c program.  That'll
>> solve it.  I see no reason it would have to be in c/c++.  If speed really
>> matters that much, then then you can turn your perl script into C source
>> and compile it (I believe).  I have found that redoing something in C or
>> C++ takes too much time and effort, and the rewards are not that great
>> compared to Perl.
>
>I guess I could call Perl from the C program. But I'm writing a Windows
>program (yeah, I know) that has to talk to Internet Explorer, so I can't
>expect users to have Perl on their machine -- which is why I can't just do
>it in Perl. Also, I'm very new to Windows programming and know that there
>are far more relevant C++ examples available than there are in Perl.
>
>It would just be tidier (I'm in a rush) if I could use a regex library
>written for C/C++ -- is there one that does what I need (substitutions
>supporting backreferences, and /sgie modifers)? I've tried posting to
>comp.lang.c++ but have not gotten replies yet.
>
>>
>>  - Mik Mifflin
>> Dogansmoobs at ctel dot net
>>
>> Young C. Fan wrote:
>>
>> > Hi,
>> >
>> > I was writing a regex-heavy Perl script, but I've been told to rewrite
>it
>> > in C/C++. The problem is that I'm having a lot of trouble finding a
>regex
>> > library which supports regular expressions as well as Perl does.
>> >
>> > I need the library to support the following:
>> >
>> > - substitutions with the /s, /g, /i, and especially the /e modifiers,
>with
>> > support for backreferences.
>> >
>> > If anyone here knows of any such regex library, can you please let me
>> > know? Thank you so much.
>> >
>> > Young
>> >
>> >
>> >
>
>



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

Date: 03 Aug 2001 17:15:15 +0100
From: nobull@mail.com
Subject: Re: Regex library?
Message-Id: <u93d79xgq4.fsf@wcl-l.bham.ac.uk>

"Young C. Fan" <yf32@cornell.edu> writes:

> I was writing a regex-heavy Perl script, but I've been told to rewrite it in
> C/C++.

Why?  This is not a flippant question.  Knowing why you have been
asked to do this is a very important part of knowing what you are
really being asked to do.

> The problem is that I'm having a lot of trouble finding a regex
> library which supports regular expressions as well as Perl does.

What happend when you typed "perl regex library" into a search engine?
For example the first hit from Google was "PCRE (Perl-compatible Regex
library) 3.1" which seems close to what you want.

> I need the library to support the following:
> 
> - substitutions with the /s, /g, /i, and especially the /e modifiers, with
> support for backreferences.

If you need something that supports execution of arbitrary Perl code
(/e) then AFAIK then there's only libperl (see perldoc perlembed).

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 03 Aug 2001 11:45:36 -0400
From: Jeremy Lavine <jlavine@mitre.org>
Subject: Re: Regular Expression
Message-Id: <3B6AC720.250B8E9C@mitre.org>


or:

if($inputLn =~ /^\d*$/) {print "digits only"}
else {print "not just digits"}

	- Jeremy Lavine

Lee Osborne wrote:
> 
> Hi all,
> 
> OK heres a solution!
> 
> $input = "12a3456";
> 
> $idLengthIn = length($input);
> 
> if ($input{'document_id'} =~ /\d{$idLengthIn}/) {
> 
>    print "Digits ONLY!";
> 
> }
> 
> else {
> 
>    print "Not just digits!";
> 
> }
> 
> Lee.
> 
> "Lee Osborne" <osbornelee@hotmail.com> wrote in message
> news:996079173.11940.0.nnrp-01.c2de1f0e@news.demon.co.uk...
> > Hi all,
> >
> > Sorry to bother you all but I can't find a solution to a simple problem. I
> > assure you I have had a good look for the solution, but have had no
> success.
> >
> > What is the regular expresssion to check whether a string contains ONLY
> > numbers?
> >
> > It will be part of the code:
> >
> > if ($stringIn =~ /<THE RE SOLUTION>/) {
> >
> >   #  Numbers only in this string}
> > else {
> >
> >   # There are characters other than number in the string.
> > }
> >
> > Thanks in advance,
> >
> > Lee.
> >
> >


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

Date: Fri, 03 Aug 2001 11:45:49 -0400
From: Jeremy Lavine <jlavine@mitre.org>
Subject: Re: Regular Expression
Message-Id: <3B6AC72D.AE9113B2@mitre.org>


or:

if($inputLn =~ /^\d*$/) {print "digits only"}
else {print "not just digits"}

	- Jeremy Lavine

Lee Osborne wrote:
> 
> Hi all,
> 
> OK heres a solution!
> 
> $input = "12a3456";
> 
> $idLengthIn = length($input);
> 
> if ($input{'document_id'} =~ /\d{$idLengthIn}/) {
> 
>    print "Digits ONLY!";
> 
> }
> 
> else {
> 
>    print "Not just digits!";
> 
> }
> 
> Lee.
> 
> "Lee Osborne" <osbornelee@hotmail.com> wrote in message
> news:996079173.11940.0.nnrp-01.c2de1f0e@news.demon.co.uk...
> > Hi all,
> >
> > Sorry to bother you all but I can't find a solution to a simple problem. I
> > assure you I have had a good look for the solution, but have had no
> success.
> >
> > What is the regular expresssion to check whether a string contains ONLY
> > numbers?
> >
> > It will be part of the code:
> >
> > if ($stringIn =~ /<THE RE SOLUTION>/) {
> >
> >   #  Numbers only in this string}
> > else {
> >
> >   # There are characters other than number in the string.
> > }
> >
> > Thanks in advance,
> >
> > Lee.
> >
> >


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

Date: 03 Aug 2001 16:05:21 GMT
From: trammell@bayazid.hypersloth.invalid (John J. Trammell)
Subject: Re: Regular Expression
Message-Id: <slrn9ml15k.464.trammell@haqq.hypersloth.net>

On Fri, 03 Aug 2001 11:45:49 -0400, Jeremy Lavine jeopary-posted:
[jeopardectomized]
>> "Lee Osborne" wrote:
[snip]
>>> What is the regular expresssion to check whether a string contains ONLY
>>> numbers?
> 
> if($inputLn =~ /^\d*$/) {print "digits only"}
> else {print "not just digits"}
> 

How about:

 if ($input =~ /\D/) {
     print "matched a non-digit\n";
 } else {
     print "failed to match a non-digit\n";
 }

-- 
Aren't you, at this point, cutting down a California Redwood using a
banana *and* a particle accelerator?
                                         - Bernard El-Hagin, in CLPM


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

Date: 03 Aug 2001 16:08:02 GMT
From: Jim Cook <jcook@strobedata.com>
Subject: Re: Setting DOS Variables (Was: Matt Wrights formmail alert)
Message-Id: <3B6ACC61.E66E40A7@strobedata.com>


> > > The concept here, inspired by an article, is to set
> > > a DOS environmental variable and have it "stick" even
> > > after a Perl script closes. Otherwords, you could start
> > > another script and access this variable; behavior just
> > > like a proper .bat DOS file.

I apologize for posting C code here. If it is terribly bad form, let me
know and I'll not do it again. I don't know how to do just the same
thing in Perl (snoop through memory). 

The following snippet is something I used in DOS in 1992. This finds the
primary command.com. The environment segment then has the stuff you can
poke around in. I wrote my own "set" program so I could do stuff like
"set a=1+1" to get the same as "set a=2".

None of this works under NT, since the 16-bit app gets VDMmed and I only
fiddle my own virtual space. Maybe this will give you something else to
waste time with ... er ... play with.

struct   mcb_struct {
    byte end_flag;                              // M or Z
    word owner;
    word size;
    byte resv1[11];
};

struct mcb_struct _far *mcb;

void    find_mcb(void)
{
    mcb = NULL;
    while (mcb->end_flag != 'M' || mcb->owner != FP_SEG(mcb) + 1
        FP_SEG(mcb)++;
}

struct  psp_struct {
    word    int20_term;                         // INT 20 termination
addr
    word    eom_seg;                            // End of mem alloc
block
    byte    resv1;
    byte    resv2[5];                           // CALL FAR to DOS
function
    void (_interrupt _far *INT22)();            // INT 22 terminate addr
    void (_interrupt _far *INT23)();            // INT 23 Ctrl-Break
    void (_interrupt _far *INT24)();            // INT 24 Critical error
    word    parent_psp;                         // Parent PSP segment
    byte    handle[20];                         // FF = available
    word    environment;                        // Environment segment
    lword   resv3;
    word    handle_size;                        // Sizeof handle[]
    byte    _far *handle_table;                 // Handle address
    byte    resv4[23];
    word    CD21;                               // INT 21 DOS call
    byte    ret_far;                            // RET FAR
    byte    resv5[9];
    byte    fcb1[16];                           // Unopened FCB #1 (uses
[36])
    byte    fcb2[20];                           // Unopened FCB #1
    byte    cli_length;                         // Length of parameters
    byte    cli[127];                           // Starts blank, ends CR
};

void    show_psp(void)
{
    struct psp_struct _far *psp;
    char _far *cli;

    psp = NULL;
    FP_SEG(psp) = mcb->owner;

    if (mcb->owner == psp->parent_psp) {
        depth++;
    }

    cli = &psp->cli[0];
    printf("%04X ", psp->parent_psp);
    if (psp->environment != 0 && psp->environment != 0xFFFF) {
        printf("%04X ", psp->environment);
        cli = NULL;
        FP_SEG(cli) = psp->environment;
        while (cli[0] != '\0' || cli[1] != '\0')
            cli++;
        cli += 2 + sizeof(int);
        if (cli[1] == ':')
            printf("%Fs ", cli);
    }
}

--
jcook@strobedata.com  Live Honourably  4/1 - 4/3 + 4/5 - 4/7 + . . .
2001 Wed: Feb/last 4/4 6/6 8/8/ 10/10 12/12 9/5 5/9 7/11 11/7 3/14
Strobe Data Inc. home page   http://www.strobedata.com
My home page    O-           http://jcook.net


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

Date: 3 Aug 2001 11:03:24 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Strange behavior?
Message-Id: <74f348f7.0108031003.7a45e1bb@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<9ke97p$58c$3@mamenchi.zrz.TU-Berlin.DE>...
> According to Roman Khutkyy  <sky@mail.lviv.ua>:
> > Pardon...... $try{22}
> 
> Still nonsense.
> 
> Anno

Actually Anno its not nonsense.  For some reason all of the following
are the same.  This is a semi-bug in perl apparently that probably
wont be fixed (or so I have been told) as many scripts would break.

Try this:
#!perl
use strict;
use warnings;
my %hash=(key=>'value');
my $r_hash=\%hash;

print $hash{key}    ."\n";     # standard 
print $r_hash->{key}."\n";     # standard reference
print %hash->{key}  ."\n";     # should not work but does
__END__
And you should get:
------OUTPUT--------
value
value
value
------END OUTPUT----
as output.

If you do a search in CLPM for the subject "Why does this hash work?
%h->{a}='v'" you will see a minor discussion about this issue.

Cheers,
Yves


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

Date: Fri, 03 Aug 2001 16:53:59 -0000
From: darkon@one.net (David Wall)
Subject: Understanding parsers
Message-Id: <Xns90F282ED88855darkononenet@207.126.101.97>


I've been trying to learn how to use modules such as HTML::Parser and 
Parse::RecDescent, but I think I lack the background to completely 
understand the documentation.  Should I get a book or two from the 
comp.compilers FAQ, or are there other references I should read first?  
URLs are ok, but I generally prefer books that I can read at leisure.

-- 
David Wall
darkon@one.net


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

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.  

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


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