[25811] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8050 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 4 18:05:39 2005

Date: Wed, 4 May 2005 15:05:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 4 May 2005     Volume: 10 Number: 8050

Today's topics:
    Re: a numbering question <abigail@abigail.nl>
    Re: Filling the Perl Stack <tassilo.von.parseval@rwth-aachen.de>
    Re: Filling the Perl Stack <guenther.sohler@newlogic.com>
    Re: How do I parse certain "bits" out of bytes? <tadmc@augustmail.com>
    Re: How do I parse certain "bits" out of bytes? <joe@inwap.com>
    Re: How do I parse certain "bits" out of bytes? <joe@inwap.com>
        why test ret-val of EACH cmd (example!): (David Combs)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 04 May 2005 19:59:15 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: a numbering question
Message-Id: <slrnd7iacj.4ql.abigail@alexandra.abigail.nl>

Geoff Cox (geoff.cox@notquitecorrectfreeuk.com) wrote on MMMMCCLXIV
September MCMXCIII in <URL:news:d8ih715j12ahn6foloap88jqhsrv1uljtu@4ax.com>:
))  Hello,
))  
))  I have some images named as
))  
))  pic001.gif through pic010.gif to pic200.gif
))  
))  I am not clear how I can use something like
))  
))  pic$number++
))  
))  any pointers please!


$ perl -wle '$f = "pic001"; print + $f ++ . ".gif" for 1 .. 10'
pic001.gif
pic002.gif
pic003.gif
pic004.gif
pic005.gif
pic006.gif
pic007.gif
pic008.gif
pic009.gif
pic010.gif


Abigail
-- 
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_;
sub   _   {push         @_ => /::(.*)/s and goto &{ shift}}
sub shift {print shift; @_              and goto &{+shift}}
Hack ("Just", "Perl ", " ano", "er\n", "ther "); # 20050504


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

Date: Wed, 4 May 2005 20:00:57 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Filling the Perl Stack
Message-Id: <slrnd7i3ep.se.tassilo.von.parseval@localhost.localdomain>

Also sprach Guenther Sohler:

> In my embedded perl I decided to handle a 2D coordinate as
> a anonymous reference to an array of 2 numbers like
> [ 5.6 , 3.4 ]
>
> Therefore a list of points would be like
>
> [ [ 1,2 ] , [ 3,4 ] , [ 5,6] ]
>
> In C I want to put this onto the perl stack.
>
> I have written this C code.
>
>
> int j;
> AV *points=newAV();
> for(j=0;j<pars[i].points.len();j++)
> {
> 	AV *point=newAV();
> 	av_push(point,newSVnv(pars[i].points[j].x*l.unit_db));
> 	av_push(point,newSVnv(pars[i].points[j].y*l.unit_db));
> 	av_push(points,newSVrv((SV *) point,NULL));
> }
> XPUSHs(sv_2mortal(newSVrv((SV *) points,NULL)));

Whitespaces are not a scarce resource, so use them in your code.

Other than that, what is the context codewise of the above snippet?
Evidently it is taken from an XSUB, but how do you return from it? Does
it end on

    XSRETURN(1);

?

> But the data does not arrive in the perl function.
> Did I do an error ?
> Do I have to use more/less mortal ??

The mortalizing seems correct. Values in arrays and hashes are
non-mortal, everything returned to the caller should be mortal.

> Do I have to free/not free any references, arrays :?

As the above looks correct, that should be taken care of by perl's
garbage-collecting.

> The perl code looks like
>
> sub test
> {
>         $coords=shift;
>         print scalar(@$coords)." coords found\n";
> }

That's not too helpful. You haven't shown the part where the XSUB is
called. Also, we don't really know what the XSUB looks like. Relevant
parts of the XSUB would be the declaration and how it processes its
arguments (if any), the population of the array-to-be-returned (which
you showed above) and the actual returning to the caller.

Tassilo
-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);


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

Date: Wed, 04 May 2005 21:56:44 +0200
From: Guenther Sohler <guenther.sohler@newlogic.com>
Subject: Re: Filling the Perl Stack
Message-Id: <pan.2005.05.04.19.56.40.376426@newlogic.com>

Dear Tassilo,

thank you for all your answers.

I supposed, that the complete c function calling the perl xsub is not
interesting, because all the rest works. just putting a list
of "coorindates" onto the perl stack does not seem to work.
I dont use the xsubpp compiler. I have everything integrated into my c
program(and it works for everything else)

However I will paste all my function now:



int perl_call(char *func,GsList<PCellParam> &pars)
{
        int i,ret;
        dSP;
        ENTER;
        SAVETMPS;
        PUSHMARK(SP);
        for(i=0;i<pars.len();i++)
        {
                switch(pars[i].type)
                {
                        case PCELL_PAR_NUMBER:
                        case PCELL_PAR_BOOLEAN:
                                XPUSHs(sv_2mortal(newSViv(pars[i].number)));
                                break;
                        case PCELL_PAR_METRIC:
                                XPUSHs(sv_2mortal(newSVnv(pars[i].metric)));
                                break;
                        case PCELL_PAR_STRING:
                                XPUSHs(sv_2mortal(newSVpv(pars[i].string.str(),0)));
                                break;
                        case PCELL_PAR_CHOICE:
                                XPUSHs(sv_2mortal(newSVpv(pars[i].string.str(),0)));
                                break;
                        case PCELL_PAR_POINTS:
                                {
                                        int j;
                                        AV *points=newAV();
                                        for(j=0;j<pars[i].points.len();j++)
                                        {
                                                AV *point=newAV();
                                                av_push(point,newSVnv(pars[i].points[j].x*l.unit_db));
                                                av_push(point,newSVnv(pars[i].points[j].y*l.unit_db));
                                                av_push(points,newSVrv((SV *) point,NULL));
                                        }
                                        XPUSHs(sv_2mortal(newSVrv((SV *) points,NULL)));
                                }
                                break;
                        default: printf("Unsupported Variable type!\n");
                                exit(1);
                                break;

                }
        }
        PUTBACK;
        ret=call_pv(func,G_SCALAR);
        SPAGAIN;
        PUTBACK;
        FREETMPS;
        LEAVE;
        return ret;
}

