[22464] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4685 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 8 21:06:53 2003

Date: Sat, 8 Mar 2003 18:05:07 -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           Sat, 8 Mar 2003     Volume: 10 Number: 4685

Today's topics:
    Re: /proc equivalent in HP-UX <mgjv@tradingpost.com.au>
        call subroutine with reference with strict in place (Mike Solomon)
    Re: call subroutine with reference with strict in place <kevin@vaildc.net>
    Re: call subroutine with reference with strict in place <mgjv@tradingpost.com.au>
    Re: call subroutine with reference with strict in place (Tad McClellan)
    Re: Catching errors using DBI ctcgag@hotmail.com
        Form ----> Email Supporting file input??!! <cwservices2@qwest.net>
    Re: Form ----> Email Supporting file input??!! <noreply@gunnar.cc>
        Help print 2d array. <mail@annuna.com>
    Re: Help print 2d array. (Anno Siegel)
    Re: is a hash the best way to do this? <s_grazzini@hotmail.com>
    Re: is a hash the best way to do this? <s_grazzini@hotmail.com>
    Re: is a hash the best way to do this? <brad@langhorst.com>
    Re: is a hash the best way to do this? (david)
    Re: new Perl feature request: call into shared libs <no.spam@gknw.de>
    Re: new Perl feature request: call into shared libs <no.spam@gknw.de>
    Re: new Perl feature request: call into shared libs (Bryan Castillo)
    Re: Obfuscated Perl Challenge <abigail@abigail.nl>
        Regular expression question <zarlenga@conan.ids.net>
    Re: Regular expression question <mbudash@sonic.net>
    Re: Regular expression question <noreply@gunnar.cc>
    Re: Regular expression question (Anno Siegel)
    Re: Regular expression question <noreply@gunnar.cc>
    Re: Regular expression question <abigail@abigail.nl>
    Re: Regular expression question <zarlenga@conan.ids.net>
    Re: SUBSTR or pattern matching? <tassilo.parseval@post.rwth-aachen.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 9 Mar 2003 10:49:34 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: /proc equivalent in HP-UX
Message-Id: <slrnb6l0ce.747.mgjv@martien.heliotrope.home>

On 8 Mar 2003 02:30:36 -0800,
	amar <amarsantpur@hotmail.com> wrote:
> Hi,
> 
> In unix the files for a pid is present in /proc directory. 
> Can anyone tell me the equivalent directory name where i 
> can find all the files for a given pid in HP-UX systems.

I think you mean to post this in a newsgroup that talks about HP UX,
instead of a Perl newsgroup:

comp.sys.hp.hpux

Martien
-- 
                        | 
Martien Verbruggen      | That's not a lie, it's a terminological
                        | inexactitude.
                        | 


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

Date: 8 Mar 2003 16:38:43 -0800
From: mike_solomon@lineone.net (Mike Solomon)
Subject: call subroutine with reference with strict in place
Message-Id: <56568be5.0303081638.9cabb8b@posting.google.com>

I have written a small test script that calls a subroutine depending
on a variable

it uses a sympolic reference, which is not allowed when using strict,
i would appreciate any help making this work without turning off
strict

Thanks


Here is the test script:

use strict;
no strict 'refs';

our $screen = "a2";

&test;

sub test {
	&$screen;
}

sub a1 {
         print "A1";
}

sub a2 {
         print "A2";
}


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

Date: Sat, 08 Mar 2003 20:14:56 -0500
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: call subroutine with reference with strict in place
Message-Id: <kevin-79C01C.20145608032003@vienna7.his.com>

In article <56568be5.0303081638.9cabb8b@posting.google.com>,
 mike_solomon@lineone.net (Mike Solomon) wrote:

> I have written a small test script that calls a subroutine depending
> on a variable
> 
> it uses a sympolic reference, which is not allowed when using strict,
> i would appreciate any help making this work without turning off
> strict
> 
> Thanks
> 
> 
> Here is the test script:
> 
> use strict;
> no strict 'refs';
> 
> our $screen = "a2";

our $screen = \&a2;

> &test;
> 
> sub test {
> 	&$screen;
> }
> 
> sub a1 {
>          print "A1";
> }
> 
> sub a2 {
>          print "A2";
> }
-- 
Kevin Michael Vail | Dogbert: That's circular reasoning.
kevin@vaildc.net   | Dilbert: I prefer to think of it as no loose ends.
http://www.vaildc.net/kevin/


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

