[18475] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 643 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 6 14:05:48 2001

Date: Fri, 6 Apr 2001 11:05:20 -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: <986580320-v10-i643@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 6 Apr 2001     Volume: 10 Number: 643

Today's topics:
        'use package' doesn't appear to work? <gmktb9cbu27001@sneakemail.com>
    Re: ANNOUNCE: Math::MatrixReal::Ext1 0.04 <sb@mcasia.imperia.net>
    Re: Anyone know how to handle CVS files With " in them? <cingram-at-pjocs-dot-demon-dot-co-dot-uk>
    Re: Anyone know how to handle CVS files With " in them? <clinton.munden@alcatel.com>
    Re: Anyone know how to handle CVS files With " in them? (Martien Verbruggen)
    Re: Anyone know how to handle CVS files With " in them? (Martien Verbruggen)
        Backtic-Escape help needed <jlm@cca-int.com>
    Re: Backtic-Escape help needed (Steven Smolinski)
        bare block usage (Cosmic Cruizer)
        Bot Script <npertuset@hotmail.com>
    Re: Bot Script (Anno Siegel)
    Re: Bot Script <npertuset@hotmail.com>
        can Perl be used to draw tables or lines on the screen  <user@home.com>
        re: CGI perl/php/ePerl <19wlr@globalnet.co.uk>
        Copying Directories <philip.shean@uwe.ac.uk>
    Re: Copying Directories <npertuset@hotmail.com>
    Re: Copying Directories <npertuset@hotmail.com>
    Re: Copying Directories <philip.shean@uwe.ac.uk>
    Re: Copying Directories <philip.shean@uwe.ac.uk>
    Re: Copying Directories <npertuset@hotmail.com>
    Re: Help needed compiling DB_File on HP-UX 11 (H. Merijn Brand)
    Re: How can I use  a var as part of a regex pattern <joeybach@127.0.0.1>
    Re: maximum value of a list (Randal L. Schwartz)
    Re: modify [not replace] code of a routine at runtime? <ubl@schaffhausen.de>
    Re: modify [not replace] code of a routine at runtime? nobull@mail.com
    Re: Most efficient way to extract unique array elements <abe@ztreet.demon.nl>
    Re: newbie: DBI:ODBC and M/S SQL Server <cpryce@pryce.net>
        parsing question... <rayj00@yahoo.com>
    Re: parsing question... (Tad McClellan)
    Re: parsing question (Anno Siegel)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 6 Apr 2001 13:41:06 -0400
From: "Crazy Cat" <gmktb9cbu27001@sneakemail.com>
Subject: 'use package' doesn't appear to work?
Message-Id: <9akuvo$ahn$1@imas0002.us.dg.com>

I have a perl script test_aamctl.pl that looks like the following
(the mixed cases are just as they are in the actual
code - we use all lower for packages and the mixed cases for
functions)

use dbs::test_dbs_user_manager;
 ...
test_DBS_User_Manager();

in a directory that contains a subdirectory called dbs.
In dbs there is a perl module called test_dbs_user_manager.pm that
looks like this --

package dbs::test_dbs_user_manager;

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(test_DBS_User_Manager);

sub test_DBS_User_Manager {
 ...
}
 ...
1;

When I run test_aamctl.pl I get an error
'Undefined subroutine &main::test_DBS_User_Manager called at
 ./test_aamctl.pl line ...

For some reason perl has not imported test_DBS_User_Manager into my
namespace and I can only get this code to run if I fully qualify the
function name
as dbs::test_dbs_user_manager::test_DBS_User_Manager.

The funny thing is I also have another module in a subdirectory called anl
and when I reference
functions there I have no problems.

What am I doing wrong? HELP!

Crazy




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

Date: 6 Apr 2001 15:53:30 GMT
From: Steffen Beyer <sb@mcasia.imperia.net>
Subject: Re: ANNOUNCE: Math::MatrixReal::Ext1 0.04
Message-Id: <9akopq$b5a$1@swifty.westend.com>