Maybe you see an error ...

Thank you for your help





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

Date: Wed, 4 May 2005 13:28:07 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How do I parse certain "bits" out of bytes?
Message-Id: <slrnd7i51n.87q.tadmc@magna.augustmail.com>

Adam Schneider <schneiderNOSPAM@N0SPAM.pobox.com> wrote:

> To the rest of you, my apologies for
> trespassing in your little clubhouse.


So long then!


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


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

Date: Wed, 04 May 2005 13:28:46 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: How do I parse certain "bits" out of bytes?
Message-Id: <maudnVRUXc8YreTfRVn-rA@comcast.com>

Adam Schneider wrote:

>>Simplified, this just cuts off the last three bits. The trailing "&0x1f"
>>(or "&0b00011111") part ensures that only the last 5 bits are used. This
>>could be only a problem if there are more than 8 bits stored in $n.
> 
> Now, what do you
> mean when you say "this could be only a problem if there are more than
> 8 bits"?  Because in my real-world example, I need to get data from 32
> bits.  Can I not use these same techniques?

If you have an 8-bit number and shift it right 3 bits, then you have
a 5-bit quantity.  If all you are interested in is those 5 bits,
then fine.

If you have a 32-bit number and shift it right 3 bits, then you have
a 29-bit quantity.  If all you are interested in is 5 bits, then you
will have to perform an extra step to ensure that you are getting only
5 bits.  That's where the 'AND' operation comes in.

	-Joe


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

Date: Wed, 04 May 2005 13:53:59 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: How do I parse certain "bits" out of bytes?
Message-Id: <6pCdnaODG5Dwq-TfRVn-hg@comcast.com>

Adam Schneider wrote:
> I still have no idea how to extract
> a few bits out of a longer string of bytes.  The help files all seem to
> have been written with the assumption that I majored in computer
> science and learned how to program years ago in some pre-Perl language

Whenever dealing with bits or bytes, it is assumed that the student
has been exposed to Computer Science 101 where they teach you about
the basics: numbering systems, bit positions, AND/OR/XOR.  Almost
any tutorial on binary numbers will provide you with the nomenclature
and concepts you need to know.

You are somewhat correct in describing it as "some pre-Perl language"
in that the concepts existed before Perl.  But operations with binary
bits is not "programming from years ago"; it is also part of programming
in modern languages.
	-Joe


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

Date: 4 May 2005 15:10:15 -0400
From: dkcombs@panix.com (David Combs)
Subject: why test ret-val of EACH cmd (example!):
Message-Id: <d5b6mn$n7m$1@panix1.panix.com>

Just for use when warning people to test return-values,
here's this post I just saw on comp.unix.solaris:


| comp.unix.solaris #503931 (367 + 1662 more)                                                                                       |    |    \-(1)--(1)+-(1)
| Newsgroups: comp.unix.programmer,comp.unix.solaris                                                                                |    |              \-(1)
| [1] Re: implicit -e in Solaris /bin/sh on cd?                                                                                     |    \-(1)--(1)
| From: Casper H.S. Dik <Casper.Dik@Sun.COM>                                                                                        \-(1)+-(1)
| Date: Sat Apr 16 16:39:29 EDT 2005                                                                                                     |-(1)
| Lines: 47                                                                                                                              \-[1]
| 
| Oscar del Rio <delrio@mie.utoronto.ca> writes:
| 
| >Henry Townsend wrote:
| >>     % /bin/sh -c "cd /xxxx; /bin/pwd"
| >> On Linux, this gives an error for the cd and thn proceeds to run 
| >> /bin/pwd (as it should IMHO):
| 
| >not so good if the command is supposed to run in /xxxx, think of
| 
| >cd /xxxx; rm -rf *
| 
| 
| Indeed; one day a rather distraught Sun Service person turned up
| at my desk, fearing that one of his customers systems had gotten hacked.
| He brought with him a disk.
| 
| I examined this disk; I was particularly worried about hacks because the
| system didn't run anyting much at al, nothing from inetd anyway.
| 
| Then I found that they had a ksh script which went as follows:
| 
| 
| 
| for dir in <list of dirs>
| do
|         cd $dir
|         find . -mtime -30 -exec rm {} \;
| done
| 
| Unfortunately, this was run as root, the first directory didn't
| exist (had in fact been removed just prior to the incident) and
| the find proceeded to remove all files until the point it removed
| /usr/lib/ld.so.1; then it stopped removing stuff but rather started
| logging errors.
| 
| In the end I managed to recover the list of file printed by find
| to tmpfs (/tmp/cron..*).
| 
| It was a "ksh" script; had it been a "sh" script it would not
| have failed in this manner.
| 
| Casper
| -- 
| Expressed in this posting are my opinions.  They are in no way related
| to opinions held by my employer, Sun Microsystems.
| Statements on Sun products included here are not gospel and may
| be fiction rather than truth.
| End of article 503931 (of 505348) -- what next? [npq] 
| 

(Now watch me go off and do that very thing!)

David




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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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