[31247] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2492 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 25 21:09:42 2009

Date: Thu, 25 Jun 2009 18:09:08 -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           Thu, 25 Jun 2009     Volume: 11 Number: 2492

Today's topics:
        Calling 'C' routines from perl. <prathap.bgl@gmail.com>
    Re: Calling 'C' routines from perl. <peter@makholm.net>
    Re: Calling 'C' routines from perl. <ben@morrow.me.uk>
    Re: Calling 'C' routines from perl. <tzz@lifelogs.com>
    Re: Calling 'C' routines from perl. <tadmc@seesig.invalid>
    Re: Calling 'C' routines from perl. <prathap.bgl@gmail.com>
    Re: Calling 'C' routines from perl. <glex_no-spam@qwest-spam-no.invalid>
    Re: Calling 'C' routines from perl. <No_4@dsl.pipex.com>
    Re: Calling 'C' routines from perl. <ben@morrow.me.uk>
    Re: dup hash ref in array <tadmc@seesig.invalid>
    Re: matching two strings sln@netherlands.com
    Re: matching two strings <someone@example.com>
        Using end of line in character class <nilesh.da@gmail.com>
    Re: Using end of line in character class <NoSpamPleaseButThisIsValid3@gmx.net>
    Re: Using end of line in character class <tadmc@seesig.invalid>
    Re: XML Parser <tadmc@seesig.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 25 Jun 2009 09:16:23 -0700 (PDT)
From: Prathap <prathap.bgl@gmail.com>
Subject: Calling 'C' routines from perl.
Message-Id: <7619cb17-5cbe-4610-b3d3-f5c63d3c9ca7@p21g2000prn.googlegroups.com>

Hi All:


  Can someone let me know how to invoke a 'C' routine from perl. I
have to develop an application
  that requires Perl and C interactions. I need to know this in
detail. Please provide me with exmples or referances where I can learn
this.

   Thanks for the help in advance.

Regards,
Prathap


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

Date: Thu, 25 Jun 2009 18:25:44 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: Calling 'C' routines from perl.
Message-Id: <87prcs1drr.fsf@vps1.hacking.dk>

Prathap <prathap.bgl@gmail.com> writes:

>   Can someone let me know how to invoke a 'C' routine from perl. I
> have to develop an application

I believe that the easiest way is to look at Inline::C. 

//Makholm


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

Date: Thu, 25 Jun 2009 17:22:04 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Calling 'C' routines from perl.
Message-Id: <cqkch6-gov.ln1@osiris.mauzo.dyndns.org>


Quoth Prathap <prathap.bgl@gmail.com>:
> 
>   Can someone let me know how to invoke a 'C' routine from perl. I
> have to develop an application
>   that requires Perl and C interactions. I need to know this in
> detail. Please provide me with exmples or referances where I can learn
> this.

    perldoc perlxstut
    perldoc perlxs
    perldoc Inline::C

Ben



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

Date: Thu, 25 Jun 2009 13:57:49 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Calling 'C' routines from perl.
Message-Id: <87eit8rviq.fsf@lifelogs.com>

On Thu, 25 Jun 2009 09:16:23 -0700 (PDT) Prathap <prathap.bgl@gmail.com> wrote: 

P>   Can someone let me know how to invoke a 'C' routine from perl. I
P> have to develop an application
P>   that requires Perl and C interactions. I need to know this in
P> detail. Please provide me with exmples or referances where I can learn
P> this.

I've been happy with Swig.  It works with C++ as well and generates glue
libraries that work with Java and other languages.

Ted


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

Date: Thu, 25 Jun 2009 15:44:18 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Calling 'C' routines from perl.
Message-Id: <slrnh47o7n.f4d.tadmc@tadmc30.sbcglobal.net>

Prathap <prathap.bgl@gmail.com> wrote:


>   Can someone let me know how to invoke a 'C' routine from perl.


    perldoc -q ' C '

        Where can I learn about linking C with Perl?


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Thu, 25 Jun 2009 13:56:32 -0700 (PDT)
From: Prathap <prathap.bgl@gmail.com>
Subject: Re: Calling 'C' routines from perl.
Message-Id: <3eb16b01-5714-49cd-87bd-0c6002a4e90e@j9g2000prh.googlegroups.com>

