[8388] in Perl-Users-Digest
Perl-Users Digest, Issue: 2005 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 2 21:08:12 1998
Date: Mon, 2 Mar 98 18:00:29 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 2 Mar 1998 Volume: 8 Number: 2005
Today's topics:
[Q] How to redirect STDERR to a subroutine? (Mark W. Schumann)
Re: Anybody want a small puzzle? <uri@sysarch.com>
Re: Anybody want a small puzzle? (John Moreno)
Re: awk -> Perl on Win32 <mchase@ix.netcom.com>
Cookie question (Jan H.W.G.)
CPAN (Was: Help: Seeking cgi and html libs...) <trot@cam.org>
Re: Faxing from Perl <metcher@spider.herston.uq.edu.au>
Formats and diamond operator (Brian Springstead)
mail header stripping (SenimotBor)
Re: MX name lookup (Michael Fuhr)
Re: MX name lookup <metcher@spider.herston.uq.edu.au>
OOP query in PERL (Srinivas Abburi)
Oracle Webserver and Perl Cartridge -- recompiling perl <anatolii.belomestnov@gecapital.com>
Re: Perl system admin tools (Joe McMahon)
Re: Perl, OLE and Excel on Win32 (John Callender)
Perl5 architecture dependat files... <gafton@redhat.com>
Re: post to usenet (Nathan V. Patwardhan)
Re: Question for Tom Christiansen (John Callender)
simple perl question (Siemel Naran)
Re: simple perl question <ebohlman@netcom.com>
Re: Sorting by order of array elements? (Craig Berry)
SWIG, Perl5, valloc() and char * return (John R. Jackson)
Re: The -w switch (was Re: better way to do this?) (I R A Aggie)
Re: The -w switch (was Re: better way to do this?) <cmargoli@world.northgrum.com>
Re: Web Clients book (John Callender)
Webmaster Job, Montgomery Alabama (Don Nolte)
Why I have a result such as 108.879999999999 <ff@public.fz.fj.cn>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 2 Mar 1998 20:22:12 -0500
From: catfood@apk.net (Mark W. Schumann)
Subject: [Q] How to redirect STDERR to a subroutine?
Message-Id: <6dfm04$drp@junior.apk.net>
I've read the FAQs and perldoc'd it to death, but I still don't
see a clear solution. Perhaps the minds of clpm have some
insight or BTDT.
Scenario: Program already has a Log class that is used to write
program log and debug data to a file. One module used by the
program (it happens to be Net::FTP) writes to STDERR. I would
love for the STDERR output to be redirected, not to a file but to
the Log::write method. The idea is for
print STDERR "We print anything";
to be equivalent to
$logobject->write ("We print anything");
I'm wondering whether I should redirect STDERR to a pipe that is
read by a child process that reads that input in a loop to write
to Log::write... well, I'm not sure that's the most robust way.
What do you think?
--
Mark W. Schumann | catfood@apk.net
Why should I change or hide my return address to deter spammers?
I just loop the garbage right back at 'em.
------------------------------
Date: 02 Mar 1998 17:21:49 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Anybody want a small puzzle?
Message-Id: <x7iupwzqbm.fsf@sysarch.com>
phenix@interpath.com (John Moreno) writes:
> <SPC@popstar.com> wrote:
>
> > if ($FILES[$count] =~ $startmarker ){
>
> This is wrong no matter how you slice it.
>
> > until ($FILES[$count] =~ $endmarker) {
>
> Ditto.
actually they are legal perl but not good perl. if the right side of =~
is an expression the value is compiled into a regex. it is bad perl
nonetheless since it is not clear and you can't use modifiers.
see my previous post about this code.
uri
--
Uri Guttman SYStems ARCHitecture and Software Engineering
uri@sysarch.com Have Perl, Will Hack
http://www.sysarch.com (781) 643-7504 x*2 FAX: (781) 643-2710
Try the Best Search Engine on the Net --------> http://www.northernlight.com
------------------------------
Date: Mon, 2 Mar 1998 18:52:43 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: Anybody want a small puzzle?
Message-Id: <9B3D066EDA59839C.94552955D0FF3CA8.C273F94EE9CC9362@library-proxy.airnews.net>
Uri Guttman <uri@sysarch.com> wrote:
> phenix@interpath.com (John Moreno) writes:
>
> > <SPC@popstar.com> wrote:
> >
> > > if ($FILES[$count] =~ $startmarker ){
> >
> > This is wrong no matter how you slice it.
> >
> > > until ($FILES[$count] =~ $endmarker) {
> >
> > Ditto.
>
> actually they are legal perl but not good perl.
Sorry, I worded that a bit strongly - that's what I meant. It might
work, but it's going to be confusing, and you're just going to have to
change it anyway if you have to do something like make your search
case-insensitve or something.
--
John Moreno
I am trying to convince the author of YA-NewsWatcher that the latest
version should be released to the public. He doesn't think there's much
interest in a new version. Help me prove him wrong. To do so, send me
mail <mailto:phenix@interpath.com> with a Subject of New YA. Comments
on what you like/dislike in the current version will be appreciated.
------------------------------
Date: Mon, 2 Mar 1998 05:33:04 -0800
From: "Blue" <mchase@ix.netcom.com>
Subject: Re: awk -> Perl on Win32
Message-Id: <6dfa0r$ebc@dfw-ixnews10.ix.netcom.com>
Your best bet is to install the Gurusamy Sarathy binary distribution (in
http://www.perl.com/CPAN/authors/GSAR/) on one of your machines and use the
a2p that comes with it. The resulting script can be used under either port.
Both ports can reside on the same machine, you can adjust your path variable
and registry to control which gets used for which purposes.
Mac :})
Ed Avis wrote in message <34f2e5d9.17154366@news-direct>...
>I'm using Perl for Win32 - but it doesn't seem to come with the awk to
>Perl translator.
>
>Where can I get this from?
------------------------------
Date: Mon, 02 Mar 1998 21:07:10 GMT
From: info@realm.nl (Jan H.W.G.)
Subject: Cookie question
Message-Id: <34fb1e30.2724674@news.IAEhv.nl>
Hello,
I have trided and trided to install the cookie script from
matt@worldwidemart.com but it seems to be that I still have to learn a
lot.
My Question:
After configer and installing the script " cookie.lib " it doesn't
work. Do I have to put something in the head from the HTM(L) page ?
<META HTTP_COOKIE="set cookie"> or something like that ?
Or should the cookie start automatical from the script ?
I have read and read again but I can't find the sollution,
Please who can help me .
With best regards,
Jan
------------------------------
Date: Mon, 02 Mar 1998 17:15:22 -0500
From: Trottinette <trot@cam.org>
To: Patrick Sibenaler <patrick@arch.ethz.ch>
Subject: CPAN (Was: Help: Seeking cgi and html libs...)
Message-Id: <34FB2F79.79DD92A8@cam.org>
1. www.perl.com -> CPAN
2. Read the FAQ, search the Web.
Patrick Sibenaler wrote:
>
> Hi all,
>
> I'm currently looking for 2 things:
>
> 1. A lib or module that provides functions to dissect html
> code into its tags. I found some that needed htmlscript,
> but I need one without that.
>
> 2. A cgi-lib that can deal with a multipart input that is
> uploaded (commonly known as 'uploading' through the web).
> Again, there are simple solutions that do this in php,
> but I need it in perl...
>
> If anyone knows a module or lib that can do one of those
> tasks, please send me a mail.
>
> thanx in advance,
> patrick./
>
> --
> ---------------------------------------------------------------------------
> The trick is to communicate bi-directional in real time and high
> resolution
> ---------------------------------------------------------------------------
------------------------------
Date: Tue, 03 Mar 1998 11:23:18 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Faxing from Perl
Message-Id: <34FB5B86.528C787C@spider.herston.uq.edu.au>
If you're implementing a large scale solution, use a fax server with
SMTP capabilities. Then you can use your perl script to send mail to
the fax server.
--
Jaime Metcher
Martin Wong wrote:
>
> Dear all,
>
> is there any way I can fax a document/text file in Perl on a win32 based
> NT platform? Maybe I can use an external program or something.
>
> Any ideas?
>
> Drop me an email : martin@highway-innovations.com.sg
------------------------------
Date: Tue, 3 Mar 1998 01:23:27 GMT
From: bspring@j51.com (Brian Springstead)
Subject: Formats and diamond operator
Message-Id: <slrn6fmmrg.onf.bspring@j51.com>
I'm using perl to output a number of similar files to the printer by
using the diamond operator <> and a format I designed. I wanted the
top of the page format to include the filename and the page number(s).
All works well if I only put one filename on the command line. If
I list more than 1 file and if the information doesn't fill a page, it
gets treated as one big file. How do I force an end of page and get
the next filename? Thanks in advance.
Brian
--
Brian Springstead |
Looney tunes! | "Consequences, Schmonsequences, as long as I'm rich."
bspring@j51.com | -- "Ali Baba Bunny" [1957, Chuck Jones]
------------------------------
Date: 3 Mar 1998 00:54:32 GMT
From: tomines@rohan.sdsu.edu (SenimotBor)
Subject: mail header stripping
Message-Id: <6dfkc8$t5o$1@gondor.sdsu.edu>
I'm a newbie to Perl and I was wondering if there was a more efficient way to strip
mail headers from a /var/spool/mail/$file and write it out to another file.
than the way I have it set up in the sub routine down below.
I tried to do a s/^From\b.*^$//smg; to remove each block starting from 'From' and
ending in a blank line but that doesn't seem to work. I suspecting that I'm reading
the mail file wrong. If there is a way this substitue could be implemented it would
definately decrease my lines of substition code.
My next question is - Is there a way to use variable interpolation within s/// and m//
strings to match beginning or endof line strings.
ex. s/^$variable1/$variable2/g How is the ^$ in the sub stirng interpreted?
or s/$variable$/$variable2/g and is $variable$ legal?
Much thanks in advance for any help that comes in
Robert Tomines
tomines@rohan.sdsu.edu
########################################################################################
sub strip_header {
$status="/var/spool/mail/status";
$noheader="/var/tmp/status/noheader";
open(STATUS, "<$status") or die "Can't open $status !$ \n";
open(NOHEADER, ">$noheader") or die "Can't open $noheader !$ \n";
while (<STATUS>) {
s/^From.*$//sm;
s/^Return.*$//mg;
s/^Received.*$//mg;
s/^Date:.*$//mg;
s/^From:.*$//mg;
s/^Message.*$//mg;
s/^To.*$//mg;
s/^id.*$/mg/;
s/^Subject.*$//mg;
s/^Status.*$//mg;
s/^Cc.*$//mg;
s/^X-Sun.*$//mg;
s/^Mime.*$//mg;
s/^Content.*$//mg;
s/^X-Mailer.*$//mg;
s/^-----.*$//mg;
#The following will remove special characters. Most notably the ^M which I believe to be
#similar to a \n. Another character that is removed is the \t which is also ^I.
s/^\x09.*$//mg; #hex for \t or ^I
s/^\x0a.*$//mg; #hex for \n
s/\x0d$//mg; #hex for ^M
print NOHEADER;
}
close STATUS;
close NOHEADER;
}
#################################################################################################
------------------------------
Date: 2 Mar 1998 18:18:12 -0700
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: MX name lookup
Message-Id: <6dflok$sao@flatland.dimensional.com>
Please don't post with an address like this. Many people, including
myself, refuse to edit munged email addresses. Mail filters are easy
to use.
dboldt@usgs.gov.NO_SPAM (David Boldt) writes:
> How might one get a canonical hostname, given an
> MX record name, if "nslookup" cannot be called.
There's a module on the Comprehensive Perl Archive Network (CPAN)
that can perform DNS lookups:
http://www.perl.com/CPAN/CPAN.html
If you visit that page and do a little searching, you should be
able to find it in no time :-)
--
Michael Fuhr
http://www.dimensional.com/~mfuhr/
------------------------------
Date: Tue, 03 Mar 1998 11:40:09 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: MX name lookup
Message-Id: <34FB5F79.AE75C34D@spider.herston.uq.edu.au>
I believe there's a Net::DNS module on CPAN. I have used it, and the
module list says it's in alpha, but maybe worth a look.
--
Jaime Metcher
David Boldt wrote:
>
> How might one get a canonical hostname, given an
> MX record name, if "nslookup" cannot be called.
>
> --
> --david boldt <dboldt@usgs.gov.NO_SPAM>
>
> Lottery: A tax on people who are bad at math
------------------------------
Date: 2 Mar 1998 14:59:03 -0800
From: srinivas@pyramid.com (Srinivas Abburi)
Subject: OOP query in PERL
Message-Id: <6dfdjn$a8f@t-rex.eng.pyramid.com>
Hi!
This is a simple perl script to check object oriented programming.I followed the guidelines of OOP programming in PERL, but got unexpected results. I am not able to locate the problem after spending lot of time in debugging. I appreciate if you can find the problem here. Pls. send your response to
srinivas@pyramid.com
Functionality of the script:
Create an Emp object.
Initialize the object
print the data of the object.
Emp package:
Create the object by using new routine which doesn't do anything except declaring the object elements.
Defines the routines initialize and output for the tasks.
Thanks much for your help.
Srinivas
#!/usr/bin/perl
#require Exporter;
#@ISA = qw(Exporter);
#@EXPORT = qw(new initialize output);
#@EXPORT_OK = qw($first_name $last_name $id $status $employer);
package Emp;
#use strict;
#BEGIN {
# printf " Start of the package Emp\n ";
# my $self;
# my $first_name;
# my $last_name;
# my $id;
# my $status;
# my $employer;
# sub initialize();
# sub output();
#}
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
$self->{$first_name} = undef;
$self->{$last_name} = undef;
$self->{$id} = undef;
$self->{$employer} = undef;
$self->{$status} = undef;
# bless($self);
bless($self, $class);
return $self;
}
sub initialize {
my $self = shift;
$self->{$first_name} = shift;
$self->{$last_name} = shift;
$self->{$id} = shift;
$self->{$employer} = shift;
$self->{$status} = shift;
}
sub output {
my $self = shift;
printf " First Name = %s\n", $self->{$first_name} ;
printf " Last Name = %s\n", $self->{$last_name} ;
printf " ID = %s\n", $self->{$id} ;
printf " Status = %s\n", $self->{$status} ;
printf " Employer = %s\n", $self->{$employer} ;
}
#END { printf " End of the package\n "; }
1;
#require "Emp.pl";
$first_name = "James";
$emp = Emp->new();
$emp->initialize(George, Adams, 1234, Professional, M);
$emp->output();
printf " Name = $first_name " ;
#Emp::new();
#Emp::initialize("George", "Adams", "1234", "Professional", "M");
#Emp::output();
--
---------------------------------------------------------------------------
Srinivas Abburi Voice (408)428-7422
Siemens Pyramid Information Systems Email: srinivas@pyramid.com
------------------------------
Date: Mon, 02 Mar 1998 16:40:36 -0500
From: Anatolii Belomestnov <anatolii.belomestnov@gecapital.com>
Subject: Oracle Webserver and Perl Cartridge -- recompiling perl library
Message-Id: <34FB2754.E718B1C9@gecapital.com>
Dear ALL,
I wondered if anybody has recompiled the perl cartridge
of the Oracle Webserver 3.0 ???
I was thinking of adding a module, but Oracle did not seem
to provide neither makefiles nor Makefile.PL prototypes
to make a perl cartridge linkable library.
I would like to hear from ANYBODY who is at least a little
bit interested in Oracle's Perl Cartridge.... Have some ideas.
Thanks for your time
Anatolii Belomestnov
anatolii.belomestnov@gecapital.com
------------------------------
Date: Mon, 02 Mar 1998 17:36:48 -0500
From: joe.mcmahon@gsfc.nasa.gov (Joe McMahon)
Subject: Re: Perl system admin tools
Message-Id: <joe.mcmahon-0203981736490001@prtims.stx.com>
>Hi,
>Is there any place where i can find some kind of tools to move files
>from one server to another server periodically?
>All i can seem to find is only CGI and web scripts. Can anyone point me
>to a place where i can find some of these types of
>tools?
>Thanks
>Steve Kruzich
>skruzich@stc.net
>
Look for mirror. Handy script that connects to "somewhere else" via FTP
and rebuilds a copy of the remote directory tree locally. Also does time
checking, etc., so it only moves the new stuff. I believe that the home
site is sunsite.ic.ac.uk, but I don't remember for sure. An archie search
for mirror will probably find it.
--- Joe M.
------------------------------
Date: 2 Mar 1998 14:05:42 -0800
From: jbc@west.net (John Callender)
To: c.caminati@computer.org
Subject: Re: Perl, OLE and Excel on Win32
Message-Id: <6dfafm$4s2@acme.sb.west.net>
Carlo Caminati (ccaminati@mail.enjoy.it) wrote:
: I'm trying to write a perl script that fetches data from an
: Excel sheet to get the work done.
Martin Schwartz (no relation, I assume) has something called LAOLA that
is supposed to do just what you're describing. I've used it on Word files
with good success, at least.
Check out the following Web page for more details:
http://user.cs.tu-berlin.de/~schwartz/pmh/
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: Mon, 2 Mar 1998 17:17:55 -0500
From: Cristian Gafton <gafton@redhat.com>
Subject: Perl5 architecture dependat files...
Message-Id: <Pine.LNX.3.96.980302171644.15877P-100000@alien.redhat.com>
Hello,
If this is an issue that was brought to the list several times already,
please excuse me. I would like to know an "official" answer to the
problems we have here at Red Hat shipping a perl distribution that both
conforms with the Perl standards on other platforms, yet allows one to
upgrade his perl package without having to worry about loosing other perl
modules he installed - modules not included in our package.
More specific: the default arch-depend directory for perl (at least on
Linux) is set to be /usr/lib/perl5/i386-linux/5.00401 for perl version
5.004_01. Now, if somebody upgrades to 5.004_04, all his modules installed
over 5.004_01 will stop working - even if they are nothing but some small
.pm modules...
My question is: given that in the /usr/lib/perl5/i386-linux directory the
only entry is the 5.004_xx subdir, will it hurt if we reconfigure the perl
package to store the arch-dependent files in /usr/lib/perl5/i386-linux
directly, leaving out the version directory ?
Anyone sees any problems with this if we will start shipping perl
reconfigured this way ? Are there any chances that internally some things
will start to break ? (most concerned about shared objects, etc). Is it
safe to assume that all modules which are using the perl makemaker will
work okay if we change it this way ?
Thank you,
Cristian
--
----------------------------------------------------------------------
Cristian Gafton -- gafton@redhat.com -- Red Hat Software, Inc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
UNIX is user friendly. It's just selective about who its friends are.
------------------------------
Date: 2 Mar 1998 22:04:15 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: post to usenet
Message-Id: <6dfacv$gj3@fridge.shore.net>
Alexander Kovalenko (techsoft@abcpages.com) wrote:
: anybody know how i can post a message to newsgroup by perl program?
Oy.
News::NNTPClient
Net::NNTP
--
Nathan V. Patwardhan
------------------------------
Date: 2 Mar 1998 16:22:12 -0800
From: jbc@west.net (John Callender)
Subject: Re: Question for Tom Christiansen
Message-Id: <6dfifk$469@acme.sb.west.net>
Brian L. King (blk@redneck.intel.com) wrote:
: Given some of the recent threads in this newgroup, I'd bet a buck that
: Tom has killfiled ($subject =~ /Tom Christiansen/i) postings....
: Wouldn't blame him ,anyway. ;-)
You're on. I bet he reads them all--and I'll gladly mail you the $1 if Tom
confirms that you're correct.
For the record (since some have taken issue with me privately when I
claimed to be a "longtime fan" of Tom C.'s, with one even likening me to
Mark David Chapman), I am really, really happy that he posts in this
group, and hope he continues to do so. In addition to the outstandingly
helpful (if sometimes insulting) advice he offers to the clueless, his
participation in the group makes for vast amounts of love him/hate him
rants and flames, which, truth be told, I find a lot more entertaining
than high-level discussions of how many blessed objects can dance on the
head of a thingy.
I realize this attitude is contrary to dogma. But I'll bet that for every
person like me who admits feeling this way, there are a dozen others who
are just as avid in reading the meta chatter, even while they complain
about its presence.
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: 2 Mar 1998 22:31:26 GMT
From: sbnaran@bardeen.ceg.uiuc.edu (Siemel Naran)
Subject: simple perl question
Message-Id: <slrn6fmcq2.9kr.sbnaran@bardeen.ceg.uiuc.edu>
Hello. On the subject of perl, does anyone know how to do the following.
Both of these are very easy to do in C, but I want a simple way to do them
from a shell script. I can do (b) with gawk, but this seems to be
overkill as gawk goes through the trouble of splitting the input line into
fields.
(a)
If I have a string and want to get the string minus the last character if
it is a '/', how can I do it? For example,
/home/sbnaran/stuff ==> /home/sbnaran/stuff
/home/sbnaran/stuff/ ==> /home/sbnaran/stuff
(b) If I have a string and I want to return a substring in it starting at
a given search-substring, how? For example, if the search-substring is
"sbnaran", then
/home/sbnaran/stuff ==> sbnaran/stuff
Thanks.
Siemel B. Naran.
------------------------------
Date: Mon, 2 Mar 1998 23:11:36 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: simple perl question
Message-Id: <ebohlmanEp7sFC.2oC@netcom.com>
Siemel Naran <sbnaran@bardeen.ceg.uiuc.edu> wrote:
: (a)
: If I have a string and want to get the string minus the last character if
: it is a '/', how can I do it? For example,
: /home/sbnaran/stuff ==> /home/sbnaran/stuff
: /home/sbnaran/stuff/ ==> /home/sbnaran/stuff
perldoc perlre
: (b) If I have a string and I want to return a substring in it starting at
: a given search-substring, how? For example, if the search-substring is
: "sbnaran", then
: /home/sbnaran/stuff ==> sbnaran/stuff
perldoc perlre
perldoc -f index
------------------------------
Date: 2 Mar 1998 23:28:33 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Sorting by order of array elements?
Message-Id: <6dffb2$r6p$1@marina.cinenet.net>
David Fetter (dfetter@shell4.ba.best.com) wrote:
: Suppose I have an array of arbitrary (non-list) elements like this:
:
: # This order must be preserved:
: @cannonical_order = qw(foo fie bar baz);
:
: # Weird values for the coming hash
: @weird_values = ('Fee', 'Torchiere', 'Doohickey', 'Teddy Bear');
:
: $#canonical_order == $#weird_values or die "Something's badly wrong: $!";
:
: # Make a hash
: for $i (0..$#canonical_order) {
: push @groovy_hash, $canonical_order[$i],$wierd_values[$i];
: }
That's the wrong way to load the hash. Try a hash slice:
@groovy_hash{@canonical_order} = @weird_values;
: Now, the tricky part: I want to print out the values of the hash,
: sorted by the canonical order.
foreach my $key (@canonical_order) {
my $val = $groovy_hash{$key};
print "$key = $val\n";
}
: Which FM's should I be R'ing?
Why, all of them, of course! :-)
Seriously, I'd suggest the Llama and Camel books, even if you've already
read them. They reward constant study.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 2 Mar 1998 16:53:09 -0500
From: jrj@gandalf.cc.purdue.edu (John R. Jackson)
Subject: SWIG, Perl5, valloc() and char * return
Message-Id: <6df9o5$20@gandalf.cc.purdue.edu>
Environment: SWIG Version 1.1 (Patch 4)
perl5 (5.0 patchlevel 4 subversion 4)
Solaris 2.5.1
What am I doing wrong here? I have a function that I want to return a
simple string. If I compile without -DBUG, it works fine. If I compile
with -DBUG to enable the valloc()/free(), then perl does:
Bad free() ignored at jj.pl line 7.
0: xx 1 xx
Bad free() ignored at jj.pl line 7.
1: xx 2 xx
Bad free() ignored at jj.pl line 7.
2: xx 3 xx
...
Bad free() ignored at jj.pl line 7.
15: xx 16 xx
Segmentation Fault(coredump)
I'm sure I'm doing something out of bounds in the typemap, but I could
not find any examples that were simple enough to show me how to do this.
Please E-mail responses directly to me -- I don't read the newsgroup
(although I did try to search it first for references to this).
John R. Jackson, Technical Software Specialist, jrj@purdue.edu
====
jj.i
====
%module jj
%typemap(perl5,out) char *robot_get_element {
if ($source) {
$target = sv_newmortal();
sv_setpv($target, $source);
} else {
$target = &sv_undef;
}
argvi++;
}
char *robot_get_element (void);
%{
#include <stdlib.h>
char *robot_get_element (void)
{
static int n = 1;
static char *result = NULL;
char *a;
#if defined(BUG)
a = valloc (12);
free (a);
#endif
if (result) free(result);
if ((result = malloc (20)) != NULL) {
sprintf(result, "xx %d xx", n++);
}
return result;
}
%}
=======
jj.make
=======
#!/bin/ksh
swig -perl5 jj.i \
&& gcc -Dsparc \
-I/opt/perl5.004/lib/sun4-solaris/5.00404/CORE \
-g \
-c \
-fpic \
"$@" \
jj_wrap.c \
&& ld -G jj_wrap.o -o jj.so
=====
jj.pl
=====
#!/opt/perl5.004/bin/perl -w
use jj;
package jj;
for ($i = 0; $i < 20; $i++) {
$x = robot_get_element ();
print "$i: $x\n";
}
exit (0);
=========
jj_wrap.c
=========
XS(_wrap_robot_get_element) {
char * _result;
int argvi = 0;
dXSARGS ;
cv = cv;
if ((items < 0) || (items > 0))
croak("Usage: robot_get_element();");
_result = (char *)robot_get_element();
{
if (_result) {
ST(0) = sv_newmortal();
sv_setpv(ST(0), _result);
} else {
ST(0) = &sv_undef;
}
argvi++;
}
XSRETURN(argvi);
}
------------------------------
Date: Mon, 02 Mar 1998 17:00:15 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <fl_aggie-0203981700150001@aggie.coaps.fsu.edu>
In article <6df2f4$74e@fridge.shore.net>, Art Cohen <upsetter@shore.net> wrote:
+ Everybody in this newsgroup posts as if you're a total and complete moron
+ if you don't use the -w switch on every single perl script.
It has a tendency to save you from "D0H!"'s...
+ Well, guess what? One of the things I (and I suspect, a lot of other
+ people) like about Perl is that I don't have to pre-declare variables!
+ They spring into existence, pre-initialized to a null variable, whenever I
+ need them.
Yep.
+ However, if I turn the -w switch on, I get warnings about them!
Why? If it is the warning that I think it is, once you use the variable a
second time, the warning goes away. If you simply declare them with a my ();
statement, the warning goes away. If you need a $junk variable, you can
simply undef the variable, and the warning goes away.
+ I find
+ this very annoying and not particularly helpful. If I need to initialize a
+ variable, I do it. If I don't need to, I just use the variable name, and
+ Perl works the way it was designed.
And -w switch will also save you from making typing errors by warning you
that a variable is being used only once. In fact, the warning message
wonders aloud if that is indeed the case.
+ Does that make me an idiot or a masochist?
Only if you like chasing your tail trying to find a subtle, but preventable
typing goof.
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: Mon, 2 Mar 1998 22:36:11 GMT
From: Charles Margolin <cmargoli@world.northgrum.com>
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <34FB345B.3E18@world.northgrum.com>
Art Cohen wrote:
>
> I'd like to say that I almost never use the -w switch and I don't miss it
> (and I don't particularly enjoy pain).
>
> Everybody in this newsgroup posts as if you're a total and complete moron
> if you don't use the -w switch on every single perl script.
>
> Well, guess what? One of the things I (and I suspect, a lot of other
> people) like about Perl is that I don't have to pre-declare variables!
> They spring into existence, pre-initialized to a null variable, whenever I
> need them.
>
> However, if I turn the -w switch on, I get warnings about them! I find
> this very annoying and not particularly helpful. If I need to initialize a
> variable, I do it. If I don't need to, I just use the variable name, and
> Perl works the way it was designed.
>
> Does that make me an idiot or a masochist?
Yes, unless you never make coding mistakes such as scoping errors or
misspelling a variable name.
Even if you turn on -w, verify that all of the messages are covered by
situations where perl Does The Right Thing, and then remove -w,
then you are forcing whoever will be maintaining your code to
check it all over again.
It's not a big deal (and maybe more efficient at runtime) to declare
variables in a my statement and put in a 'use strict'.
--
Charles G. Margolin DSSD Internal Information Services
cmargoli@world.northgrum.com Northrop Grumman Corp. 0624/23
margolin@acm.org Hawthorne, California 90250-3277
------------------------------
Date: 2 Mar 1998 16:41:28 -0800
From: jbc@west.net (John Callender)
Subject: Re: Web Clients book
Message-Id: <6dfjjo$8io@acme.sb.west.net>
Jen Lyons (lyonsj@bgnet.bgsu.edu) wrote:
:
: Has anyone in this NG read the O'Reilly "Programming Web Clients with
: Perl" book?
I have it, and like it. The information density is considerably lower than
the Camel, and it's shorter to boot, so there's a good deal less overall
meat there. But the lower density is more feature than bug for an
accidental tourist like me, and if Web clients are something you're
interested in doing, and if they don't seem inherently obvious to you,
it's probably a good choice.
I seem to recall that Clinton Wong was at the same table at the infamous
O'Reilly Conference book signing by tchrist and larry and randal (along
with the Advanced Perl Programming author, Sriram Srinivasan), but sadly,
I'd left both my Pelican and my Jaguar back at the hotel, so I wasn't
able to analyze either of their signing styles. They mostly looked bored,
since they weren't getting all the adulation that the Camel authors were.
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: Tue, 03 Mar 1998 00:30:39 GMT
From: dnolte@mindspring.com (Don Nolte)
Subject: Webmaster Job, Montgomery Alabama
Message-Id: <6dfhr3$udu@camel15.mindspring.com>
Air Force JAG Department offers a position as Webmaster, GS-12.
Announcement is found at:
http://www.usajobs.opm.gov/wfjic/jobs/AH0457.HTM
------------------------------
Date: Tue, 03 Mar 1998 09:37:08 +0800
From: Fu Zhibin <ff@public.fz.fj.cn>
Subject: Why I have a result such as 108.879999999999
Message-Id: <34FB5EC4.CBA87277@public.fz.fj.cn>
Hi all:
in my program:$fee=360+0.12*int(($time-$timebase)/60)
So,int(($time-$timebase)/60)is an integer.
but why $fee is result as xxx.xx99999999....(It should be xxx.xx+0.01)
Or the result is xxx.xx00000000...1 (so it should be xxx.xx)
Why it happen??Should I do some config to the variables??
But how?or it is because the "int" ??
Appreciated to any help
regards
ff@public.fz.fj.cn
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2005
**************************************