In comp.lang.perl.misc msouth@fulcrum.org wrote:

> Ilya Zakharevich suggested that Math::MatrixReal is
> obsolete and should not be used, given the existence of the
> more powerful Math::Pari.

I believe this was quite a selfish remark of his, since he's
the author of the Math::PARI module.... :-)

I don't think Math::MatrixReal is obsolete, for simple cases
it's just easier to use, no fuss in first getting a C library
compiled and installed, getting Math::PARI configured properly
so that it does find the library....

Math::MatrixReal is just a simple plain Perl module, to get
a simple job done simply and easily.

But of course it doesn't lend itself well for heavy-duty
number crunching, in such a case you should indeed consider
using Math::PARI or PDL.

Best reagrds,
-- 
    Steffen Beyer <sb@engelschall.com>
    http://www.engelschall.com/u/sb/whoami/ (Who am I)
    http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
    http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)


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

Date: Fri, 6 Apr 2001 13:12:54 +0100
From: "Clyde Ingram" <cingram-at-pjocs-dot-demon-dot-co-dot-uk>
Subject: Re: Anyone know how to handle CVS files With " in them?
Message-Id: <986564474.1558.0.nnrp-12.9e98e5bc@news.demon.co.uk>

Gary,

Gary Blake <gary@tigerstripes.co.uk> wrote in message
news:k5az6.5644$bL6.1097917@news2-win.server.ntlworld.com...
> Anyone know how to handle CVS files With " in them?

Try the "quotewords" function.
The Perl Cookbook explains how it lets you avoid some write-only reqular
expressions.

See the documentation for the standard Text::ParseWords function.
Something like:

use Text::ParseWords;
 ...
while (<INFILE>) {
    my @fields = quotewords( ",", 0, $_[0] );
    ...
}

Regards,
Clyde




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

Date: Fri, 06 Apr 2001 11:18:09 -0400
From: Clinton Munden <clinton.munden@alcatel.com>
Subject: Re: Anyone know how to handle CVS files With " in them?
Message-Id: <3ACDDE31.F01927D1@alcatel.com>

I think he is talking about CVS which is Concurrent Version System.

Clyde Ingram wrote:

> Gary,
>
> Gary Blake <gary@tigerstripes.co.uk> wrote in message
> news:k5az6.5644$bL6.1097917@news2-win.server.ntlworld.com...
> > Anyone know how to handle CVS files With " in them?
>
> Try the "quotewords" function.
> The Perl Cookbook explains how it lets you avoid some write-only reqular
> expressions.
>
> See the documentation for the standard Text::ParseWords function.
> Something like:
>
> use Text::ParseWords;
> ...
> while (<INFILE>) {
>     my @fields = quotewords( ",", 0, $_[0] );
>     ...
> }
>
> Regards,
> Clyde



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

Date: Sat, 7 Apr 2001 01:31:40 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Anyone know how to handle CVS files With " in them?
Message-Id: <slrn9croas.3ud.mgjv@martien.heliotrope.home>

On Fri, 6 Apr 2001 03:47:30 -0700,
	Gary Blake <gary@tigerstripes.co.uk> wrote:
> Anyone know how to handle CVS files With " in them?
> 
> I've come up blank with google searches!

That's maybe because they're called CSV (for comma-separated value).
search.cpan.org will suggest at least one module if you use that as a
search string.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I used to have a Heisenbergmobile.
Commercial Dynamics Pty. Ltd.   | Every time I looked at the
NSW, Australia                  | speedometer, I got lost.


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

Date: Sat, 7 Apr 2001 01:50:47 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Anyone know how to handle CVS files With " in them?
Message-Id: <slrn9crpen.3ud.mgjv@martien.heliotrope.home>

[Please in the future, put your comments after the suitably trimmed text
you reply to. it's the commonly accepted quoting style on this
newsgroup, and usenet in general.]