Date: Sun, 9 Mar 2003 12:36:42 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: call subroutine with reference with strict in place
Message-Id: <slrnb6l6la.747.mgjv@martien.heliotrope.home>

On 8 Mar 2003 16:38:43 -0800,
	Mike Solomon <mike_solomon@lineone.net> wrote:
> I have written a small test script that calls a subroutine depending
> on a variable
> 
> it uses a sympolic reference, which is not allowed when using strict,
> i would appreciate any help making this work without turning off
> strict

The mornal jway of doing these sorts of things is with a dispatch table:


my %dispatch = (
    'a1' => \&a1,
    'a2' => \&a2,
);

# time passes

my $callref = $dispatch{$whatever_variable};

$callref->(@arguments);


If you don't have to have those subroutines (a1, a2) available with a
name in your program, then consider:


my %dispatch = (
    'a1' => sub { ... code for a1 goes here },
    'a2' => sub { ... code for a2 goes here },
);


For more on this, use groups.google.com to see past discussions in this
newsgroup  on dispatch tables.

> Here is the test script:
> 
> use strict;
> no strict 'refs';
> 
> our $screen = "a2";

Of course, it would also all work if you did something like:

my $screen = \&a2;


$screen->(@args);

or even like you did it:

> 	&$screen;

It's just that the dispatch table is a more organised way of keeping these
things together.

Martien
-- 
                        | 
Martien Verbruggen      | Begin at the beginning and go on till you
                        | come to the end; then stop.
                        | 


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

Date: Sat, 8 Mar 2003 19:47:50 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: call subroutine with reference with strict in place
Message-Id: <slrnb6l7a6.d8c.tadmc@magna.augustmail.com>

Mike Solomon <mike_solomon@lineone.net> wrote:

> 
> it uses a sympolic reference, which is not allowed when using strict,


So use a Real Reference instead of a symbolic one.


> i would appreciate any help making this work without turning off
> strict

> our $screen = "a2";
> 
> &test;
> 
> sub test {
> 	&$screen;
> }
> 
> sub a1 {
>          print "A1";
> }
> 
> sub a2 {
>          print "A2";
> }


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

my %subs = (
   a1 => \&a1,
   a2 => \&a2,
);

my $screen = "a2";

&test;

sub test {
        $subs{$screen}->();
}

sub a1 {
         print "A1";
}

sub a2 {
         print "A2";
}
--------------------------------


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


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

Date: 08 Mar 2003 22:39:56 GMT
From: ctcgag@hotmail.com
Subject: Re: Catching errors using DBI
Message-Id: <20030308173956.607$Z3@newsreader.com>

"Geoff Soper" <geoff.news7@alphaworks.co.uk> wrote:
> I'm using DBI to access a MySQL database. There are times when it is
> possible that the queries I'm executing won't return a result, how can I
> catch this in the example of the code below, i.e. when there is no
> user_cookie corresponding to the username?
>
> Many thanks
> Geoff
>
> # Get cookie value from database and set up cookie
>    my $cookie_value = $dbh->selectrow_array( "SELECT user_cookie FROM
> users WHERE username = ?",
>               {},
>               param("username"));

There are three reasons $cookie_value could be null:
  If the select returns the empty set (what you asked about, but not an
  error) If user_cookie is nullable and the first row returned is a null
  value. If the query encountered an error and RaiseError is not on.

It may (or may not) be important that you distinguish these cases.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Sat, 08 Mar 2003 12:41:30 -0800
From: P.C. Ford <cwservices2@qwest.net>
Subject: Form ----> Email Supporting file input??!!
Message-Id: <u5lk6v0jppbl8ld7ssiltmepbifh452ece@4ax.com>

I am strictly a graphics person but am now working on a form which
needs to be able to upload files. 

On the hosting service, the following scripts are installed.

Formmail. I know that Formmail will not upload files..

