[18076] in Perl-Users-Digest
Perl-Users Digest, Issue: 236 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 7 18:11:06 2001
Date: Wed, 7 Feb 2001 15:10:37 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981587436-v10-i236@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 7 Feb 2001 Volume: 10 Number: 236
Today's topics:
ANNOUNCE: Tie::SentientHash 0.54 andrew@icarus.demon.co.uk
Announce: WWWdb-0.8.1 <K.Reger@gmx.de>
Re: Can't locate URI/Escape.pm in @INC <jamie.oshaughnessy@ntlworld.com>
Re: Cannot Decrement in For Loop? <grichard@uci.edu>
Re: convert HTML results to XML?? jgs2283@my-deja.com
Converting nested hashes to objects (Sameer Vadakke-Kuruppath)
Re: Embedding perl Lee.Lindley@bigfoot.com
Re: Fastest way of left-padding a number? (Abigail)
Re: Fastest way of left-padding a number? <jll63@easynet.be>
Re: Hashes aramis1631@my-deja.com
Re: Help with calling functions from dynamic/shared lib <jeff_nokes@yahoo.com>
Re: help with multiple if statements ? <mischief@velma.motion.net>
Re: help with multiple if statements ? <ccx138@coventry.ac.uk>
Re: hex to binary conversion ? Please help (Peter J. Acklam)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Feb 2001 23:02:36 -0000
From: andrew@icarus.demon.co.uk
Subject: ANNOUNCE: Tie::SentientHash 0.54
Message-Id: <t83l0c8pu3jm7a@corp.supernews.com>
I have just uploaded version 0.54 of Tie::SentientHash to CPAN:
http://www.cpan.org/authors/id/A/AN/ANDREWF/Tie-SentientHash-0.54.tar.gz
NAME
Tie::SentientHash - Perl module implementing intelligent objects
SYNOPSIS
use Tie::SentientHash;
tie %hash, 'Tie::SentientHash', $meta_data, $initial_data;
$hashref = Tie::SentientHash->new($meta_data, $initial_data);
$modified = $hashref->modified($key [, $bool])
$untiedhash = $hashref->export;
$metadata = $hashref->_metadata;
$modified = $hashref->_modified;
$hashref->{key} = 'value';
$hashref->{key1}{key2} = $value;
$value2 = $hashref->{key};
undef $hashref;
DESCRIPTION
The `Tie::SentientHash' package provides intelligent objects. The
objects are represented as hashes which:
* provide read-only elements
* provide 'special' elements that are handled by user-supplied
functions
* disallow changes to the data as specified by metadata
* track changes and call a 'commit changes' function when the object
is destroyed
References to scalars, arrays, hashes and objects can be stored in hash
elements in which case the referenced object is tied to an internal
class of the appropriate type (Tie::SentientHash::NestedHash,
::NestedArray or ::NestedScalar), so that changes to the nested data
structures can be tracked.
The constructor is invoked with two hash references: the first contains
metadata and the second the initial data values. The metadata hash may
contain the following flags:
READONLY
a list of hash entries that are read-only (read-only elements cannot
be modified -- except by special element handlers -- or deleted and
are not deleted when the CLEAR method is called)
SPECIAL
a hash of name/subroutine-refs pairs that specifies elements that
are handled specially (special elements also cannot be deleted). The
user function is called both for STORE (with four arguments) and for
FETCH (with three arguments). The arguments are: a reference to the
metadata hash, a reference to the data hash, the element key and if
the funtion is being called for a STORE operation, the value to be
stored. SPECIAL elements can be used to implement calculated
attributes.
TRACK_CHANGES
flag to indicate that the class should keep track of the keys of
modified (top-level) hash elements
COMMIT_SUB
a reference to a subroutine to commit changes (called with a
reference to the data hash and a reference to the metadata hash)
FORBID_INSERTS
forbid inserts into hash and sub-hashes/arrays
FORBID_DELETES
forbid deletes from hash
FORBID_CHANGES
forbid any changes
Trying to change an object in a way that is forbidden by the metadata
will cause the module to croak.
Changes are only tracked at the top level.
The API is as follows:
tie %hash, 'Tie::SentientHash', $meta_data, $initial_data
Functional interface to create a new sentient hash. $meta_data
describes the properties of the sentient hash (as outlined above)
and $initial_data is the initial content of the sentient hash.
Tie::SentientHash->new($meta_data, $initial_data)
Object oriented constructor for a sentient hash.
$hashref->modified([$key [, $bool]])
If called with no arguments in a scalar returns an indication of
whether the sentient hash has been modified. If called with no
arguments in an array context returns the list of elements that have
been modified. Otherwise queries or sets the modification status of
a specific top level element.
$untiedhash = $hashref->export
Creates an "untied" copy of the sentient hash.
If a commit function is specified when the sentient hash is created it
will be called when the destructor is called (normall when it is
garbage-collected).
EXAMPLE
I use Tie::SentientHash as the basis for implementing persistent objects
in my CGI/mod_perl scripts. The details of reading and writing the
objects from and to the database is handled by a class, but neither the
class nor the high level code needs to keep track of whether the object
has been changed in any way.
For example if you had a pay per view system of some kind you could have
a script that contained the following fragment:
sub pay_per_view ($$) {
my($cust_id, $cost) = @_;
my $cust = load Customer $cust_id;
$cust->{CREDIT} -= $cost;
}
The customer object would be implemented in a module sketched out below.
A commit function is specified on the call to create a new sentient
object, and that function will be called when $cust goes out of scope at
the end of the pay_per_view function and can write the modified object
back to the database. If none of the attributes had been modified then
the commit function would not be invoked.
package Customer;
sub load ($$) {
my ($class, $cust_id) = @_;
my $data = {};
# read customer data from a database into $data
my $meta = { COMMIT_SUB => \&_commit,
READONLY => [ qw( CUST_ID ) ],
FORBID_INSERTS => 1 };
return bless Tie::SentientHash->new($meta, $data), $class;
}
sub _commit ($$) {
my ($meta, $data) = @_;
# As we have been called, something has changed. The names of
# the modified fields are the keys of $meta->{MODIFIED}. We had
# better write the data back out to the database.
}
RESTRICTIONS
Full array semantics are only supported for Perl version 5.005.
Starting with version 0.54 blessed objects may be stored in the
*sentient hash*, however this functionality is experimental, has not
been exhaustively tested, may not work, and may be subject to change.
Use at your own peril!
Tie::SentientHash ties nested elements to internal subclasses so it can
track changes. If you keep references to such elements and modify them
directly then Tie::SentientHash may not be aware of the changes.
Objects of classes that use the tie mechanism may not work when stored
in a sentient hash.
If you use an object as the data for a new sentient hash, then the hash
will not be re-blessed, i.e. if $object is an object then after
$href = Tie::SentientHash->new($meta, $object);
$href will be blessed in the same class as $object. This means you
cannot use the `modified' or `export' methods on $href. However you can
use them on the tied array, e.g.:
@keys = (tied %$href)->modified;
$newhash = (tied %$href)->export;
As Tie::Sentient recursively ties nested elements to internal subclasses
it may not be very efficent on large, deeply nested data structures. (If
I find the time I may provide a C implementation that would be faster in
this regard).
AUTHOR
Andrew Ford <A.Ford@ford-mason.co.uk>
Please let me know if you use this module.
SEE ALSO
perl(1).
COPYRIGHT
Copyright 1999-2001 Andrew Ford and Ford & Mason Ltd. All rights
reserved.
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
Enjoy
Andrew
--
Andrew Ford, Director Ford & Mason Ltd Tel: +44 1531 829900
A.Ford@ford-mason.co.uk South Wing, Compton House Fax: +44 1531 829901
http://www.ford-mason.co.uk Compton Green, Redmarley Mobile: +44 7785 258278
http://www.refcards.com Gloucester, GL19 3JB, UK
------------------------------
Date: Wed, 07 Feb 2001 23:01:46 -0000
From: Klaus Reger <K.Reger@gmx.de>
Subject: Announce: WWWdb-0.8.1
Message-Id: <t83kuqp9gfp868@corp.supernews.com>
Managing Web-Sites with a powerful database in the background ...
that is WWWdb.
WWWdb is a powerful developing-tool for web-applications, that are
based on a SQL database. You can browse and modify any data stored in
database-tables and display them in a format, you like. If you own a
Palm-PDA, you can downlaod the selected data directly to your
device. To check, that the data-integrity is kept, you can plug in
Perl-scripts, that guarantee that only correct data is inserted in
your database.
WWWdb handles WWW-connections as sessions and you can login and setup
your own session. Everytime you come back, your last session can be
continued. Because it is password-protected, no cookies are needed.
To link the single WWWdb-applications together, a navigation hierarchy
connects the applications, as well as the possibility to search them
by predefined words, using a search-engine. With an
applications-wizard you can create and modify WWWdb-applications over
the web on the fly.
At the moment, four databases PostgreSQL, Oracle, InterBase, MySQL and
ODBC are supported.
WWWdb is also internationalized! You can set the language for every
Session-Id separateley.
NEW in the actual Version (0.8.1):
New databases: InterBase and ODBC
Better and customizable support of date-fields for the different
database-types
SSL-encryption
Separation of layout and program-logic
Better import- and export-support for database-data
WWWdb is distributed as a gzipped tar-ball.
It includes all sources, of the software as well as the
configuration-files
and the corresponding perl-plugins. The .po-Files for
internationalisation
are also included.
The contents of the database are kept in database-description-files and
the corresponding export-/import-files, ready for importing in one of
the
supported databases.
You can download the actual version(0.8.1) of WWWdb at:
http://download.sourceforge.net/wwwdb/WWWdb-0.8.1.tar.gz
If you need the additional perl-modules, WWWdb does rely on, you can
find them at:
http://download.sourceforge.net/wwwdb/WWWdb-contrib-0.8.1.tar.gz.
I have separated them, because I dont to waste internet-bandwidth.
Of course, you can find these modules at the usual CPAN -archives.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 07 Feb 2001 19:14:26 +0000
From: Jamie O'Shaughnessy <jamie.oshaughnessy@ntlworld.com>
Subject: Re: Can't locate URI/Escape.pm in @INC
Message-Id: <3c738t8mmre10rchedq0d8nr8r5bbgucfm@4ax.com>
Justin,
Humm, strange problem you have there. It's complaining it can't find
some header files (.h), all of which seem to be standard
system/library ones at a glance. What distribution are you running?
Maybe you don't have these installed for some reason - I can't imagine
why as you wouldn't be able to build anything at all?
Have you sorted this out yet?
Jamie
On Wed, 24 Jan 2001 12:43:43 GMT, "Justin Kuo" <jkuo@bellatlantic.net>
wrote:
>Jamie O'Shaughnessy" <jamie.oshaughnessy@ntlworld.com> wrote in message
>news:c8uf6t02ijtmmnipsbeqors1gi1mchfhao@4ax.com...
>>
>> Not sure if URI::Escape is part the libwww group of modules, so you
>> should have this (maybe not though).
>>
>> Read up about the CPAN module. This is a module that will help you
>> download, build, test and install modules from CPAN. Run it doing
>> something like:
>>
>> perl -MCPAN -e shell
>>
>> It may then be as simple as "installl URI::Escape".
>>
>> Jamie
>>
>> On Fri, 19 Jan 2001 05:25:45 GMT, "Justin Kuo" <jkuo@bellatlantic.net>
>> wrote:
>>
>> >I'm completely new to perl/CGI and need a little help getting my program
>to
>> >work in my Apache server's cgi-bin.
>> >
>> >I'm installed the "tree.pl" routine available at:
>> >
>> > <http://www.ev-stift-gymn.guetersloh.de/server/tree_e.html>
>> >
>> >When I attempt to run the program as a cgi in a browser, I got an
>Internal
>> >Server error. The error log gave me this message:
>> >
>> >Can't locate URI/Escape.pm in @INC (@INC contains:
>> >/usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503
>> >/usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005
>.)
>> >at /home/jkuo/www/cgi-bin/tools/tree.pl line 153.
>> >BEGIN failed--compilation aborted at /home/jkuo/www/cgi-bin/tools/tree.pl
>> >line 153.
>> >[Thu Jan 18 21:57:53 2001] [error] [client 192.168.1.4] Premature end of
>> >script headers: /home/jkuo/www/cgi-bin/tools/tree.pl
>> >
>> >What can I do to correct the problem? Is my perl application on my Linux
>> >machine missing a module? If so, how do I install the module? I
>appreciate
>> >any help. Thank you. -- Justin
>> >
>>
>
>
>After reading Jamie's message I attempted to learn how to use CPAN to
>install/upgrade my Perl software on my Linux machine. I had to install sudo,
>and figure out how to configure CPAN to get it working properly. I'm still a
>novice and need some help.
>
>There are a lot of messages that zip by me when I run an install. I can
>capture them. Some make sense, others are confusing. Should I review all of
>them?
>
>As an example, I tried to install the Perl GD.pm Module to be used with the
>HAMweather Pro CGI scripts. (http://www.hamweather.com/). I started CPAN and
>asked it to install GD. I have included a log below. When the install
>finished, it reported these errors:
>
> "Can't test without successful make"
>
> "make had returned bad status, install seems impossible"
>
>Would you let me know what I should look for in order to install
>successfully?
>
>Thanks. -- Justin Kuo <kuo@world.std.com>
>
>----- begin log -----
>
>sudo perl -MCPAN -e shell
>
>cpan> install GD
>Running install for module GD
>Running make for L/LD/LDS/GD-1.32.tar.gz
>CPAN: Net::FTP loaded ok
>Fetching with Net::FTP:
> ftp://carroll.cac.psu.edu/pub/CPAN/authors/id/L/LD/LDS/GD-1.32.tar.gz
>Couldn't login on carroll.cac.psu.edu at /usr/lib/perl5/5.00503/CPAN.pm line
>207
>2.
>Fetching with Net::FTP:
> ftp://cpan.in-span.net/authors/id/L/LD/LDS/GD-1.32.tar.gz
>Fetching with Net::FTP:
> ftp://cpan.in-span.net/authors/id/L/LD/LDS/CHECKSUMS
>Checksum for
>/home/jkuo/.cpan/CPAN/sources/authors/id/L/LD/LDS/GD-1.32.tar.gz ok
>GD-1.32/
>GD-1.32/t/
>[snip]
>GD-1.32/Makefile.PL
>GD-1.32/README
>
> CPAN.pm: Going to build L/LD/LDS/GD-1.32.tar.gz
>
>NOTICE: This module requires libgd 1.8.3 or higher (shared library version
>4.X).
>
>Please choose the features that match how libgd was built:
>Build JPEG support? [y]
>Build FreeType support? [y]
>Build XPM support? [y]
>
>If you experience compile problems, please check the @INC, @LIBPATH and
>@LIBS
>arrays defined in Makefile.PL and manually adjust, if necessary.
>
>Checking if your kit is complete...
>Looks good
>Writing Makefile for GD
>mkdir blib
>mkdir blib/lib
>mkdir blib/arch
>mkdir blib/arch/auto
>mkdir blib/arch/auto/GD
>mkdir blib/lib/auto
>mkdir blib/lib/auto/GD
>mkdir blib/man3
>cp patch_gd.pl blib/lib/patch_gd.pl
>cp GD.pm blib/lib/GD.pm
>AutoSplitting blib/lib/GD.pm (blib/lib/auto/GD)
>cp qd.pl blib/lib/qd.pl
>/usr/local/bin/perl -I/usr/lib/perl5/5.00503/i386-linux -I/usr/lib/perl5/5.0
>0503
> /usr/lib/perl5/5.00503/ExtUtils/xsubpp -object_capi -typemap
>/usr/lib/perl5/5.
>00503/ExtUtils/typemap -typemap typemap GD.xs >xstmp.c && mv xstmp.c GD.c
>cc -c -I/usr/local/include -I/usr/local/include/gd -Dbool=char -DHAS_BOOL -I
>/usr
>/local/include -O2 -DVERSION=\"1.32\" -DXS_VERSION=\"1.32\" -fpic -I/usr/
>lib/
>perl5/5.00503/i386-linux/CORE -DHAVE_JPEG -DHAVE_TTF -DHAVE_XPM GD.c
>In file included from GD.xs:5:
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:307: sys/types.h: No such file
>or directory
>In file included from /usr/lib/perl5/5.00503/i386-linux/CORE/iperlsys.h:203,
> from /usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:325,
> from GD.xs:5:
>/usr/lib/perl5/5.00503/i386-linux/CORE/perlsdio.h:5: stdio.h: No such file
>or directory
>In file included from GD.xs:5:
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:336: ctype.h: No such file or
>directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:344: locale.h: No such file or
>directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:361: setjmp.h: No such file or
>directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:367: sys/param.h: No such file
>or directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:373: stdlib.h: No such file or
>directory
>In file included from GD.xs:5:
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:433: string.h: No such file or
>directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:523: netinet/in.h: No such
>file or directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:527: arpa/inet.h: No such file
>or directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:537: sys/stat.h: No such file
>or directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:566: sys/time.h: No such file
>or directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:573: sys/times.h: No such file
>or directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:580: errno.h: No such file or
>directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:637: sys/ioctl.h: No such file
>or directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:660: dirent.h: No such file or
>directory
>In file included from
>/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/syslimits.h:7,
> from
>/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/limits.h:11,
> from /usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:860,
> from GD.xs:5:
>/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/limits.h:117:
>limits.h:
>No such file or directory
>In file included from /usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:1121,
> from GD.xs:5:
>/usr/lib/perl5/5.00503/i386-linux/CORE/unixish.h:93: signal.h: No such file
>or directory
>In file included from GD.xs:5:
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:1531: math.h: No such file or
>directory
>In file included from GD.xs:5:
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:2543: sys/ipc.h: No such file
>or directory
>/usr/lib/perl5/5.00503/i386-linux/CORE/perl.h:2544: sys/sem.h: No such file
>or directory
>GD.xs:7: gd.h: No such file or directory
>GD.xs:14: stdio.h: No such file or directory
>make: *** [GD.o] Error 1
> /usr/bin/make -- NOT OK
>Running make test
> Can't test without successful make
>Running make install
> make had returned bad status, install seems impossible
>
>cpan>
>
>----- end log -----
>
------------------------------
Date: Wed, 7 Feb 2001 13:51:51 -0800
From: "Gabe" <grichard@uci.edu>
Subject: Re: Cannot Decrement in For Loop?
Message-Id: <95sg5h$6le$1@news.service.uci.edu>
Thanks you all for your help.
Gabe
Gabriel Richards <grichards@endertechnology.com> wrote in message
news:xyOf6.181306$y9.31536460@typhoon.we.rr.com...
> This works fine:
>
> for (my $i=1; $i<$num+1; $i++) {
> my $j = ID('pollans', 'ansid', $dbh);
> $answers{$j} = $cgi->param("ans$i");
> }
>
> The problem is, I need the answers saved in %answers in reverse order so I
> tried this:
>
> for (my $i = $num; $i<1; $i--) {
> my $j = ID('pollans', 'ansid', $dbh);
> $answers{$j} = $cgi->param("ans$i");
> }
>
> But $i is not decrementing (I've tested by printing $i in the loop). Help?
>
> Gabe
> --
> Ender Technology
> Website and Database Development for Small Business
> http://www.endertechnology.com
> 310-532-7455
>
>
------------------------------
Date: Wed, 07 Feb 2001 20:36:56 GMT
From: jgs2283@my-deja.com
Subject: Re: convert HTML results to XML??
Message-Id: <95sbl7$3bf$1@nnrp1.deja.com>
In article <95mmoc$36o$1@nnrp1.deja.com>,
jgs2283@my-deja.com wrote:
> Please be patient with me...I'm new to posting... I am trying to
> search 'search engine' type of sites for keywords that a user types
> in. I'm able to query the sites, but I don't know how to search for
> the keywords. This is the snippet of code that I have that queries
the
> site...
> use LWP;
> use URI::Escape;
>
> $webhost = 'www.whatever.com';
> $webpage = '/results/ResultPage';
> $refpage = '/Main/Mainpage.htm';
>
> $PageUrl = 'http://' . $webhost . $webpage;
> $RefererUrl = 'http://' . $webhost . $refpage;
>
> $ua = LWP::UserAgent->new();
> $ua->agent($UserAgentName);
> $ua->from($FromUser);
> $ua->timeout($Timeout);
>
> $rqst = HTTP::Request->new('GET', $PageUrl);
> $rqst->referer($RefererUrl);
> $rqst->header(%RequestHdrs);
>
> $rspn = $ua->request($rqst);
> $rspn->is_success || print("ERROR!\n");
>
> print "Status: %s\n", $rspn->status_line();
> print "CONTENT====\n%s====\n", $rspn->content();
>
> This is working to get to the site...but how would you search for a
> keyword on a site. For example, altavista.com something of that
> nature... I'm trying to pull results. Also, right now I'm getting the
> page in HTML format, is there a way to put it into XML format? I
would
> appreciate any incite.... thanks in advance!
>
> Sent via Deja.com
> http://www.deja.com/
>
OK...I figured out how to search for keywords, but does anyone know how
to query more than 1 site at a time, and how to convert the returned
results from HTML to XML?
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 7 Feb 2001 21:49:19 GMT
From: svadakke@cochin.qualcomm.com (Sameer Vadakke-Kuruppath)
Subject: Converting nested hashes to objects
Message-Id: <95sfsv$86b$1@coset.qualcomm.com>
Hello,
I'm trying to come up with a maintainable OO solution for a problem and
would appreciate some insights.
I've a config. file looking like this:
{
'valid' => [ 'a', 'b' ],
'a' => {
'valid' => [ 'c', 'd' ],
'c' => {
'valid' => [ 'e', 'f' ],
'e' => 'testing e',
'f' => 'testing f'
},
'd' => 'testing d',
}
'b' => 'testing b',
}
The 'valid' array is used to check the keys. There are other keys at
each level, which I've omitted. There is a whole set (~20) of such
files, and these files are used to configure a Perl/Tk GUI.
One solution uses a class (say MyConfig) and creates an object
containing
the entire config file hash (using 'do'). During traversals and
retrievals from the object, each nested hash is 'blessed' into MyConfig,
in order to access methods.
Another solution is to create a hierarchy of classes, one that is a
'composite' class, and one that is a 'leaf' class. Via inheritance,
re-blessing is not needed to access methods.
Which would be easier to maintain? Performance would be better for the
first, right?
Thanks
--
Sameer
------------------------------
Date: Wed, 07 Feb 2001 19:45:49 GMT
From: Lee.Lindley@bigfoot.com
Subject: Re: Embedding perl
Message-Id: <95s8la$as$1@nnrp1.deja.com>
In article <95s4kh$75u@news.or.intel.com>,
"terminalsplash" <shino_korah@yahoo.com> wrote:
> Hi
> I was trying to embed perl in C.
> I got the following code form a book
[snip embedded perl]
> > when I compile using::
>
> > gcc -o name nameoffile.cpp 'perl -MExtUtils::Embed -e ccopts -e
ldopts'
>
> >
>
> > It says EXTERN.h and perl.h not found.....
Then I suspect that you did not compile your own perl.
>
> >
>
> > In the book it says "to find the EXTERN.H and perl.h type::
>
> > perl -MConfig -e "print $Config{archlib}"
>
> >
>
> > but when i do this it gives an error::
>
> > syntax error at -e..
What do you think your shell did to that dollar sign in double quotes?
>
> >
>
> > Please help me to find those header file paths...
>
> > is there an easier way to embed perl in C???
You seem to be doing the right thing. The perlembed manual page
will serve you as well or better than the chapter from the book.
Now you need to either find out why your perl install is broken
or redo it from scratch yourself. Note that if you did not
compile perl yourself, then at a minimum you will need the same
compiler that was used to build it.
perl -V # will tell you lots of useful stuff about your perl
--
// Lee.Lindley@Bigfoot.com
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 7 Feb 2001 19:38:59 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Fastest way of left-padding a number?
Message-Id: <slrn98392j.258.abigail@tsathoggua.rlyeh.net>
Jean-Louis Leroy (jll63@easynet.be) wrote on MMDCCXVII September MCMXCIII
in <URL:news:m3vgqmidl0.fsf@enterprise.starfleet>:
;; abigail@foad.org (Abigail) writes:
;;
;; > ## Given the choice between two incantations that produce the same
;; > ## result, and are more or less equally readable, I prefer to use the
;; > ## faster one.
;; >
;; > Really? Then, why-oh-why are you using Perl, a language not known to
;; > be particular fast.
;;
;; Ok, make that between two *Perl* incantations. Sorry for indulging in
;; the oh-so-human practice of stating things the way I assume everyone
;; else would understand. So I'd pick the faster one given that
;; everything else remains the same.
But everything else cannot remain the same - if they remained the same,
they would be identical. You are picking between two different things
that produce the same result, and then the faster one.
;; XS are faster but take more effort,
;; are less immediately understandable, or immediately understandable by
;; fewer people, and are less portable, at least between different
;; systems ;-)
So..... what is it? First you say you pick the faster one, as long as
they produce the same result, but now understandability, portability
and effort play a role as well.
Perhaps you should just stick with sprintf.
;; And, agreed, nothing in Perl stops you from writing code that is
;; gratuitiously slower than needs be.
Nothing is there to stop people from doing pointless micro-optimilizations
either.
Abigail
--
perl -wlpe '}$_=$.;{' file # Count the number of lines.
------------------------------
Date: 07 Feb 2001 21:55:11 +0100
From: Jean-Louis Leroy <jll63@easynet.be>
Subject: Re: Fastest way of left-padding a number?
Message-Id: <m3n1byi574.fsf@enterprise.starfleet>
abigail@foad.org (Abigail) writes:
> Perhaps you should just stick with sprintf.
That's what I'll do, but at least now it will be an informed choice.
> Nothing is there to stop people from doing pointless micro-optimilizations
> either.
I didn't know it was a micro-opt yet. It may have turned out that
another way existed, which was as readable, portable, compact, etc,
but faster. I know that I don't know everything about Perl. Why bet on
ignorance?
--
Jean-Louis Leroy
http://users.skynet.be/jll
------------------------------
Date: Wed, 07 Feb 2001 21:10:36 GMT
From: aramis1631@my-deja.com
Subject: Re: Hashes
Message-Id: <95sdk2$59v$1@nnrp1.deja.com>
In article <YFfg6.1503$561.11560@eagle.america.net>,
garry@zvolve.com (Garry Williams) wrote:
> On Wed, 07 Feb 2001 15:39:07 GMT, aramis1631@my-deja.com
> <aramis1631@my-deja.com> wrote:
> >In article <f%4g6.1387$561.8850@eagle.america.net>,
> > garry@zvolve.com (Garry Williams) wrote:
> >> On Wed, 07 Feb 2001 02:52:27 GMT, aramis1631@my-deja.com
> >> <aramis1631@my-deja.com> wrote:
> >>
> >> >In article <95qbrr$cku$1@nnrp1.deja.com>,
> >> > bakor@my-deja.com wrote:
> >>
> >> [snip]
> >>
> >> >> %days_in_month=(Jan,31,Feb,28,Mar,31);
> >> >>
> >> >> $month=`date +%b`;
> >> >> print $month;
> >> >> print $days_in_month($month);
> >> >
> >> >It appears to me, that you have parens (), when you mean to use
curly
> >> >braces {}.
> >>
> >> Nope.
> >>
> >> Braces will produce a reference to an anonymous hash.
> >
> >I do not understand what you mean by this... he was attempting to
> >access a hash incorrectly.
>
> You are quite right.
>
> I thought the comment referred to the construction of the hash instead
> of the (obviously wrong syntax) reference to the hash element.
>
> I even quoted the OP's faulty line. :-(
>
> --
> Garry Williams
Thanks for the clarification, I was startled as I usually find you to
be correct. I should be more careful about specifying the exact line I
am referring to in the future.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 07 Feb 2001 11:10:00 -0800
From: "Jeffry A. Nokes" <jeff_nokes@yahoo.com>
Subject: Re: Help with calling functions from dynamic/shared libraries
Message-Id: <3A819D87.7382D14E@yahoo.com>
Hamish,
I actually haven't tried Dynaloader yet. From the following exerpt from the
Dynaloader documentation ...
---------------------------------
"This document defines a standard generic interface to the dynamic linking
mechanisms available on many platforms. Its primary purpose is to implement
automatic dynamic loading of Perl modules.
This document serves as both a specification for anyone wishing to implement
the DynaLoader for a new platform and as a guide for anyone wishing to use
the DynaLoader directly in an application.
The DynaLoader is designed to be a very simple high-level interface that is
sufficiently general to cover the requirements of SunOS, HP-UX, NeXT, Linux,
VMS and other platforms.
It is also hoped that the interface will cover the needs of OS/2, NT etc and
also allow pseudo-dynamic linking (using ld -A at runtime).
It must be stressed that the DynaLoader, by itself, is practically useless
for accessing non-Perl libraries because it provides almost no Perl-to-C
'glue'. There is, for example, no mechanism for calling a C library
function or supplying arguments. A C::DynaLib module is available from CPAN
sites which performs that function for some common system types. "
--------------------------------------
.. and from other news articles/mail threads I've read, I've kind of gotten
the impression that this works fine on Unix platforms, but is sketchy at
best on Win32. And since I'm trying to find a single method that is
portable to both platforms, I didn't dig any further. Plus, my libraries
are written in C, not Perl.
You are correct in assuming that I want to call functions dynamically from
external, shared libraries (.so / DLL). I actually write a lot of stuff
like this in Visual Basic, just to conceptualize it first and then usually
port it over to C++ or Java. But, I'm on this kick in trying to do it from
Perl and am having trouble figuring it out how to do it. I know I can
update my program (exe) by just updating my libraries, as long as I retain
the API, but am just having trouble finding the right tool in Perl to use.
Have you ever used Dynaloader on Win32? Successfully? I just didn't want
to go down that avenue if it seemed hopeless to begin with. Love to hear
your thoughts.
Regarding your question about static libraries, I'm trying to stay away from
them as much as possible (on this little project anyway), I want to make my
executable as small as possible. So, I cannot provide you any assistance
with your current dilema unfortunately.
Just as a side note, normally, when just creating a utility for my own use,
I usually just link everything in all-togther, making one giant executable.
But this particular project, I'm trying to write some apps for some network
engineer buddies. Since the machies these apps would be running on live in
a remote hosted facility, I was hoping to make any updates to these apps by
just re-installing any associated libraries remotely.
Regards,
- Jeff
jimjim123@my-deja.com wrote:
> Hmm, Dynaloader should enable you to call functions like this. Let me
> see if I'm understanding this correctly... You have a perl progam,
> that calls functions in external shared objects (.so), and you want to
> know if the .so's are updated, if your perl program will still work?
> Is that what you want to know?
>
> Well it should, as long as your perl software calls the function in the
> shared library, and doesn't compile it into a binary and call it
> locally, then it should all be sweet. Yeah, as long as it calls it
> from the external object....
>
> I'm fairly certain DynaLoader can do this....
>
> Just off topic a little, have you tried linking shared and static
> libraries in the same object, and running it via perl? This is my
> issue at the moment...
>
> Cheers!
>
> H.
>
> In article <3A805B39.B113676@yahoo.com>,
> "Jeffry A. Nokes" <jeff_nokes@yahoo.com> wrote:
> > Thanks for the response. I've actually thought of doing that, but
> > basically, I'm making platform specific executable applications using
> > perl2exe. I'm trying to find a way to just update shared object
> files and
> > thus update my application. I'm also trying to use the same code for
> all
> > platforms. I'm writing the exe's in Perl and the shared libraries in
> GNU
> > C. I've looked at Dynaloader, and from what I've read, I don't think
> this
> > will do the trick. Also, I'm looking at the new FFI (Foreign Function
> > Interface) module, but it's too new and there is barely in
> documentation on
> > it, that I can find anyway. Would you happen to know if the Perl 6
> effort
> > is tackling these issues?
> >
> > jimjim123@my-deja.com wrote:
> >
> > > My advice is read the perlxs man pages.... There are tutorials
> around
> > > which show you how to include C functions in your PERL code. In
> fact,
> > > I have a problem with this right now, but no-one answered my message
> > > about it :-(
> > >
> > > In article <3A7F9E04.1F238A77@yahoo.com>,
> > > "Jeffry A. Nokes" <jeff_nokes@yahoo.com> wrote:
> > > > Greetings,
> > > > I was wondering if anyone new of a way to call functions from
> a ".so"
> > > > file in Linux/Unix from a Perl script? I currently use Perl on
> Win32
> > > > and call functions from DLLs using Win32::API. Is there an
> equivalent
> > > > Perl module I can use to call functions from the Linux/Unix
> > > > environments? Or even better, a single Perl module that will work
> > > bothe
> > > > with DLLs in Win32, and .so files in Linux/Unix? This would save
> me a
> > > > lot of time.
>
> Sent via Deja.com
> http://www.deja.com/
------------------------------
Date: Wed, 07 Feb 2001 22:31:12 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: help with multiple if statements ?
Message-Id: <t83j5g13rp9cec@corp.supernews.com>
tvn007@my-deja.com wrote:
> Hi,
> I have do some search and replacement that require
> a lot of "if then" statement:
perldoc -q switch
perldoc perlsyn
> I have to assign $name to different character according
> to it numerial value.
> Here is what I have to do:
> $name eq '&' if ($name == 0)
> $name eq '!' if ($name == 1)
> $name eq '#' if ($name == 2)
> $name eq '$' if ($name == 3)
> $name eq '%' if ($name == 4)
> and this can go on, probably when $name reach 500.
This requires a test for every possible value. If/elsif/else
would cut the average down to half (or possibly even better,
since perl can optimize some if/elsif/else statements to a
jump table). An associative array (hash in Perl parlance)
cuts it down to about O(1).
my %name_dict = (
'0' => '&',
'1' => '!',
'2' => '#',
'3' => '$',
'4' => '%',
);
$name = $name_dict{$name};
This cuts down the mess and the way too many tests. If you
really have a number for each test and don't have huge gaps
between numbers (which would cause a sparsely populated array
and waste a bunch of space since Perl doesn't have special
sparse array support), then a normal array makes it even
less overhead.
my @name_array = (
'&',
'!',
'#',
'$',
'%',
);
$name = $name_array{$name};
This is the most efficient way to handle this ( O(1) with less
overhead than the hash), but it doesn't handle non-numeric values
of $name before the assignment, and it doesn't deal well with
large gaps between possible numbers (which would cause you to have
to build the array some other way anyway). It also doesn't give
you the key/value visual cues when maintaining the declaration
like a hash does. For some things a hash is worth the overhead
compared to and array.
> Is there better way to code this in PERL so that
> I do not have to write 500 if statement.
Any time you have multiple if statements for the same variable,
you should probably be using if/elsif/else, a hash or array, or
some other variation on a switch from the FAQ (such as the
for() loop with loop control -- see the docs for more info).
Chris
--
Christopher E. Stith
Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental. -- nobull, clp.misc
------------------------------
Date: Wed, 07 Feb 2001 22:31:59 +0000
From: JMT <ccx138@coventry.ac.uk>
Subject: Re: help with multiple if statements ?
Message-Id: <3A81CCDF.78477E16@coventry.ac.uk>
Chris Stith wrote:
>
> This is the most efficient way to handle this ( O(1) with less
> overhead than the hash), but it doesn't handle non-numeric values
> of $name before the assignment, and it doesn't deal well with
> large gaps between possible numbers (which would cause you to have
> to build the array some other way anyway). It also doesn't give
> you the key/value visual cues when maintaining the declaration
> like a hash does. For some things a hash is worth the overhead
> compared to and array.
> Chris
>
> --
> Christopher E. Stith
>
> Get real! This is a discussion group, not a helpdesk. You post
> something, we discuss its implications. If the discussion happens to
> answer a question you've asked, that's incidental. -- nobull, clp.misc
Good to see someone talking about big O notaion.
Using a hash was my first answer but I left it up to the user to work out
how to populate the hash, especially after the discusion about giving fish
and teaching how to fish last week.
john
------------------------------
Date: 07 Feb 2001 22:53:06 +0100
From: jacklam@math.uio.no (Peter J. Acklam)
Subject: Re: hex to binary conversion ? Please help
Message-Id: <wk1ytaurxh.fsf@math.uio.no>
Michael Carman <mjcarman@home.com> writes:
> "Peter J. Acklam" wrote:
> >
> > Michael Carman <mjcarman@home.com> writes:
> >
> > > print dec2bin(hex('BC')), "\n";
> > >
> > > sub dec2bin {
> > > my $str = unpack('B32', pack('N', shift));
> > > $str =~ s/^0+(?=\d)//; # strip leading zeroes
> > > return $str
> > > }
> >
> > This is "number 2 bin" or "int 2 bin", not "decimal 2 bin".
>
> It really is decimal.
Not according to Randal L. Schwartz. See the thread "converting
between dec. and hex" in alt.perl for more information.
Peter
--
sub int2roman{@x=split//,sprintf'%04d',shift;@r=('','I','V','X','L','C','D'
,'M');@p=([],[1],[1,1],[1,1,1],[1,2],[2],[2,1],[2,1,1],[2,1,1,1],[1,3],[3])
;join'',@r[map($_+6,@{$p[$x[0]]}),map($_+4,@{$p[$x[1]]}),map($_+2,@{$p[$x[2
]]}),map($_+0,@{$p[$x[3]]})];}print "@{[map{int2roman($_)}@ARGV]}\n";#JAPH!
------------------------------
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 236
**************************************