On Jun 26, 1:44=A0am, Tad J McClellan <ta...@seesig.invalid> wrote:
> Prathap <prathap....@gmail.com> wrote:
> > =A0 Can someone let me know how to invoke a 'C' routine from perl.
>
> =A0 =A0 perldoc -q ' C '
>
> =A0 =A0 =A0 =A0 Where can I learn about linking C with Perl?
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Thanks for all the suggestions. Can you please explain with an example
why and how swig is useful?
How do I make C libraries and finally infoke them from Perl. It will
be of great quick help for me.

Regards,
Prathap


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

Date: Thu, 25 Jun 2009 16:36:22 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Calling 'C' routines from perl.
Message-Id: <4a43edd6$0$89392$815e3792@news.qwest.net>

Prathap wrote:
> On Jun 26, 1:44 am, Tad J McClellan <ta...@seesig.invalid> wrote:
>> Prathap <prathap....@gmail.com> wrote:
>>>   Can someone let me know how to invoke a 'C' routine from perl.
>>     perldoc -q ' C '
>>
>>         Where can I learn about linking C with Perl?
[...]
> 
> Thanks for all the suggestions. Can you please explain with an example
> why and how swig is useful?

Can you please take the time to use your browser and find it yourself?

> How do I make C libraries and finally infoke them from Perl. It will
> be of great quick help for me.

http://www.swig.org/


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

Date: Fri, 26 Jun 2009 00:40:38 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Calling 'C' routines from perl.
Message-Id: <luydnfrGOttql9nXnZ2dnUVZ8smdnZ2d@pipex.net>

Prathap wrote:

> Thanks for all the suggestions. Can you please explain with an example
> why and how swig is useful?

Find a module on CPAN that uses it (so may not be using swig, but will be 
doing what you want).
Look for a *.xs file.
Then read it, along with the perldoc perlxstut and perldoc perlxs mentioned 
earlier.

-- 
              Just because I've written it doesn't mean that
                   either you or I have to believe it.


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

Date: Fri, 26 Jun 2009 01:59:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Calling 'C' routines from perl.
Message-Id: <54jdh6-rki1.ln1@osiris.mauzo.dyndns.org>


Quoth Prathap <prathap.bgl@gmail.com>:
> On Jun 26, 1:44 am, Tad J McClellan <ta...@seesig.invalid> wrote:
> > Prathap <prathap....@gmail.com> wrote:
> > >   Can someone let me know how to invoke a 'C' routine from perl.
> >
> >     perldoc -q ' C '
> >
> >         Where can I learn about linking C with Perl?
> 
> Thanks for all the suggestions. Can you please explain with an example
> why and how swig is useful?

I would stay away from SWIG. Its primary purpose is to create bindings
for lots of different languages from one source file, and IME perl
extensions built with SWIG (e.g. the SVN bindings) tend to be somewhat
awkward to use.

> How do I make C libraries and finally infoke them from Perl. It will
> be of great quick help for me.

You give the impression that you haven't even written the C yet. You
need to do that first, and here is not the place to ask for help with
that. If you don't have a library that you know how to invoke from C,
you haven't a hope of invoking it from Perl.

You also need to read some of the documentation you have been pointed
at, and try writing something for yourself. You will not get any useful
help here until you say something like 'I wrote an XS/Inline::C file
that looks like this, and I expected X, but I got Y instead'.

Ben



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

Date: Thu, 25 Jun 2009 06:14:26 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: dup hash ref in array
Message-Id: <slrnh46mr9.9di.tadmc@tadmc30.sbcglobal.net>

Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth monkeys paw <noboey@home.com>:
>> Ben Morrow wrote:
>> > Quoth monkeys paw <noboey@home.com>:
>> >>
>> >> $VAR1 = [
>> >>            {
>> >>              'xxx' => 1,
>> >>              'yyy' => 2,
>> >>              'zzz' => 3
>> >>            },
>> >>            $VAR1->[0],
>> >>            $VAR1->[0]
>> >>          ];
>> > 
>> > ...and your question is?
>> > 
>> > That is exactly what I would expect it to produce. What were you
>> > expecting?
>> > 
>> My question would be then, why does data::dumper show $var1->[0],
>> instead of the values? The array exists as i expected, i was
>> thrown by data::dumper  interpretation.
>
> As Tad said, you need to read the docs for Data::Dumper. You also need
> to read perldoc perlreftut until you understand it.
>
> Something that might help: consider the output of this:
>
>     my $href = { a => 1 };
>     my @ary  = ($href, $href);
>
>     warn $ary[0]{a};
>     $ary[1]{a} = 2;
>     warn $ary[0]{a};