Cgiemail (http://hostingsupport.com/manual/cgib.html#1) This one
works, but won't upload files-at least for me!

There also seems to be documentation for another Cgiemail; the support
info seems a bit different.
http://web.mit.edu/wwwdev/cgiemail/user.html

There is also something called Alienform. 
http://cgi.tj/scripts/alienform/

The strange thing is that there is another site on the same server
which is able to upload files. Its ACTION path ends in mail.cgi I know
about including the multi-part business in action by the way.

If you know of another Form -->Email script which is very, very easy
to install let me know. Gotta be easy. I once spent three days
installing Matt Wright's WWWBoard. erggg.

Or if you can do this for me for a reasonable price, talk to me. 

Thank you



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

Date: Sat, 08 Mar 2003 21:51:51 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Form ----> Email Supporting file input??!!
Message-Id: <b4dl4v$1urp7t$1@ID-184292.news.dfncis.de>

P.C. Ford wrote:
> I am strictly a graphics person but am now working on a form which
> needs to be able to upload files.
> [snip]

Do *not* post the same question multiple times to different Usenet 
groups.! It's bad netiquette. Sometimes *cross-posting* may be justified.

You have received a reply in comp.infosystems.www.authoring.cgi, which 
readers of comp.lang.perl.misc may not know about.

/ Gunnar

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


-- 
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.

HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html


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

Date: Sat, 08 Mar 2003 14:05:28 -0600
From: Joe Creaney <mail@annuna.com>
Subject: Help print 2d array.
Message-Id: <3E6A4D08.3040109@annuna.com>



Alan J. Flavell wrote:
> On Wed, Mar 5, Joe Creaney caused the following to appear:
> 
> Parts/Attachments:
>    1 Shown    83 lines  Text
>    2 Shown    79 lines  Text
> 
> then blurted out:
> 
> 
>>Working the bugs out it pretty much works except for the grid printing
>>function.  Here is my code can I use nested foreach loops to print out
>>the data in my grid?
> 
> 

sub pgrid {

my ($xp,$yp) = @_;
my $l;
my $l1;
my @grd=(
         [ qw( . . . . . )],
         [ qw( . . . . . )],
         [ qw( . . . . . )],
         [ qw( . . . . . )],
         [ qw( . . . . . )],
           );

print "Printing Grid \n";

foreach $l (@grd) {

       for ( $l1=0; $l1 >4; $l1++) {
                 if (($l == $xp) and ($l1 == $yp)) {
                 print "*"; } else {
                 print "$grd[$l] [$l1]"; }

                 print "$l  $l1";
                 }
        print "\n";
        print "$grd[$l][$l1]";

        }

}
This is the part I am having problems.  I would like to use nested for 
each loops to print out the grid.  This should work until I can progam 
the function to be more flexable.  I just want to see where my error is 
and be able to print this 2d array



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

Date: 8 Mar 2003 21:11:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Help print 2d array.
Message-Id: <b4dmam$ekr$1@mamenchi.zrz.TU-Berlin.DE>

Joe Creaney  <mail@annuna.com> wrote in comp.lang.perl.misc:
> Alan J. Flavell wrote:
> > On Wed, Mar 5, Joe Creaney caused the following to appear:
> > 
> > Parts/Attachments:
> >    1 Shown    83 lines  Text
> >    2 Shown    79 lines  Text
> > 
> > then blurted out:
> > 
> > 
> >>Working the bugs out it pretty much works except for the grid printing
> >>function.  Here is my code can I use nested foreach loops to print out
> >>the data in my grid?

I don't see how what you quoted from Alan has anything to do with what
follows.

> sub pgrid {
> 
> my ($xp,$yp) = @_;
> my $l;
> my $l1;
> my @grd=(
>          [ qw( . . . . . )],
>          [ qw( . . . . . )],
>          [ qw( . . . . . )],
>          [ qw( . . . . . )],
>          [ qw( . . . . . )],
>            );

@grd should really be given as a parameter, not built inside the
routine, I think.

> print "Printing Grid \n";
> 
> foreach $l (@grd) {
> 
>        for ( $l1=0; $l1 >4; $l1++) {
                      ^^^^^^

This will fail the first time through, so the loop will never run.
use "$l1 <= 4" instead.


>                  if (($l == $xp) and ($l1 == $yp)) {
                        ^^ 
Note that $l is an arrayref, not an index into an array.  It doesn't make
sense to compare it to an index.

>                  print "*"; } else {
>                  print "$grd[$l] [$l1]"; }
                               ^^
 ...nor does it make sense to use it as an index.  I'm giving up here.

> 
>                  print "$l  $l1";
>                  }
>         print "\n";
>         print "$grd[$l][$l1]";
> 
>         }
> 
> }
> This is the part I am having problems.  I would like to use nested for 
> each loops to print out the grid.  This should work until I can progam 
> the function to be more flexable.  I just want to see where my error is 
> and be able to print this 2d array

Here is one way to tackle this.  First, write a general-purpose routine
to print a grid, whatever it contains:

    sub pgrid {
        my $grid = shift;
        print @$_, "\n" for @$grid;
    }

This will print five lines of five dots each:

    my @grid = map [ ( '.' ) x 5], 1 .. 5;
    pgrid( \ @grid);

Now, to print an asterisk instead of a dot at position $xp, $yp, just
change the corresponding grid field:

    $grid[ $xp][ $yp] = '*';

and print it again.

However, the change to the grid is permanent, which probably not exactly
what is wanted.  We can make the change local to the subroutine if
we move it inside it:

    sub pgrid {
        my $grd = shift;
        my ( $xp, $yp) = @_;
        local $grd->[ $xp][ $yp] = '*' if @_;
        print @$_, "\n" for @$grd;
    }

The local change is only made when $xp and $yp are given, so calling
pgrid() with only one parameter will print the grid as is.  In any case,
the change to the grid will be local to the subroutine body.

Anno


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

Date: Sat, 08 Mar 2003 19:33:58 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: is a hash the best way to do this?
Message-Id: <GAraa.92027$ma2.20808650@twister.nyc.rr.com>

david <dwlepage@yahoo.com> writes:
> I currently have a program that opens a file and finds 
> data to replace. The problem is the current code that 
> I have takes between 5-10 minutes to run on a 2MB file. 
> I am sure there must be better ways to do this - can 
> anyone help?
<snip>
> 
> while (<IN>) {
>     #Reset $keyname and $keyvalue for each new record
>     if (/^dn: UserId=/) {
>         $keyname = $keyvalue = "";
>         #Set $keyname to "UserId".TOK.0
>         if (/^dn: UserId=([a-zA-Z]+),/) {
>             $keyname = $1 . ".TOK.0";
>         }
>     }
>     #Set $keyvalue to true authenticator value
>     if (/^Comment:\s*(.{9})/) {
>         $keyvalue = $1;
>     }
>     #Add values to hash
>     if (!($keyname eq "") && !($keyvalue eq "")) {
>         $uid{"$keyname"} = $keyvalue;
>     }
>     foreach $key (keys(%uid)) {
>         $search = $key;
>         $replace = $uid{"$key"};
>         s/$search/$replace/g;
>     }
>     #Send each line to new file
>     print OUT $_;
> }

The big problem is the foreach loop -- you're clubbing
each line to death with the proverbial loaded Uzi.

    # Add values to hash
    if ($keyname and length $keyvalue) {
        $uid{$keyname} = $keyvalue;
    }

    s/([A-Za-z]+\Q.TOK.0)/$uid{$1} or $1/eg;
    print OUT;

-- 
Steve


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

Date: Sat, 08 Mar 2003 19:36:24 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: is a hash the best way to do this?
Message-Id: <YCraa.92070$ma2.20810080@twister.nyc.rr.com>

Steve Grazzini <s_grazzini@hotmail.com> writes:
>
>     # Add values to hash
>     if ($keyname and length $keyvalue) {
>         $uid{$keyname} = $keyvalue;
>     }
> 
>     s/([A-Za-z]+\Q.TOK.0)/$uid{$1} or $1/eg;

Whoops:

      s/([A-Za-z]+\.TOK\.0)/$uid{$1} or $1/eg;

-- 
Steve


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

Date: Sat, 08 Mar 2003 19:55:42 GMT
From: Brad Langhorst <brad@langhorst.com>
Subject: Re: is a hash the best way to do this?
Message-Id: <2Vraa.9029$gF3.911884@newsread1.prod.itd.earthlink.net>

david wrote:

> I currently have a program that opens a file and finds data to
> replace. The problem is the current code that I have takes between
> 5-10 minutes to run on a 2MB file. I am sure there must be better ways
> to do this - can anyone help?

i think your basic idea is fine...
but I think you should read in the entire input file
like this

(this is pseudocode)

while <IN>{
        if (/userid=(\w+)/ {
                $comment = find_comment;
                $uid{$1} = $comment;
        }
}
#then in another loop (outside of the reading while)
foreach $key( keys %hash) {
        s/$key/$uid{$key}/;
}

brad


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

Date: 8 Mar 2003 16:45:56 -0800
From: dwlepage@yahoo.com (david)
Subject: Re: is a hash the best way to do this?
Message-Id: <b09a22ae.0303081645.2388013@posting.google.com>

Brad Langhorst <brad@langhorst.com> wrote in message news:<2Vraa.9029$gF3.911884@newsread1.prod.itd.earthlink.net>...
> david wrote:
> 
> > I currently have a program that opens a file and finds data to
> > replace. The problem is the current code that I have takes between
> > 5-10 minutes to run on a 2MB file. I am sure there must be better ways
> > to do this - can anyone help?
> 
> i think your basic idea is fine...
> but I think you should read in the entire input file
> like this
> 
> (this is pseudocode)
> 
> while <IN>{
>         if (/userid=(\w+)/ {
>                 $comment = find_comment;
>                 $uid{$1} = $comment;
>         }
> }
> #then in another loop (outside of the reading while)
> foreach $key( keys %hash) {
>         s/$key/$uid{$key}/;
> }
> 
> brad

Thanks. This works in all but the cases where the comment field is set
to "". It looks like this is happening if a comments field is
something like this:
Comment: (some text)
When it does the search/replace on these records, it writes the
$uid{$key} as a blank. Any ideas to not process these records? My
previous code checked to make sure it has a value before executing the
replace:
if (!($keyname eq "") && !($keyvalue eq "")) 

I can't seem to throw this in anywhere without messing up the
replaces..


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

Date: Sat, 08 Mar 2003 19:53:46 +0100
From: Guenter <no.spam@gknw.de>
Subject: Re: new Perl feature request: call into shared libs
Message-Id: <3E6A3C3A.2010801@gknw.de>

Hi Ilya,

Ilya Zakharevich schrieb:
>>Hi all,
>>although I dont like VBScript, what I really like from it is the 
>>possibility to directly call into shared libs.
> 
> This is not possible.  Shared libraries provide addresses of
> C-callable functions, but do not describe which calling convention the
> function implement.  Without this knowledge, it is not possible to
> call such a function.  While Perl allows you to easily load a shared
> library, and get the address of a function, you cannot provide
> arguments to the function - unless via XS interface, which goes
> through a C compiler, so is not a runtime method.
well, I dont see the problem: f.e. spoken for Win32 you can get tons of 
info about the Win32 API, in addition every compiler comes with the SDK 
headers, so there's absolutely no problem to find descriptions for the 
functions. You really should take a look at Win32::API, it's very cool; 
and I've already done sone samples which access the Novell CLient API, 
and show that everything's possible, even with complex structs...

> But it is easy to write a wrapper which would work with e.g., n<20;
> both for cdecl, and for regparam(3) calling conventions.  Actually,
> doing this for the OS2 port is in my TODO list.  [Important since OS/2
> API more or less always takes a series of longs (or compatibles) as
> arguments.]
you should take a look at th .xs code from Win32::API;
but I dont know: do you compile OS/2 with emx?? if so you will have 
trouble with the inline assembler, I think gcc doesnt know it...
but once you have solved that I think the rest is not so hard to port...

good luck, Guenter.




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

Date: Sat, 08 Mar 2003 20:27:45 +0100
From: Guenter <no.spam@gknw.de>
Subject: Re: new Perl feature request: call into shared libs
Message-Id: <3E6A4431.5020602@gknw.de>

Hi Ilya,

Ilya Zakharevich schrieb:
>>Hi all,
>>although I dont like VBScript, what I really like from it is the 
>>possibility to directly call into shared libs.
> 
> This is not possible.  Shared libraries provide addresses of
> C-callable functions, but do not describe which calling convention the
> function implement.  Without this knowledge, it is not possible to
> call such a function.  
but where's the problem?? The information is accessable, you can get 
tons of docu about teh Win32 API, and in addition I was thinking of 
calling documented libs, f.e. the NetWare Client APIs; and I already was 
successful with the module Win32-API which provides such an interface; 
others pointe me to it....

> While Perl allows you to easily load a shared
> library, and get the address of a function, you cannot provide
> arguments to the function - unless via XS interface, which goes
> through a C compiler, so is not a runtime method.
well, seems you have some more inside knowledge: you mean the syscall() 
function, or? I've experimented with this too on Linux, but no luck yet; 
and I dont know how to load a shared lib; hoe is this done then??

> During the time of v5.000alpha, there was a discussion on p5p about
> adding a functionality of a call to a function with the simplest,
> cdecl, calling convention.  Again, this was not implemented due to
> non-portability of such a call.  E.g., I do not know how to write i386
> assembler which would call a C function with n long arguments; here n
> is a variable number given as a parameter:
> 
>   void
>   call_many_longs(void (*f)(), long n, long *array_of_arguments)
>   {
>     __asm__("???");
>   }
> 
> But it is easy to write a wrapper which would work with e.g., n<20;
> both for cdecl, and for regparam(3) calling conventions.  Actually,
> doing this for the OS2 port is in my TODO list.  [Important since OS/2
> API more or less always takes a series of longs (or compatibles) as
> arguments.]
you should really take a look at Win32::API; the .xs code looks portable 
for me; only problem could be the inline asembler; I dont know: do you 
compile for OS2 with emx?? I think gcc doesnt know inline asm, so you 
have to rewrite these parts...
but the module is worth to have on every platform: it's often only one 
or two simple calls into a lib for which creating an own module is too 
much work...

Guenter.




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

Date: 8 Mar 2003 13:09:58 -0800
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: new Perl feature request: call into shared libs
Message-Id: <1bff1830.0303081309.752facce@posting.google.com>

> During the time of v5.000alpha, there was a discussion on p5p about
> adding a functionality of a call to a function with the simplest,
> cdecl, calling convention.  Again, this was not implemented due to
> non-portability of such a call.  E.g., I do not know how to write i386
> assembler which would call a C function with n long arguments; here n
> is a variable number given as a parameter:
> 
>   void
>   call_many_longs(void (*f)(), long n, long *array_of_arguments)
>   {
>     __asm__("???");
>   }

(This should work on Linux/i386 using gcc/gas? I only tried 0 to 6 32 bit args)

_call_fptr:
        pushl   %ebp            /* save register */
        movl    %esp, %ebp      /* setup ebp for reference */

        pushl   %ecx            /* save register */
        pushl   %ebx            /* save register */

        movl    16(%ebp), %ecx  /* store count */
        sall    $2, %ecx        /* multiply by 4 */
        movl    12(%ebp), %ebx  /* load array */
        addl    %ecx, %ebx      /* set position to end of array */

 .lp1bg:
        cmpl    %ebx, 12(%ebp)  /* at beginning of array ? */
        je      .lp1end         /* end loop */
        subl    $4, %ebx        /* decrement pointer */
        pushl   (%ebx)          /* push argument onto stack */
        jmp     .lp1bg          /* loop */
 .lp1end:

        movl    8(%ebp), %eax   /* get the function pointer */
        call    *%eax           /* call the function */

        movl    -4(%ebp), %ecx  /* restore register */
        movl    -8(%ebp), %ebx  /* restore register */
        movl    %ebp, %esp      /* set SP to known position */
        popl    %ebp            /* restore SP and ebp */

        ret                     /* done */



> 
> But it is easy to write a wrapper which would work with e.g., n<20;
> both for cdecl, and for regparam(3) calling conventions.  Actually,
> doing this for the OS2 port is in my TODO list.  [Important since OS/2
> API more or less always takes a series of longs (or compatibles) as
> arguments.]
> 
> Hope this helps,
> Ilya



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

Date: 08 Mar 2003 22:37:41 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Obfuscated Perl Challenge
Message-Id: <slrnb6ks5l.ekj.abigail@alexandra.abigail.nl>

Benjamin Goldberg (goldbb2@earthlink.net) wrote on MMMCDLXXVI September
MCMXCIII in <URL:news:3E69523B.CE731197@earthlink.net>:
,,  Abigail wrote:
,, > 
,, > Benjamin Goldberg (goldbb2@earthlink.net) wrote on MMMCDLXXV September
,, > MCMXCIII in <URL:news:3E685F6E.C3E9A517@earthlink.net>:
,, > ||  Can anyone guess/figure out what this code does, without running
,, > ||  it?
,, > ||
,, > ||  @1=a..c;$;=4;{push@2,map[$;--,@1[0,2,1]=@1
,, > ||  ],2..$;x--$|;print"$1[0]=>$1[2]\n";--$;?@1
,, > ||  =@1[1,0,2]:(($;,@1)=@{pop@2||last});redo}
,, > ||
,, > ||  A large part of the obfuscation is because the flow control is
,, > ||  significantly different from the way this particular algorithm is
,, > ||  normally implemented, so even using Deparse won't significantly
,, > ||  help you.
,, > 
,, > After a few seconds, I guessed "Towers of Hanoi". Running it seems
,, > to confirm the guess.
,, > 
,, > The 0, 1, 2 permutations are a giveaway.
,,  
,,  Wow -- I wouldn't have made the leap from those 0,2,1 and 1,0,2 to
,,  "Towers of Hanoi".  If I'd hidden those permutations, like this:
,,  
,,     @1=a..c;$;=4;sub x{@1[@_]=@1[@_[1,0]]}{(push@2,[
,,     $;--,@1]),x 1,2 for 2..$;x--$|;print"$1[0]=>$1[
,,     2]\n";--$;?x 0,1:(($;,@1)=@{pop@2||last});redo}
,,  
,,  Would it have been better, less obvious?

Hard to tell. Now I already know what's it doing, so I can't try it out.

,,  (I'm assuming that you guessed that *only* from seeing those 0,1,2
,,  permutations, not due to recognizing the algorithm from the arrangement
,,  of pushes and pops... and that really cool 'x --$|' that acts sortof the
,,  way an "if $iteration++ % 2" modifyer would.)

Well, the 0, 1, 2 made me think of Hanoi, and the pushes and pops
strengthen the idea it could be Hanoi.

,,  This version of the code has a fringe "benefit", if it can be called
,,  that, of not being liked by perl 5.6's B::Deparse, for some reason.  It
,,  produces the following error:
,,  
,,     Can't call method "PADLIST" on an undefined value at
,,     C:/Ben/ActivePerl/Perl/lib/B/Deparse.pm line 1039.
,,     CHECK failed--call queue aborted.
,,  
,,  Strange, no?  Especially since, IIRC, perl's "PAD" things are where
,,  lexical variables live, and I have no my() variables in my code.

Hmmm. I thought that on the PAD variables with a limited timespan
lived. Which would be lexicals, but also localized variables.
But I guess I'm wrong.

,, > # Needs perl 5.005_03 or *earlier*.
,, > %0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;
,,                           ^
,,  Adding in a 'map$_,' here, it will work on later perls.

Yeah, but then it would lose part of its charme.



Abigail
-- 
print 74.117.115.116.32.97.110.111.116.104.101.114.
      32.80.101.114.108.32.72.97.99.107.101.114.10;


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

Date: Sat, 08 Mar 2003 22:34:58 -0000
From: Z  <zarlenga@conan.ids.net>
Subject: Regular expression question
Message-Id: <v6ks0idovad508@corp.supernews.com>

Sorry if this is a repost ...

I need to create a regular expression that matches if a string
(s1) is somewhere in the search string but not if the string (s1)
is immediately preceded by another string (s2).

For example, I want to match if "bar" is in the string, but not
if the "bar" is preceded by "foo ".

Is this possible with one regular expression?


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

Date: Sat, 08 Mar 2003 22:47:31 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Regular expression question
Message-Id: <mbudash-8E5972.14473008032003@typhoon.sonic.net>

In article <v6ks0idovad508@corp.supernews.com>,
 Z  <zarlenga@conan.ids.net> wrote:

> Sorry if this is a repost ...
> 
> I need to create a regular expression that matches if a string
> (s1) is somewhere in the search string but not if the string (s1)
> is immediately preceded by another string (s2).
> 
> For example, I want to match if "bar" is in the string, but not
> if the "bar" is preceded by "foo ".
> 
> Is this possible with one regular expression?

as for your example, you could type:

perldoc perlre

and scan for 'look-behind'

where you'd see (among other things):

       "(?<!pattern)"
                 A zero-width negative look-behind assertion.
                 For example "/(?<!bar)foo/" matches any occur-
                 rence of "foo" that does not follow "bar".
                 Works only for fixed-width look-behind.

note the last sentence. while this method won't work for your originally 
stated requirement, it will for your example, so it's still useful...

otherwise, this'd work, but it's not one regex, but who cares?

if ($astring =~ /^(.+?)bar/ && $1 !~ /foo $/) {
   # match!
}

hth-


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

Date: Sat, 08 Mar 2003 23:54:40 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regular expression question
Message-Id: <b4dsba$1ukd16$1@ID-184292.news.dfncis.de>

Z wrote:
> Sorry if this is a repost ...
> 
> I need to create a regular expression that matches if a string
> (s1) is somewhere in the search string but not if the string (s1)
> is immediately preceded by another string (s2).
> 
> For example, I want to match if "bar" is in the string, but not
> if the "bar" is preceded by "foo ".
> 
> Is this possible with one regular expression?

     $searchstring =~ /(?:^|[^$s2])$s1/;

/ Gunnar

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



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

Date: 8 Mar 2003 23:05:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regular expression question
Message-Id: <b4dt0c$i2n$1@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Z wrote:
> > Sorry if this is a repost ...
> > 
> > I need to create a regular expression that matches if a string
> > (s1) is somewhere in the search string but not if the string (s1)
> > is immediately preceded by another string (s2).
> > 
> > For example, I want to match if "bar" is in the string, but not
> > if the "bar" is preceded by "foo ".
> > 
> > Is this possible with one regular expression?
> 
>      $searchstring =~ /(?:^|[^$s2])$s1/;
                              ^^^^^^
This doesn't do what you think it does.  Look up how character classes work.

Anno


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

Date: Sun, 09 Mar 2003 01:06:50 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regular expression question
Message-Id: <b4e0in$1vkjit$1@ID-184292.news.dfncis.de>

Anno Siegel wrote:
> Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
>>
>>     $searchstring =~ /(?:^|[^$s2])$s1/;
>                             ^^^^^^
> This doesn't do what you think it does.  Look up how character classes work.

You are right, of course. I *did* test it before posting... But 
obviously not enough. :(

Now I realize that the expression does not match if the *last* character 
preceeding $s1 is *any* of the characters in $s2. I should have realized 
that it couldn't be that easy.

Thanks for correcting me, Anno. Sorry for possible confusion.

/ Gunnar

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



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

Date: 09 Mar 2003 01:50:49 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Regular expression question
Message-Id: <slrnb6l7fp.ekj.abigail@alexandra.abigail.nl>

Michael Budash (mbudash@sonic.net) wrote on MMMCDLXXVI September MCMXCIII
in <URL:news:mbudash-8E5972.14473008032003@typhoon.sonic.net>:
()  
()  otherwise, this'd work, but it's not one regex, but who cares?
()  
()  if ($astring =~ /^(.+?)bar/ && $1 !~ /foo $/) {
()     # match!
()  }


Unfortunally, if $string contains 'foo bar bar', it does contain a
bar not (directly) preceeded by 'foo ', yet your solution won't
find the match. The single regex solution would have found the
match.


Abigail

-- 
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");


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

Date: Sun, 09 Mar 2003 01:54:11 -0000
From: Z  <zarlenga@conan.ids.net>
Subject: Re: Regular expression question
Message-Id: <v6l7m3j10l7f41@corp.supernews.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
: Thanks for correcting me, Anno. Sorry for possible confusion.

So, then, is it not possible?


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

Date: 8 Mar 2003 19:14:02 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: SUBSTR or pattern matching?
Message-Id: <b4dfdq$hv3$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Barry Kimelman:

> In article <que76vctuialp9vo5hkvdeflrku8jd8mfv@4ax.com>, 
> impervious@attbi.com (impervious@attbi.com) says...
>> What is the best technique to use when trying to work with a string
>> that contains a date and you want to find the day?  Ie.  in a string
>> like this is want to find out that the day is the 25th:
>> 
>> 12/25/2000 blah blah blah blah

> $buffer = "12/25/2000 blah acih jklm wish"
> $buffer =~ m/(\d+)\/(\d+)\/(\d+)\s+(\w+)/; # match date & following word
> $month = $1;
> $day = $2;
> $year = $3;
> $word = $4;

The above four assignments should be made conditionally:

    if ($buffer =~ m!(\d+)/(\d+)/(\d+)\s+(\w+)/) {
        $month = $1;
        ...
    }

Otherwise you may end up with garbage in $<DIGIT> since on an
unsuccesful match they will contain their old value. Even better yet
would be a match in list-context:

    my ($month, $date, $year, $word) =
        $buffer =~ m!(\d+)/(\d+)/(\d+)\s+(\w+)/;
        
Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

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


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