On Fri, 06 Apr 2001 11:18:09 -0400,
	Clinton Munden <clinton.munden@alcatel.com> wrote:
> Clyde Ingram wrote:
>> Gary Blake <gary@tigerstripes.co.uk> wrote in message
>> news:k5az6.5644$bL6.1097917@news2-win.server.ntlworld.com...
>> > Anyone know how to handle CVS files With " in them?
>>
>> Try the "quotewords" function.
> 
> I think he is talking about CVS which is Concurrent Version System.

What makes you say that? I have many, many files in several CVS
repositories, with loads of quotes in them. There is nothing special
about dealing with them.

Besides that, who in their right mind would ask about how to deal with
things that would be CVS specific in a perl newsgroup? (I know, odd
questions are asked here). 

I really must say that the assumption that the OP mistyped or misspelled
CSV is much more likely, given that the quoted quotes in CSV files is
something that people would want to deal with from a perl program, and
something that, in fact, often gets asked here.

All the people who assumed this, including me, could be wrong, and you
could be right, but then I'd say to the OP: There's nothing special
about files in CVS that have quotes in them. If you have quotes in the
file names in CVS, deal with them as your OS wants you to deal with
them. No Perl content there whatsoever.

Martien
-- 
Martien Verbruggen              | The Second Law of Thermodenial: In
Interactive Media Division      | any closed mind the quantity of
Commercial Dynamics Pty. Ltd.   | ignorance remains constant or
NSW, Australia                  | increases.


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

Date: Fri, 06 Apr 2001 13:42:00 -0400
From: jlm <jlm@cca-int.com>
Subject: Backtic-Escape help needed
Message-Id: <3ACDFFE8.491CFE3B@cca-int.com>

I'm trying to search a directory and it's sub-directory's for a string
and print out the file names containing that string.
On the command line I can:      find . type f -exec grep -l string {} \;

I'm having trouble carrying that over to perl. I want to send the
results to an array but can't seem to get it right. Here's what I'm
trying:
@farr = `find . -type f -exec grep -l string {} \;`;
I can't seem to get the escaping right.
Is it possible - maybe there's a better way - can somebody help please?
Thank You!



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

Date: Fri, 06 Apr 2001 17:57:00 GMT
From: sjs@linux.ca (Steven Smolinski)
Subject: Re: Backtic-Escape help needed
Message-Id: <slrn9cs5qb.1dn.sjs@ragnar.stevens.gulch>

jlm <jlm@cca-int.com> wrote:
> I'm trying to search a directory and it's sub-directory's for a string
> and print out the file names containing that string.

I'd use File::Find for the directory traversal.  Whether you open a
new shell for system(grep) on each file or do it yourself in perl is up 
to you.

> On the command line I can:      find . type f -exec grep -l string {} \;

I assume that "type" is "-type".

> I'm having trouble carrying that over to perl. I want to send the
> results to an array but can't seem to get it right.

Another tack is to try find2perl.  (I don't really like its output that 
much, but it's usually a good place to start if you're stuck.)  From the 
manpage:

       find2perl is a little translator to convert find command
       lines to equivalent Perl code.  The resulting code is typ-
       ically faster than running find itself.

Steve
-- 
Steven Smolinski => http://www.steven.cx/


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

Date: Fri, 06 Apr 2001 16:32:50 -0000
From: c_cruizer@my-deja.com_nospam (Cosmic Cruizer)
Subject: bare block usage
Message-Id: <Xns907B610E29D78ccruizermydejacom@207.126.101.100>

I've been reading up on using bare block statements and I have to question 
it's redundant use. It seems to me that using either do-while or do-until 
would be much clearer when it comes to reading the code. I've been looking 
through examples of code, but have not seen any that uses bare blocks.

My questions: Does anybody here use bare blocks and why? Is there a 
specific situation where bare blocks might be better then using a do-while 
or do-until? Any other benefits or drawbacks?

Thanks for any input.

Cos


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

