[17499] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4919 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 18 18:07:13 2000

Date: Sat, 18 Nov 2000 15:05:10 -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: <974588710-v9-i4919@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 18 Nov 2000     Volume: 9 Number: 4919

Today's topics:
        Data missing, rogue proccess. <josh@projectperl.com>
    Re: Data missing, rogue proccess. <josh@projectperl.com>
    Re: hello i am new (Gwyn Judd)
    Re: How do I ensure that only a single instance of my s (Gwyn Judd)
    Re: I am sorry for posting this so many times! <bart.lateur@skynet.be>
        locale questions - Newbie <carlos_benj@my-deja.com>
    Re: long array to multivalue hash <abe@ztreet.demon.nl>
        multidimensional array help <polar@cloud9.net>
    Re: Newbie Rename() Function (Gwyn Judd)
        print "Location: revised <todd@mrnoitall.com>
    Re: print 'Location: (Gwyn Judd)
        Problems saving an uploaded file. <johan.ditmar@era.ericsson.se>
        Problems saving an uploaded file. <johan.ditmar@era.ericsson.se>
        Problems saving an uploaded file. <johan.ditmar@era.ericsson.se>
        Problems saving an uploaded file. <johan.ditmar@era.ericsson.se>
        Problems saving an uploaded file. <johan.ditmar@era.ericsson.se>
        Problems saving an uploaded file. <johan.ditmar@era.ericsson.se>
        Problems saving an uploaded file. <johan.ditmar@era.ericsson.se>
        Problems saving an uploaded file. <johan.ditmar@era.ericsson.se>
    Re: simple question: can Perl do this? (talking to a pe <-@-.com>
    Re: solution: installing Image::Magick to host as non-r dtbaker_dejanews@my-deja.com
        views and/or cursors with DBD::mysql ?? <stevie_d38nospam@hotmail.com>
        Why SvSETMAGIC? <pavel@gingerall.cz>
    Re: XSUB output strings <pavel@gingerall.cz>
    Re: XSUB output strings <eric@urbanrage.com>
    Re: XSUB output strings (Ilya Zakharevich)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 18 Nov 2000 15:50:22 -0600
From: "Josh" <josh@projectperl.com>
Subject: Data missing, rogue proccess.
Message-Id: <h%CR5.2$tG2.133@news2.dnvrcoidc.firstworld.net>

I have been having problems where a datafile is becoming corrupt at random
times. At random times with apparently different functions being used the
larger of two datafiles(in plaintext) will become corrupt(data is missing
and fields are moved all over the place. I have yet to find an answer on
this and would greatly appreciate any help. Files are always locked using
either the non-exclusive or exclusive lock appropriately.

The other problem I am having seems doesn't really have anything to do with
the script and just recently appeared. When the script is called to write to
one of two databases it will stall and return nothing to the browser. This
also will spur another process that will never end unless explicitly killed
by an admin. After awhile this clogs up the server and will force a reboot.
This has never happened before without a change in the script. The server
runs Linux, Apache, and a PERL 5.6.x.

All help is greatly appreciated, thank you.

Regards,
-Josh







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

Date: Sat, 18 Nov 2000 16:12:35 -0600
From: "Josh" <josh@projectperl.com>
Subject: Re: Data missing, rogue proccess.
Message-Id: <7kDR5.3$tG2.138@news2.dnvrcoidc.firstworld.net>

Sorry, the second problem with a runaway script was actually caused by low
memory on the server and has now been resolved. I would appreciate it if
someone can help me with the first problem where data is randomly lost.
Thank you.

Josh wrote in message ...
>The other problem I am having seems doesn't really have anything to do with
>the script and just recently appeared. When the script is called to write
to
>one of two databases it will stall and return nothing to the browser. This
>also will spur another process that will never end unless explicitly killed
>by an admin. After awhile this clogs up the server and will force a reboot.
>This has never happened before without a change in the script. The server
>runs Linux, Apache, and a PERL 5.6.x.
>






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

Date: Sat, 18 Nov 2000 22:03:17 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: hello i am new
Message-Id: <slrn91dv54.jm5.tjla@thislove.dyndns.org>

I was shocked! How could Tango <heh@bbbb.org>
say such a terrible thing:
>This is a multi-part message in MIME format.

>HELLO I AM NEW TO THIS GROUP. CANB SOMEONE TELL ME WHAT IT IS ABOUT, I =
>HEARD ABOUT IT IN ALT.POKEMON

alt.stupidity is that way ------------->

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
DISCUSSION

n. A method of confirming others in their errors.


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

Date: Sat, 18 Nov 2000 20:39:17 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: How do I ensure that only a single instance of my script is running  (in Linux)?
Message-Id: <slrn91dq7h.jm5.tjla@thislove.dyndns.org>

I was shocked! How could Michael Koehne <not-for-mail@copyleft.de>
say such a terrible thing:
>Craig Manley <c.manley@chello.nl> wrote:
>> Thanks. This is the function I created and it works:
>
>  great - now merge your original idea - to detect stale locks !

I think flock()'ed files are unlocked when the process ends.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Garbage In, Gospel Out


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

Date: Sat, 18 Nov 2000 19:51:49 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: I am sorry for posting this so many times!
Message-Id: <5fnd1t4m0rifu2jk6m1t3llvj1236oefhj@4ax.com>

Johan M. Ditmar wrote:

>I apologize for posting this message so many times. I donīt think itīs my
>fault, it must have something to do with the newsgroup server at my work or
>outlook.

Thank goodness it didn't happen again with this post.   ;-)

-- 
	Bart.


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

Date: Sat, 18 Nov 2000 19:49:31 GMT
From: Carlos Benjamin <carlos_benj@my-deja.com>
Subject: locale questions - Newbie
Message-Id: <8v6mga$vpo$1@nnrp1.deja.com>

I've just started through "Learning Perl" and am getting the following
warning:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LANG = "(null)"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").


I've looked for locale in the book's index and found nothing. I've
checked man locale, but it's rather terse and seems to indicate that
these are specific to Perl. Just typing 'locale' on the command line, I
get this:

LANG=(null)
LC_CTYPE="(null)"
LC_NUMERIC="(null)"
LC_TIME="(null)"
LC_COLLATE="(null)"
LC_MONETARY="(null)"
LC_MESSAGES="(null)"
LC_ALL=


Do I set these like an environment variable (when I tried to
'export LANG=whatever'
the value does change) or is there a more proper way?

What are the proper American English settings for these values (better
yet, where is there a source on the web for this info?


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sat, 18 Nov 2000 20:37:23 +0100
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: long array to multivalue hash
Message-Id: <g9ld1tcmmqonuqca6uhne86enc4p75363o@4ax.com>

On 17 Nov 2000 13:23:22 +0000, nobull@mail.com wrote:

> richard_dobson@my-deja.com writes:
> 
> > I have tried the following but to no avail:
> > 
> > while (($rate,$date,$descr,$who)=@array){
> > $hash{$rate}=[$date,$descr,$who];
> > }
> 
> The assignment in the while condition does not consume elements from
> @array so it reads the first 4 elements over and over.  (Oh and you've
> also missed out a my()). What you probably wanted to do is shift off
> the elements 4 at a time:
> 
> while (my ($rate,$date,$descr,$who) = splice @array,0,4 ) { 
>    $hash{$rate}=[$date,$descr,$who];
> }
> 
> BTW: TMTOWTDI - many of which may be more efficient than this simple
> solution.

I don't know about efficiency, but you might not want to destroy the
original array. If the data is indeed in 'groups of four', this should
work:

	my %hash = map { 
		$array[4*$_] => [ @array[(1 + 4*$_)..(3 + 4*$_)] ]
	} 0..(@array/4) - 1;



-- 
Good luck,
Abe
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'


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

Date: Sat, 18 Nov 2000 15:55:43 +0000
From: brian <polar@cloud9.net>
Subject: multidimensional array help
Message-Id: <3A16A67E.AACEB428@cloud9.net>

I am having trouble setting up a multidimensional array.  Assume I have
two arrays @aaa ( 1..5) and @bbb (6..10).  I am trying to set ccc = (
[\@aaa] , [\@bbb] ) .  I have tried using $ccc and @ccc = = ( [\@aaa] ,
[\@bbb] ) but I can still not access the array.  I read thru several of
the help pages and I have no problem accessing the data if I use @= (
[1..5] , [6..10] ) but i can't acces the data when I'm passing it
another array.  I'm sure I'm missing somethig very easy but could
someone please help me out.

thanks    brian



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

Date: Sat, 18 Nov 2000 22:13:43 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Newbie Rename() Function
Message-Id: <slrn91dvom.jm5.tjla@thislove.dyndns.org>

I was shocked! How could Randall <tech-removethis-@rch-usa.com>
say such a terrible thing:

>Thanks. Can you tell me where the FAQ is?

See the post entitled "How to find the Perl FAQ"

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The number of computer scientists in a room is inversely proportional
to the number of bugs in their code.


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

Date: Sat, 18 Nov 2000 14:12:08 -0600
From: Todd Anderson <todd@mrnoitall.com>
Subject: print "Location: revised
Message-Id: <3A16E0F5.3BDB09B6@mrnoitall.com>

Dear Sirs,
I am trying to write a script that would be run by cron. I'm not sure of

how to prompt another scipt on another server.
In otherwords, I can put this line...
http://my.com/?Add2&Login=name&password=name&DomainID=678679
in my url finder and it works. I want to do the same thing with the
script...
Thanks in advance for your help

 #!/usr/bin/perl
 open(LIST,"names.txt");
 @array=<LIST>;
 close(LIST);
 $number = "0";
 foreach $name (@array ) {
 $number ++;
 chomp($name);
#code in question....
 print "Location:
http://my.com/?Add2&Login=$name&password=$name&DomainID=678679";
  sleep(3);
 }
 print qq~Success~;



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

Date: Sat, 18 Nov 2000 22:15:12 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: print 'Location:
Message-Id: <slrn91dvrf.jm5.tjla@thislove.dyndns.org>

I was shocked! How could Tango <heh@bbbb.org>
say such a terrible thing:
>This is a multi-part message in MIME format.

>I don't know

Troll, go away.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Everybody wants to go to heaven, but nobody wants to die.


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

Date: Fri, 17 Nov 2000 15:58:08 +0100
From: "Johan Ditmar" <johan.ditmar@era.ericsson.se>
Subject: Problems saving an uploaded file.
Message-Id: <8v6jok$eq4$1@newstoo.ericsson.se>

Hi all,

I am using Apache 1.3 together with ActiveState Perl 5.6.0.618 and I have
the following problem. I want to upload a file from a webpage and save it at
a server. I am using the following code to do that:

   $bitfile = param("bitfile");

   open (SAVE,">./bitfile.bit") || die $!;
   binmode(SAVE);

    while ( read($bitfile,$data,1024) ) {
      print SAVE $data;
    }
   close SAVE;

What it does is that it takes the file handle and then saves the clients
file under 'bitfile.bit' on the server.

Sometimes this works, but many times it happens that the file is not saved
(it is created, but has size 0 or is only 1 byte long). I have enough space
on my disk and enough memory. Could this be a bug?

Johan




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

Date: Fri, 17 Nov 2000 15:58:08 +0100
From: "Johan Ditmar" <johan.ditmar@era.ericsson.se>
Subject: Problems saving an uploaded file.
Message-Id: <8v6lgs$i6h$1@newstoo.ericsson.se>

Hi all,

I am using Apache 1.3 together with ActiveState Perl 5.6.0.618 and I have
the following problem. I want to upload a file from a webpage and save it at
a server. I am using the following code to do that:

   $bitfile = param("bitfile");

   open (SAVE,">./bitfile.bit") || die $!;
   binmode(SAVE);

    while ( read($bitfile,$data,1024) ) {
      print SAVE $data;
    }
   close SAVE;

What it does is that it takes the file handle and then saves the clients
file under 'bitfile.bit' on the server.

Sometimes this works, but many times it happens that the file is not saved
(it is created, but has size 0 or is only 1 byte long). I have enough space
on my disk and enough memory. Could this be a bug?

Johan




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

Date: Fri, 17 Nov 2000 15:58:08 +0100
From: "Johan Ditmar" <johan.ditmar@era.ericsson.se>
Subject: Problems saving an uploaded file.
Message-Id: <8v6n94$lgn$1@newstoo.ericsson.se>

Hi all,

I am using Apache 1.3 together with ActiveState Perl 5.6.0.618 and I have
the following problem. I want to upload a file from a webpage and save it at
a server. I am using the following code to do that:

   $bitfile = param("bitfile");

   open (SAVE,">./bitfile.bit") || die $!;
   binmode(SAVE);

    while ( read($bitfile,$data,1024) ) {
      print SAVE $data;
    }
   close SAVE;

What it does is that it takes the file handle and then saves the clients
file under 'bitfile.bit' on the server.

Sometimes this works, but many times it happens that the file is not saved
(it is created, but has size 0 or is only 1 byte long). I have enough space
on my disk and enough memory. Could this be a bug?

Johan




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

Date: Fri, 17 Nov 2000 15:58:08 +0100
From: "Johan Ditmar" <johan.ditmar@era.ericsson.se>
Subject: Problems saving an uploaded file.
Message-Id: <8v6p1c$oih$1@newstoo.ericsson.se>

Hi all,

I am using Apache 1.3 together with ActiveState Perl 5.6.0.618 and I have
the following problem. I want to upload a file from a webpage and save it at
a server. I am using the following code to do that:

   $bitfile = param("bitfile");

   open (SAVE,">./bitfile.bit") || die $!;
   binmode(SAVE);

    while ( read($bitfile,$data,1024) ) {
      print SAVE $data;
    }
   close SAVE;

What it does is that it takes the file handle and then saves the clients
file under 'bitfile.bit' on the server.

Sometimes this works, but many times it happens that the file is not saved
(it is created, but has size 0 or is only 1 byte long). I have enough space
on my disk and enough memory. Could this be a bug?

Johan




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

Date: Fri, 17 Nov 2000 15:58:08 +0100
From: "Johan Ditmar" <johan.ditmar@era.ericsson.se>
Subject: Problems saving an uploaded file.
Message-Id: <8v6qpk$rtb$1@newstoo.ericsson.se>

Hi all,

I am using Apache 1.3 together with ActiveState Perl 5.6.0.618 and I have
the following problem. I want to upload a file from a webpage and save it at
a server. I am using the following code to do that:

   $bitfile = param("bitfile");

   open (SAVE,">./bitfile.bit") || die $!;
   binmode(SAVE);

    while ( read($bitfile,$data,1024) ) {
      print SAVE $data;
    }
   close SAVE;

What it does is that it takes the file handle and then saves the clients
file under 'bitfile.bit' on the server.

Sometimes this works, but many times it happens that the file is not saved
(it is created, but has size 0 or is only 1 byte long). I have enough space
on my disk and enough memory. Could this be a bug?

Johan




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

Date: Fri, 17 Nov 2000 15:58:08 +0100
From: "Johan Ditmar" <johan.ditmar@era.ericsson.se>
Subject: Problems saving an uploaded file.
Message-Id: <8v6sht$1ud$1@newstoo.ericsson.se>

Hi all,

I am using Apache 1.3 together with ActiveState Perl 5.6.0.618 and I have
the following problem. I want to upload a file from a webpage and save it at
a server. I am using the following code to do that:

   $bitfile = param("bitfile");

   open (SAVE,">./bitfile.bit") || die $!;
   binmode(SAVE);

    while ( read($bitfile,$data,1024) ) {
      print SAVE $data;
    }
   close SAVE;

What it does is that it takes the file handle and then saves the clients
file under 'bitfile.bit' on the server.

Sometimes this works, but many times it happens that the file is not saved
(it is created, but has size 0 or is only 1 byte long). I have enough space
on my disk and enough memory. Could this be a bug?

Johan




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

Date: Fri, 17 Nov 2000 15:58:08 +0100
From: "Johan Ditmar" <johan.ditmar@era.ericsson.se>
Subject: Problems saving an uploaded file.
Message-Id: <8v6ua5$50v$1@newstoo.ericsson.se>

Hi all,

I am using Apache 1.3 together with ActiveState Perl 5.6.0.618 and I have
the following problem. I want to upload a file from a webpage and save it at
a server. I am using the following code to do that:

   $bitfile = param("bitfile");

   open (SAVE,">./bitfile.bit") || die $!;
   binmode(SAVE);

    while ( read($bitfile,$data,1024) ) {
      print SAVE $data;
    }
   close SAVE;

What it does is that it takes the file handle and then saves the clients
file under 'bitfile.bit' on the server.

Sometimes this works, but many times it happens that the file is not saved
(it is created, but has size 0 or is only 1 byte long). I have enough space
on my disk and enough memory. Could this be a bug?

Johan




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

Date: Fri, 17 Nov 2000 15:58:08 +0100
From: "Johan Ditmar" <johan.ditmar@era.ericsson.se>
Subject: Problems saving an uploaded file.
Message-Id: <8v702f$85e$1@newstoo.ericsson.se>

Hi all,

I am using Apache 1.3 together with ActiveState Perl 5.6.0.618 and I have
the following problem. I want to upload a file from a webpage and save it at
a server. I am using the following code to do that:

   $bitfile = param("bitfile");

   open (SAVE,">./bitfile.bit") || die $!;
   binmode(SAVE);

    while ( read($bitfile,$data,1024) ) {
      print SAVE $data;
    }
   close SAVE;

What it does is that it takes the file handle and then saves the clients
file under 'bitfile.bit' on the server.

Sometimes this works, but many times it happens that the file is not saved
(it is created, but has size 0 or is only 1 byte long). I have enough space
on my disk and enough memory. Could this be a bug?

Johan




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

Date: Sat, 18 Nov 2000 20:32:05 -0800
From: "Mauro" <-@-.com>
Subject: Re: simple question: can Perl do this? (talking to a permanent opened prog.)
Message-Id: <8v6led$juc$1@nslave3.tin.it>

in the real case I use more sophisticated reg exps than thoose I put in the
example..

I'll try with the suggestionsof Honza Pazdziora..   I'll post the results

thanks
Marco



"Ken Dunlap" <kd@panix.com> wrote in message
news:8v6b6h$rtl$1@news.panix.com...
> If it is possible for you to eliminate the metecharacters in the
> regular expressions, they should compile and run much faster.
>
> Ken
>
> Mauro <-@-.com> wrote:
> > I think this is a simple question but I can't figure out how can I do
it:
> > I've a site with a PERL  CGI   that  performs thousands of consecutive
> > substitutions like:
>
> > $foobar=~s/.*un.*/one/;
> > $foobar=~s/.*deux.*/two/;
> > $foobar=~s/.*trois.*/three/;
> > $foobar=~s/.*quatre.*/four/;
> > $foobar=~s/.*cinq.*/five/;
> > and so on...
>
> > doing thousands of theese substitutions takes too much time in perl
>
> > I saw the same substitutions executed by a unix SED (all contained in a
> > script-file) takes a lot less time
>
> > The server is a Intel P3-500,  start time of the  SED -f script.sed  is
> > about 8 seconds because script.sed is 10MB (!) in size  but the "answer"
> > time from STDIN to STDOUT  is about 1 sec.
>
> > how can I open SED only _ONE TIME_(ie. when I start Apache..) and  do
that
> > when  the user calls the CGI  it just pass  the request (a french
number)
> > to the STDIN of SED and read STDOUT?
>
> > (I know it could be a problem if two+ users do a request at the
same/near
> > time)
>
> > thanks to any guru who know how to do it!
>
> > Marco
>
>
>
> --
> --
> The only thing to fear is fearlessness
> REM




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

Date: Sat, 18 Nov 2000 21:52:34 GMT
From: dtbaker_dejanews@my-deja.com
Subject: Re: solution: installing Image::Magick to host as non-root user
Message-Id: <8v6tn1$54l$1@nnrp1.deja.com>

In article <sean-A34607.22530317112000@usenet.plus.net>,
  Sean W <sean@motorsports.co.uk> wrote:
> I tried to follow your guide but I keep getting the following error
when
> I try to configure it
>
> configuring ImageMagick 5.2.0
> checking host system type... configure: error: cannot guess host type;
> you must
> specify one
>
> Can anyone shed any light on this
------------------------------------------

ya got me... my installation was on a LINUX host machine. what are you
trying to install on?

Dan


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sat, 18 Nov 2000 15:23:44 -0600
From: "StevieD" <stevie_d38nospam@hotmail.com>
Subject: views and/or cursors with DBD::mysql ??
Message-Id: <5qCR5.30$Uj7.70159@nnrp2.sbc.net>

Hi - moderate perl ability, only simple SQL knowledge ... i can't for the
life of me find any documentation or get anything to work in order to create
a temporary table or cursor or define a table view using DBD::mysql ...

I need to create two recordsets and then reference them both with a normal
SQL statement but any SQL examples i've seen like:

CREATE VIEW view1 AS SELECT zipcode FROM testTable
or
SELECT zipcode FROM testTable INTO CURSOR tempTable1

just gives me: "DBD::mysql::st execute failed: You have an error in your SQL
syntax near 'VIEW view1 AS SELECT zipcode FROM testTable' at line 1 at
view.cgi line 60. " etc

I can't seem to find reference to how to do this in the DBD::mysql or DBI
docs, and any SQL tutorials they link to do just what i've done above ....
i've tried various use of paranthesis and other variations and nothings
seems to work. Would appreciate any help or where to look for info on this
 ... Thanks!

-Steve





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

Date: Sat, 18 Nov 2000 19:40:33 +0100
From: Pavel Hlavnicka <pavel@gingerall.cz>
Subject: Why SvSETMAGIC?
Message-Id: <3A16CD21.6080301@gingerall.cz>

Could some hacker tell me, why this xs declaration:

void
test_func(in, out)
  char *in
  char *out
  CODE:
  out = in;
  OUTPUT:
  out

generates this:

XS(XS_Test_test_func)
{
     dXSARGS;
     if (items != 2)
	croak("Usage: Test::test_func(in, out)");
     {
	char *	in = (char *)SvPV(ST(0),PL_na);
	char *	out = (char *)SvPV(ST(1),PL_na);
#line 14 "Test.xs"
	out = in;
#line 28 "Test.c"
	sv_setpv((SV*)ST(1), out);
	SvSETMAGIC(ST(1));
     }
     XSRETURN_EMPTY;
}


The only thing I can't understand is the SvSETMAGIC macro

Thanks in advance.

Pavel

-- 
Pavel Hlavnicka
Ginger Alliance Ltd.
Prague; Czech Republic



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

Date: Sat, 18 Nov 2000 19:29:22 +0100
From: Pavel Hlavnicka <pavel@gingerall.cz>
To: glenn@greenoak.com
Subject: Re: XSUB output strings
Message-Id: <3A16CA82.8090602@gingerall.cz>

The right version of your code (causing segfaults) is following:

void
     newfunc(instring,outstring)
     char *instring
     char *outstring
     CODE:
     outstring = instring;
     OUTPUT:
     outstring

See *.c file to find out why.

(There is no guaranted size of buffer currently allocated for outstring 
in you example)


gleNOSPAMnn@greenoak.com wrote:

> I have a question about output strings with XSUB. If I simply want to
> have an output string parameter, the following appears to work fine:
> 
> void
> newfunc(instring,outstring)
>    char *instring
>    char *outstring
>    CODE:
>    strcpy(outstring, instring);
>    OUTPUT:
>    outstring
> 
> 
> My question however, is: how much space has been allocated for outstring?
> How do I know how long a string I can put into it? How can I safely ensure
> that enough space has been allocated for it? Thanks.


-- 
Pavel Hlavnicka
Ginger Alliance Ltd.
Prague; Czech Republic



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

Date: Sat, 18 Nov 2000 14:19:35 -0600
From: eric <eric@urbanrage.com>
Subject: Re: XSUB output strings
Message-Id: <3A16E457.D03922EC@urbanrage.com>

gleNOSPAMnn@greenoak.com wrote:
> 
> I have a question about output strings with XSUB. If I simply want to
> have an output string parameter, the following appears to work fine:
> 
> void
> newfunc(instring,outstring)
>    char *instring
>    char *outstring
>    CODE:
>    strcpy(outstring, instring);
>    OUTPUT:
>    outstring
> 
> My question however, is: how much space has been allocated for outstring?
> How do I know how long a string I can put into it? How can I safely ensure
> that enough space has been allocated for it? Thanks.

you probably don't want to use strcpy...  I'd look into creating a new
SV* (scalar value pointer)

SV*
 newfunc(instring)
	char* instring
	CODE:
		RETVAL = newSVpv(instring, 0);
	OUTPUT:
		RETVAL


in the newSVpv the zero represents the length, if you use zero perl will
try and determine the length.

If you don't want to do something like this perl has it's own memory
allocation routines that you want to use (they eventually call the
system ones, but they have things like statistics and garbage
collection)

from the table on page 365 of jaguar (advanced perl programming)

malloc         New
free           Safefree
realloc        Renew
calloc         Newz
memcpy         Move
memmove        Copy
memzero        Zero

another advantage of using perl's interfaces is that your code is more
portable (not relying on unixy things)


Hope this helps,

Eric
 eric@urbanrage.com
 Brainbench MVP for Unix Programming
 http://www.brainbench.com


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

Date: 18 Nov 2000 22:39:24 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: XSUB output strings
Message-Id: <8v70es$l2d$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to eric 
<eric@urbanrage.com>],
who wrote in article <3A16E457.D03922EC@urbanrage.com>:
> > I have a question about output strings with XSUB. If I simply want to
> > have an output string parameter, the following appears to work fine:
> > 
> > void
> > newfunc(instring,outstring)
> >    char *instring
> >    char *outstring
> >    CODE:
> >    strcpy(outstring, instring);
> >    OUTPUT:
> >    outstring

To output string as a *result*, mark the output value as char*, and
set RETVAL.  This assumes newer syntax (5.6.0):

  char* newfunc(char *instring)
	CODE:
	  RETVAL = instring;

If you want to modify an argument, the simplest way is to get it as an
SV*, and set the value:

  void
  newfunc(instring,outstring)
     char *instring
     SV	  *outstring
    CODE:
     sv_setpv(outstring, instring, 0);

> If you don't want to do something like this perl has it's own memory
> allocation routines that you want to use (they eventually call the
> system ones, but they have things like statistics and garbage
> collection)

In addition to what you listed, there is savepv() (which is a misnomer
for copy_pv()) which may be used like this:

  void
  newfunc(instring,outstring)
     char *instring
     char *outstring
    CODE:
     outstring = savepv(instring);
    OUTPUT:
     outstring

Ilya


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

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 V9 Issue 4919
**************************************


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