Probably even more helpful, consider the output of this:

    my $href = { };
    $href->{self} = $href;

    use Data::Dumper;
    print Dumper $href;

If it did what you expected, it would run for "a really long time":

$VAR1 = {
          'self' => {
                      'self' => {
                                  'self' => {
                                              'self' => {
                                                          'self' => ...


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Thu, 25 Jun 2009 00:37:19 -0700
From: sln@netherlands.com
Subject: Re: matching two strings
Message-Id: <37a6455qcl764aojeih1m3at2719qk95jp@4ax.com>

On Wed, 24 Jun 2009 21:49:59 -0700, sln@netherlands.com wrote:

>On Tue, 23 Jun 2009 08:46:49 +0200, Peter Makholm <peter@makholm.net> wrote:
>
>>Ben Morrow <ben@morrow.me.uk> writes:
>>
>>>> When I benchmarked grep vs. any, grep won by being 25% faster on
>>>> random indata by avarage, even tough I naivly would have expected any
>>>> to win. 
>>>
>>> Wow. Is a sub call really that expensive?
>>
>>I'm not really sure what is happening and unfortunatly I didn't seem
>>to keep my benchmarking code. I wrote about it at 
>>
>>  http://peter.makholm.net/2009/05/26/benchmarking-is-hard/
>>
>>I might have used Jason Switchers code modified to only use one
>>needle and array. 
>>
>>//Makholm
>
>I don't see how grep is faster than anything.
>
>-sln
>
>---------------------------
>use strict;
>use warnings;
>use Benchmark ':hireswallclock';
>
>my @rxs = (qr/one/, qr/two/, qr/three/);
>my @strings =
># (
>#  'two three one',
>#  'one three ',
>#  'three two',
>#  'three',
>#  ' '
># );
> (
>  'one two three',
>  'one two three',
>  'one two three',
>  'one two three',
> );
>my ($pass,$val,$string,$rxs,$t0,$t1,$tdif);
>
>
>$t0 = new Benchmark;
>for (1..10_000) {
>  foreach $string (@strings) {
>	if ( not $val = grep $string !~ $_, @rxs)
>	{
>		# print "grep !$val = yes\n";
>	} else {
>		# print "grep !$val = no\n";
>	}
>  }
>}
>$t1 = new Benchmark;
>print "grep code took:",timestr( timediff($t1, $t0) ),"\n";
>
>
>$t0 = new Benchmark;
>for (1..10_000) {
>STRING:
>  for (@strings) {
>	for $rxs (@rxs) {
>		if ( !/$rxs/)
>		{
>			# print "var && no\n";
>			next STRING;
>		}
>	}
>	# print "var && yes\n";
>  }
>}
>
>$t1 = new Benchmark;
>print "(1)&& code took:",timestr( timediff($t1, $t0) ),"\n";
>
>$t0 = new Benchmark;
>for (1..10_000) {
>  for (@strings) {
>	if ( /one/ && /two/ && /three/)
>	{
>		# print "const && yes\n";
>	} else {
>		# print "const && no\n";
>	}
>
>  }
>}
>$t1 = new Benchmark;
>print "(2)&& code took:",timestr( timediff($t1, $t0) ),"\n";
>
>__END__
>Output:
>grep code took:0.207262 wallclock secs ( 0.20 usr +  0.00 sys =  0.20 CPU)
>(1)&& code took:0.246479 wallclock secs ( 0.25 usr +  0.00 sys =  0.25 CPU)
>(2)&& code took:0.0333102 wallclock secs ( 0.03 usr +  0.00 sys =  0.03 CPU)

Because grep is oblivous to early, its square like a matrix.

-sln


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

Date: Thu, 25 Jun 2009 04:12:00 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: matching two strings
Message-Id: <5YI0m.21820$Lm.7762@newsfe24.iad>

sln@netherlands.com wrote:
> 
> Because grep is oblivous to early, its square like a matrix.

What range is described by "oblivous to early" (whatever oblivous is)? 
How do you get from one to the other and along what route?  You are 
using the possessive pronoun "its" on what object?  And how does that 
object possess a "square like a matrix"?



John
-- 
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov


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

Date: Thu, 25 Jun 2009 03:09:58 -0700 (PDT)
From: Nilesh <nilesh.da@gmail.com>
Subject: Using end of line in character class
Message-Id: <5ed2d0d3-015c-4019-9b59-e5889c8bb074@r16g2000vbn.googlegroups.com>

Hi,

I am trying extract specific value out of URL query. Here is the
example.

my $text = "http://localhost/news.xmlapi/
StoryResponse.aspxServ=RT&Pkey=1245445784nSP376208-20090619210944-2-
FRT";
#my $text = "http://localhost/news.xmlapi/StoryResponse.aspx?
Pkey=124544 84nSP376208-20090619210944-2-FRT&Serv=RT";

if($text =~ m/&*Serv=(.*)[&$]/)
{
        printf "$1\n";
} else {
        printf "not matched";
}

it gives follwing error.
Unmatched [ in regex; marked by <-- HERE in m/&*Serv=(.*)[ <-- HERE
&5.008008/ at ./x.pl line 6

If I remove $ from character class then it works fine for first text.
But it does not work for commented definition of text which is also
possible case.

I don't know what is wrong with $(end of line) in character classs.

Thanks,
Nilesh



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

Date: Thu, 25 Jun 2009 12:51:03 +0200
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: Using end of line in character class
Message-Id: <4a435697$0$31876$9b4e6d93@newsspool3.arcor-online.net>

Nilesh schrieb:
> if($text =~ m/&*Serv=(.*)[&$]/)
> 
> it gives follwing error.
> Unmatched [ in regex; marked by <-- HERE in m/&*Serv=(.*)[ <-- HERE
> &5.008008/ at ./x.pl line 6

$] is a variable containing the Perl version. See perldoc perlvar.

But then, as you are using a character class, you are looking for the
letter "$", not for the end of a line. So don't use a character class.
You need to look for "&" OR end of line: (&|$). Then, .* is greedy,
that's not what you want, so add a ?. Additionally, &* in the beginning
of your regexp is useless.

You propably want something like
-> if ($text =~ /Serv=(.*?)(?:&|$)/) { ...

- Wolf


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

Date: Thu, 25 Jun 2009 07:12:14 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Using end of line in character class
Message-Id: <slrnh46q7l.9di.tadmc@tadmc30.sbcglobal.net>

Nilesh <nilesh.da@gmail.com> wrote:

> #my $text = "http://localhost/news.xmlapi/StoryResponse.aspx?
> Pkey=124544 84nSP376208-20090619210944-2-FRT&Serv=RT";


Wolf's followup answers your question, but I see two fundamental
problems in your mental model that I'd like to try and help
clear up.

I could see both errors just from:

    Subject: Using end of line in character class

without even reading the body of your message.


First, $ does not mean "end of line", it means "end of string"
(unless you have m//m).

and in fact, your data above is not a "line" (because it does
not have a "line terminator").

If it _did_ have   $text = "...Serv=RT\n"  then another solution
to your problem would have been:

    /Serv=([^&\n]+)/


The second problem is that a character class always matches a
single character, that is, it matches things of length one.

The end of string anchor never matches any characters, that is,
it matches things of length zero. (it matches a "position" in the string)

Expecting something that matches zero-length things to match 
things of length one is a false expectation.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Thu, 25 Jun 2009 06:44:03 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: XML Parser
Message-Id: <slrnh46oiq.9di.tadmc@tadmc30.sbcglobal.net>

taz <tazwin1@yahoo.com> wrote:

> I am
> using xml simple to retrieve the needed information. I am getting all
> the information I need, but when I pull it out of the XML I am getting
> entities converted to their single characters (&amp;) becomes &, etc.


 .. so then, if your source XML had "&amp;amp;" in it, you would
end up with "&amp;" in the result...


> Is there a way to keep the entity or do I have to use something else


If your XML is truly "simple" (eg. no CDATA sections) then you
can take the simple-minded approach of preprocessing your XML
before feeding it to XML::Simple:

    $xml =~ s/&/&amp;/g;

or, if you'd like to be a little more careful with your hack:

    $xml =~ s/&(\w+;)/&amp;$1/g;


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

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 V11 Issue 2492
***************************************


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