Date: Fri, 6 Apr 2001 09:18:17 -0400
From: "Nathan Pertuset" <npertuset@hotmail.com>
Subject: Bot Script
Message-Id: <Enjz6.184$2a3.5175@newscontent-01.sprint.ca>

I"m creating a script for my bot to write to a file on command, example, if
i type(this is the usual format: ) <mybotnick>, <word> is <def> .. it will
write to the file like: Word - Def.... i can't even seem to get it writing
to the file, and, after i do get it writing to the file, how cna i see if
that word already exists, and tehn overwrite it? if someone could help me
out, that would help a lot. thanks




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

Date: 6 Apr 2001 13:26:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Bot Script
Message-Id: <9akg5u$t8h$2@mamenchi.zrz.TU-Berlin.DE>

According to Nathan Pertuset <npertuset@hotmail.com>:
> I"m creating a script for my bot to write to a file on command, example, if
> i type(this is the usual format: ) <mybotnick>, <word> is <def> .. it will
> write to the file like: Word - Def.... i can't even seem to get it writing
> to the file, and, after i do get it writing to the file, how cna i see if
> that word already exists, and tehn overwrite it? if someone could help me
> out, that would help a lot. thanks

These are very elementary questions (which doesn't mean easy-to-solve).
I don't think you should be working on something as complex as an
IRC bot with that kind of programming experience.  Do something easier
first, and buy a good book or two on Perl.

If you *must* have a bot now, check out http://www.infobot.org or
http://infobot.sourceforge.net for infobot.  It does exactly what
you want and more.

Anno


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

Date: Fri, 6 Apr 2001 09:38:42 -0400
From: "Nathan Pertuset" <npertuset@hotmail.com>
Subject: Re: Bot Script
Message-Id: <OGjz6.187$2a3.5167@newscontent-01.sprint.ca>

i do have a good bit of Perl experience. I have written 2-3 bots.. my latest
one is fully successful, and works exactly like i want it to. It controls 3
different databases, 1 being a user one. I'm just *not* that experienced
with files. i was just asking someone to help me :D
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:9akg5u$t8h$2@mamenchi.zrz.TU-Berlin.DE...
> According to Nathan Pertuset <npertuset@hotmail.com>:
> > I"m creating a script for my bot to write to a file on command, example,
if
> > i type(this is the usual format: ) <mybotnick>, <word> is <def> .. it
will
> > write to the file like: Word - Def.... i can't even seem to get it
writing
> > to the file, and, after i do get it writing to the file, how cna i see
if
> > that word already exists, and tehn overwrite it? if someone could help
me
> > out, that would help a lot. thanks
>
> These are very elementary questions (which doesn't mean easy-to-solve).
> I don't think you should be working on something as complex as an
> IRC bot with that kind of programming experience.  Do something easier
> first, and buy a good book or two on Perl.
>
> If you *must* have a bot now, check out http://www.infobot.org or
> http://infobot.sourceforge.net for infobot.  It does exactly what
> you want and more.
>
> Anno




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

Date: Fri, 6 Apr 2001 23:13:13 +1000
From: "hAWK" <user@home.com>
Subject: can Perl be used to draw tables or lines on the screen in UNIX??
Message-Id: <9akfof$9am$1@bugstomper.ihug.com.au>

If so, could you please direct me to a good tutorial site.
Thanks




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

Date: Fri, 6 Apr 2001 17:12:27 +0100
From: "John Plaxton" <19wlr@globalnet.co.uk>
Subject: re: CGI perl/php/ePerl
Message-Id: <tcrqjunhr0srea@xo.supernews.co.uk>

Anyone got any suggestions/comments (useful ones please)

When should one use eperl and when pure perl cgi, and how does eperl compare
with php?

I've got to quote on a site which might get quite busy. I want to use mysql.







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

Date: Fri, 6 Apr 2001 14:39:49 GMT
From: Phil Shean <philip.shean@uwe.ac.uk>
Subject: Copying Directories
Message-Id: <3ACDD49C.5E5A498@uwe.ac.uk>

Hi All,

Is it possible to copy a directory complete with all it's contents (inc
sub-dirs)?

Thanks for any help on this one.

Cheers

Phil



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

Date: Fri, 6 Apr 2001 10:51:48 -0400
From: "Nathan Pertuset" <npertuset@hotmail.com>
Subject: Re: Copying Directories
Message-Id: <kLkz6.291$2a3.5609@newscontent-01.sprint.ca>

system("cp <dir> <dest>"); # no < >...
"Phil Shean" <philip.shean@uwe.ac.uk> wrote in message
news:3ACDD49C.5E5A498@uwe.ac.uk...
> Hi All,
>
> Is it possible to copy a directory complete with all it's contents (inc
> sub-dirs)?
>
> Thanks for any help on this one.
>
> Cheers
>
> Phil
>




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

Date: Fri, 6 Apr 2001 10:52:50 -0400
From: "Nathan Pertuset" <npertuset@hotmail.com>
Subject: Re: Copying Directories
Message-Id: <jMkz6.293$2a3.5494@newscontent-01.sprint.ca>

oops, that's for linux, if you on win, use copy instead of cp
"Nathan Pertuset" <npertuset@hotmail.com> wrote in message
news:kLkz6.291$2a3.5609@newscontent-01.sprint.ca...
> system("cp <dir> <dest>"); # no < >...
> "Phil Shean" <philip.shean@uwe.ac.uk> wrote in message
> news:3ACDD49C.5E5A498@uwe.ac.uk...
> > Hi All,
> >
> > Is it possible to copy a directory complete with all it's contents (inc
> > sub-dirs)?
> >
> > Thanks for any help on this one.
> >
> > Cheers
> >
> > Phil
> >
>
>




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

Date: Fri, 6 Apr 2001 15:11:26 GMT
From: Phil Shean <philip.shean@uwe.ac.uk>
Subject: Re: Copying Directories
Message-Id: <3ACDDC03.21E875AA@uwe.ac.uk>

>
> > system("cp <dir> <dest>"); # no < >...

So, example would be ....(NT system)

system("copy c:\electures\m-evans\objects c:\electures\m-evans\old\objects");

Is that correct?

Cheers or the help

Phil.




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

Date: Fri, 6 Apr 2001 15:11:44 GMT
From: Phil Shean <philip.shean@uwe.ac.uk>
Subject: Re: Copying Directories
Message-Id: <3ACDDC16.137AC9FC@uwe.ac.uk>

>
> > system("cp <dir> <dest>"); # no < >...

So, example would be ....(NT system)

system("copy c:\electures\m-evans\objects c:\electures\m-evans\old\objects");

Is that correct?

Cheers or the help

Phil.




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

Date: Fri, 6 Apr 2001 11:47:38 -0400
From: "Nathan Pertuset" <npertuset@hotmail.com>
Subject: Re: Copying Directories
Message-Id: <Hzlz6.306$2a3.5713@newscontent-01.sprint.ca>

that should work Phil....

"Phil Shean" <philip.shean@uwe.ac.uk> wrote in message
news:3ACDDC03.21E875AA@uwe.ac.uk...
> >
> > > system("cp <dir> <dest>"); # no < >...
>
> So, example would be ....(NT system)
>
> system("copy c:\electures\m-evans\objects
c:\electures\m-evans\old\objects");
>
> Is that correct?
>
> Cheers or the help
>
> Phil.
>
>




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

Date: Fri, 06 Apr 2001 19:01:09 +0200
From: h.m.brand@hccnet.nl (H. Merijn Brand)
To: comp.lang.perl.misc
Subject: Re: Help needed compiling DB_File on HP-UX 11
Message-Id: <Xns907BC179819E0Merijn@192.0.1.90>

daniel.cutter@polizei.brandenburg.de wrote in
<9akbv3$bk9$1@news.netmar.com>: 

>I’m administering an Intranet-Server on HP-UX 11 with perl 5.005_03. The
>large amount of data on the server is making the installation of a search
>engine necessary. I’ve decided to use perlfect search, as it’s written in
>perl.
>
>to get their I need Berkeley DB and DB_File. I got Berkeley DB version
>3.2.9 from the sleepycat web site and compiled it, as recommended in the
>DB_File (1.76) documentation with the +z compiler switch. The library is
>called libdb.sl. When compiling DB_File though, I got an error from ld,
>that I don’t know how to handle:
>
>LD_RUN_PATH="/usr/local/BerkeleyDB.3.2/lib" ld -o
>blib/arch/auto/DB_File/DB_File.sl  -b version.o DB_File.o    -L/usr/local/
>BerkeleyDB.3.2/lib -ldb
>ld: (Warning) At least one PA 2.0 object file (version.o) was detected.
>The linked output may not run on a PA 1.x system.
>ld: Invalid loader fixup in text space needed in output file for symbol
>"$000000DC" in input file "/usr/local/BerkeleyDB.3.2/lib/lib
>db.sl(env_open.o)"
>*** Error exit code 1

Does my previous help to someone else help:

1: Does anyone know if DB_File is standard in both the UNIX and win32
>versions of Perl?
>2: Can I upload/download/move, etc. DB_File files? And how should I
>upload/download? ASCII/Binary...
>
>Maarten

The perl interface DB_File is standard, its target DB is not, but can be
downloaded at ftp://ftp.sleepycat.com/pub

DB_File module docs state it will build on both version 2 (latest is 2.7.7)
and 3 (latest is 3.0.55) of BerkelyDB, but on my HP-UX 11.00 it will not
run on version 3 due to a missing db_open call (which indeed is missing
in version 3). It builds fine on version 2.

Notes for HP-UX:
DB_File needs a shared version of libdb (for my current configuration
of perl5.00503). Default building version 2 makes a static library that
cannot be used by DB_File. On db-2.7.7:
    	# env CFLAGS="-Ae +O2 +Onolimit +Z" ../dist/configure
    	# make libdb.a
    	# ld -b -o libdb.sl *.o
    	# make install
    	# mv libdb.sl /usr/local/lib
    	# rm /usr/local/lib/libdb.a
Change locations where needed


-- 
H.Merijn Brand           Amsterdam Perl Mongers 
(http://www.amsterdam.pm.org/)
using perl-5.005.03, 5.6.0, 5.6.1, 5.7.1 & 623 on HP-UX 10.20 & 11.00, AIX 
4.2
   AIX 4.3, WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.022 &/| DBD-
Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/


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

Date: Fri, 06 Apr 2001 14:12:35 GMT
From: "John Doe" <joeybach@127.0.0.1>
Subject: Re: How can I use  a var as part of a regex pattern
Message-Id: <n9kz6.39873$Lz6.7139659@typhoon.tampabay.rr.com>

Thanks to all  for the advice. It helped me out alot. 

In article <Mi%y6.34542$z4.6682441@typhoon.tampabay.rr.com>, "John Doe"
<joeybach@127.0.0.1> wrote:


> What I need to do is match a number of strings within a string . The
> code I have subs the querry to the what I believe is the right  syntax
> (it works with hard coded values). But how can I use a variable as my
> matching pattern. Like $string = "/line/im && /sep/im"
> if ($_ =~ m$string){print}
> The actual code I am using is :
> #!/usr/bin/perl
> open (TEST, "<cisco.log");
> my $string = (<STDIN>);
> chomp $string;
> $string =~ s/ /\/im \&\& \//g;
> print "/$string/im\n";
> while (<TEST>){
> 	if ($_ =~ m/\Q$string\e/im){
> 	print "$_\n";
> 
> 	}
> 	}


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

Date: 06 Apr 2001 06:38:42 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: maximum value of a list
Message-Id: <m1n19uf8rh.fsf@halfdome.holdit.com>

>>>>> "Alun" == Alun Moon <alun.moon@unn.ac.uk> writes:

Alun> (Off topic reply, but I couldn't resist)
Alun> merlyn@stonehenge.com (Randal L. Schwartz) writes:
>> It pays to look into the CPAN from time to time.  List::Util has been
>> there for many moons.
Alun> There's not that many of my family using Perl...
Alun> cheers
Alun> 	Alun Moon
Alun> 	:-)

If you make any joke about Black[1] now, we'll have to take it outside...

:-)


[1] "Schwar[t]z" is "Black" in german... a made up name, changed from
    Von Schraeder by my grandfather when he came from Germany to the
    States before the turn of the century, for reasons the rest of us
    still haven't figured out.  So I'm not related to *any* other people
    with the name Schwartz except my immediately family.
-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Fri, 06 Apr 2001 16:47:13 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: modify [not replace] code of a routine at runtime?
Message-Id: <3ACDE500.39BCC48D@schaffhausen.de>

usenet@dbedge.com schrieb:
> 
> After coming up empty on my search of the comp.lang.perl.misc list archives,
> a
> quick run the FAQ and checking the O’Reilly collection I turn to clpm…
> 
> At runtime or compile time, I would like to get access to the source code, or
> op-codes for a sub routine.  I have access to the symbol table at run time
> and can check if a routine exists with:
> 
> print “$method\n”
> if eval (“defined( *” . $class . “::” . $method . “{CODE})”)
> 

Couldnt whatever decides to replace a subroutine set a parameter instead which
makes the routine behave differently?

->malte


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

Date: 06 Apr 2001 17:55:10 +0100
From: nobull@mail.com
Subject: Re: modify [not replace] code of a routine at runtime?
Message-Id: <u93dbmq87l.fsf@wcl-l.bham.ac.uk>

usenet@dbedge.com writes:

> At runtime or compile time, I would like to get access to the source code, or
> op-codes for a sub routine.

You can decompile code using coderef2text() method from B::Deparse (or
recent versions of Data::Dumper).

> Ideally, I could prepend or append a block of code into the existing
> routine on the fly.

Recompiling decompiled code will not generally work because of
variable scoping issues.

You can prepend/append to a subroutine like this:

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

use AtExit;

# Or if you want to roll you own AtExit
# sub My_AtExit::DESTROY { &{$_[0][0]} }

sub wrap_func {
    my ($func,$prependage,$appendage) = @_;  
    my $old_routine = \&$func;
    no warnings 'redefine';
    *$func = sub {
        my $atexit;
	$atexit = AtExit->new($appendage)
	    if $appendage;
	# $atexit = bless [ $appendage ], 'My_AtExit'
	#     if $appendage;
	&$prependage if $prependage;
	goto &$old_routine;
    }
}

sub foo { print "foo\n" }

wrap_func(\*foo,
	  sub { print "pre-foo\n" },
          sub { print "post-foo\n"}
);

foo();

__END__

Allowing the $appendage code to intercept the return value cannot
AFAIK be done without creating an extra stack frame, which is probably
OK so long as the subroutine doesn't use caller().  You also have to
take care to propagate the list/scalar/void context.

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


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

Date: Fri, 06 Apr 2001 15:25:23 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Most efficient way to extract unique array elements?
Message-Id: <gbfrctcrmdnvivd8ntol7tgt3jsh49452v@4ax.com>

On Sun, 01 Apr 2001 04:52:14 GMT, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:

[ snip of variations on answers given in perlfaq4 by various people ]

> Of course, the *best* way to do this, is to define a subroutine.
                 ^^^^^^

Does that include the syntax and semantic errors?

> sub unique { my %hash; @hash(@_) = (); keys %hash }
                              ^  ^
	sub unique { my %hash; @hash{ @_ } = (); keys %hash }
> 
> my @result = sort unique @array1;
                    ^^^^^^
That is treated as the sort-sub, you'll need to disambiguate:

	my @result = sort +unique @array1;

Please test your code before you claim it's the *best*.

-- 
Good luck,
Abe
perl -e '$_=sub{split//,pop;print pop while@_};&$_("rekcah lreP rehtona
 tsuJ")'


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

Date: Fri, 06 Apr 2001 11:23:07 -0500
From: Chris <cpryce@pryce.net>
Subject: Re: newbie: DBI:ODBC and M/S SQL Server
Message-Id: <B6F3579B.279B%cpryce@pryce.net>

in article tcp2mn12vs5v15@corp.supernews.com, David J. Marcus at
djmarcus@ex-pressnet.com wrote on 04/05/2001 10:10 AM:

> When I list the available ODBC drivers (using example in Programming the
> Perl DBI book), it shows:
> 
> Driver: ODBC
>       Data Source is DBI:ODBC:Visual FoxPro Database
>       . . .
>       Data Source is DBI:ODBC:TestDB
>       . . .
> 
> So I know that the ODBC connection is there.
> 
> In my test program I:
>       my $conn = DBI->connect( "dbi:ODBC:DSN=TestDB", 'sa', ''') or die...
>       my $sth = $conn->prepare( " CREATE TABLE ..."} or die...
>       $sth->execute or die...
> 
> The connect fails with the following error message:
>   DBI->connect(DSN=TestDB) failed: [Microsoft][ODBC Driver Manager] Data
> source name not found and no default driver specified (SQL-IM002)(DBD:
> db_login/SQLConnect err=-1)
> 
> I am suspecting that I am not specifying the DSN properly.

I suspect (although I can't say for certain, having never worked with perl
in win32) that you are correct. If the example script lists:

>       Data Source is DBI:ODBC:TestDB

Then I would try that in my connect string, as in:

my $conn = DBI->connect( "dbi:ODBC:TestDB", 'sa', ''') or die...

Also, keep in mind that the Programming the DBI book is wonderful, but it
only covers DBI::ODBC version 2.0. Current is 2.8 (?) and includes a few
significant changes.

cp




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

Date: Fri, 06 Apr 2001 09:33:17 -0400
From: RayJ <rayj00@yahoo.com>
Subject: parsing question...
Message-Id: <3ACDC59D.9080403@yahoo.com>

To make it simple, I want to parse
values in the form of "ab cd ef gh...etc"
I may want to look at "a" alone or "ab"
as a whole and make decisions based on
the values of either. The same for the
rest of the inputs.

Is that a better example?

Thanks,

Ray



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

Date: Fri, 6 Apr 2001 09:07:42 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: parsing question...
Message-Id: <slrn9crfsu.mad.tadmc@tadmc26.august.net>

RayJ <rayj00@yahoo.com> wrote:
>To make it simple, I want to parse
>values in the form of "ab cd ef gh...etc"
>I may want to look at "a" alone or "ab"
>as a whole and make decisions based on
>the values of either. The same for the
>rest of the inputs.


Assuming your string is in $_:

   foreach ( split ) {
      my($char1, $char2) = /(.)(.)/;

      # do stuff with $_, $char1 and $char2...
   }


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


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

Date: 6 Apr 2001 13:08:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: parsing question
Message-Id: <9akf3k$t8h$1@mamenchi.zrz.TU-Berlin.DE>

According to RayJ  <rayj00@yahoo.com>:
> How would I parse input in this form:
> 
> 0a 3f bb 23 b7......etc.
> 
> Now, the input is obviously in hex.
> I need to be able to take the 0a for example,
> and be able to manipulate either the 0 or the a
> as well as the 0a as a whole. By manipulate,
> I mean us the field for indexing, addressing,
> etc.

It is still not very clear what you want to do.  It looks like
unpack() could be of use.
 
> Also, I need to do a hex to binary and decimal conversion.

For this, see sprintf.

Anno


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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