[26091] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8291 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 29 18:05:37 2005

Date: Fri, 29 Jul 2005 15:05:06 -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           Fri, 29 Jul 2005     Volume: 10 Number: 8291

Today's topics:
    Re: Converting a 4 byte field to integer. <sherm@dot-app.org>
        dynamic execution of equations <"lapenta["@]ll.mit.edu>
    Re: Extract lines by name <dreamer@cox.net>
        Help with overload. <ignoramus27279@NOSPAM.27279.invalid>
        How to return list from Inline::C code? <socyl@987jk.com.invalid>
    Re: How to return list from Inline::C code? <william@wilbur.25thandClement.com>
    Re: Perl experts wanted <tadmc@augustmail.com>
        Timer/alarm clock module <ignoramus27279@NOSPAM.27279.invalid>
    Re: Timer/alarm clock module <hlarons@yahoo.com>
    Re: Timer/alarm clock module <ignoramus27279@NOSPAM.27279.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 29 Jul 2005 15:41:36 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: Converting a 4 byte field to integer.
Message-Id: <m2vf2tcscv.fsf@Sherm-Pendleys-Computer.local>

Shashank Khanvilkar <shashank@mia.ece.uic.edu> writes:

> The below fragment does not seem to work,
>
> --SNIP--
> read(IN, $buffer, 4);  #IN is the fh for a file open in binary mode..
> $page_number = ord($buffer);

You need to get acquainted with pack() and unpack(). See:
    perldoc -f pack
    perldoc -f unpack
    perldoc perlpacktut

In this case you'd use unpack(), like so:
   my $page_number = unpack('L', $buffer);

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Fri, 29 Jul 2005 15:04:25 -0400
From: "lapenta[" <"lapenta["@]ll.mit.edu>
Subject: dynamic execution of equations
Message-Id: <%4vGe.260$75.114@llslave.llan.ll.mit.edu>


Hello,

I am trying to map out a simple PERL program to optimize coefficents for 
a dynamic list of equations based on a set of rules. I'm having trouble 
figuring out how to efficiently and dynamically load different 
equations. Idealy separate files would each define the equation and 
rules, while the main tool would load 1...n equations at a time and run 
the optimization algorithm. As the equation will be executed many times 
during the optimization, execution speed is a factor. I was thinking 
dynamic modules would work nicely, but I can not figure out how to get 
them to work. I would like to avoid doing something like 'exec "perl 
$eqn"' as I imagine that would be much too slow for many equations.

for example...

file1.pl
----------------------------------------------
#!/usr/bin/perl -w

BEGIN{
  $g_module = $ARGV[0];
}

print "optimizing for $g_module\n";
require "$g_module.pm";

$g_module::eqn( 5, 6 );
----------------------------------------------

simple_eqn.pm
----------------------------------------------
package simple_eqn;

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(eqn $g_vars);

$g_vars = 2;

sub eqn {

   my $a = shift;
   my $b = shift;

   return ($a / $b)**($a);

}
----------------------------------------------

$ perl file1.pl simple_eqn
syntax error at file1.pl line 14, near "$g_module::eqn( "
Execution of file1.pl aborted due to compilation errors.

Thanks in advance,
Jason


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

Date: Fri, 29 Jul 2005 22:58:37 +0200
From: Fred Hare <dreamer@cox.net>
Subject: Re: Extract lines by name
Message-Id: <WLedncOuSeXiBXffRVnysw@giganews.com>

Jim Gibson wrote:

> In article <t_udnfoxIc47-3ffRVnyjw@giganews.com>, Fred Hare
> <dreamer@cox.net> wrote:
> 
> 
>>I have textfiles with 6000 lines (about 674k) and I want to print lines 
>>in groups containing the same name. The following code (with 3 names) 
>>works OK. But I actually use a script with 24 names and I would like to 
>>find a way where I have to open and close the infile only once.
>>
>>
> 
> [program snipped]
> 
> Store your lines arrays which are referred to by elements of a hash.
> This will work as long as your text lines fit into memory:
> 
> #!/usr/local/bin/perl
> #
> use warnings;
> use strict;
> my %text;
> while (<DATA>) {
>   if( /(adam|baker|Charly)/ ) {
>     push( @{$text{$1}}, $_ );
>   }
> }
> for my $name ( keys %text ) {
>   print "\n$name:\n\n";
>   print @{$text{$name}};
> }
> __DATA__
> line 1
> line 2 adam
> line 3
> line 4 baker
> line 5
> line 6 Charly
> line 7
> line 8 baker
> line 9
> 
> __OUTPUT__
> 
> adam:
> 
> line 2 adam
> 
> Charly:
> 
> line 6 Charly
> 
> baker:
> 
> line 4 baker
> line 8 baker
> 
> Note: there is a way to generate the regex (adam|baker|Charly|...) from
> a list of names, but I have forgotten what it is and cannot reconstruct
> it.
> 

Jim, I tried jour suggested code im my script and I got a Perl error 
message:

Scalar value @{text{$1} better written as ${text{$1} at sort.pl line 18.
Type of arg 1 to push must be array (not hash slice) at sort.pl line 18, 
near "$_) "
Execution of sort.pl aborted due to compilation errors.

I tried a few changes but could not get rid of the error messages. Since 
  the code proposed by Paul Lally works fine for me I will stay with 
that code...

-- Fred Hare


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

Date: Fri, 29 Jul 2005 19:17:47 GMT
From: Ignoramus27279 <ignoramus27279@NOSPAM.27279.invalid>
Subject: Help with overload.
Message-Id: <vhvGe.12489$ZZ5.5400@fe77.usenetserver.com>

Just a pointer to a perl manpage would be great.

I am looking to write a bunch of modules on which to perform
operations like addition etc. 

The modules would represent objects such as constants (1, 2/3, pi/2,
etc), as well as polynomials and general math functions.

What I would like is to overload operations so that I could "drop in"
the values of that type into existing subroutines. 

Suppose that I already have a subroutine

sub myGreatComputation {
  my ($a, $b) = @_.
  # do big stuff with arithmetics on $a and $b
}

is there some way to define my new module so that other subroutines
that do arithmetics would work properly when passed objects of that
module rather than regular scalar values, without rewriting that
subroutine?

thanks




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

Date: Fri, 29 Jul 2005 21:14:15 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: How to return list from Inline::C code?
Message-Id: <dce677$blb$1@reader2.panix.com>




I'm attempting to hack the Perl internals, something I know very
little of.  So I apologize ahead of time for the cluelessness of
this question.

I want to implement a function via Inline::C such that, depending
on context, it returns either a scalar or a list of two values.
(This function will access the internals of other variables, and I
want to make it as fast as possible, hence the decision to code it
in C).

Since C is not capable of optionally returning a scalar or a list,
I don't even know where to begin with this.

Any advice would be much appreciated.  In particular, I'd love to
look at source code for a simple function (in C) that returns a
scalar or a list according to calling context.

Thanks!

kj

-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.


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

Date: Fri, 29 Jul 2005 14:41:18 -0700
From: William Ahern <william@wilbur.25thandClement.com>
Subject: Re: How to return list from Inline::C code?
Message-Id: <uckqr2-mjq.ln1@wilbur.25thandClement.com>

kj <socyl@987jk.com.invalid> wrote:
> I'm attempting to hack the Perl internals, something I know very
> little of.  So I apologize ahead of time for the cluelessness of
> this question.

Hack the Perl internals, or just use the Perl internals directly from C?

From here on out this is coming from Perl XS experience, not Inline::C. I've
never used Inline::C so I don't know that the differences are.

> I want to implement a function via Inline::C such that, depending
> on context, it returns either a scalar or a list of two values.
> (This function will access the internals of other variables, and I
> want to make it as fast as possible, hence the decision to code it
> in C).
>
> Since C is not capable of optionally returning a scalar or a list,
> I don't even know where to begin with this.

If you read the perlapi man page/pod you'll come across the GIMME_V
C macro. GIMME_V can return G_SCALAR, G_ARRAY or G_VOID.

You can then decide based on those three conditions how many return values
to push onto the stack.

Realize, also, that you can't return an array directly. If you want to
return an array you have to push each array member onto the stack. For large
arrays it's far more efficient to return a single scalar which is a
reference to an array.

> Any advice would be much appreciated.  In particular, I'd love to
> look at source code for a simple function (in C) that returns a
> scalar or a list according to calling context.

Read perlxstut, perlxs, perlapi and perlguts. Anything else will just
confuse you, and they have great examples in there already.

Apologies if any of this is entirely inapplicable to Inline::C.



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

Date: Fri, 29 Jul 2005 13:58:28 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl experts wanted
Message-Id: <slrndekv2k.1ga.tadmc@magna.augustmail.com>

Wim Hoogenraad <Wim.Hoogenraad@webmasterslookup.com> wrote:


> We want as many webpersons as possible to join us.  


> Send this e-mail to other webpeople you know. 


"This" is not an "e-mail".

"This" is a Usenet news posting.


> They can join
> your network and benifit from WebmastersLookup to.


The folks running the site spam newsgroups and don't know the
difference between SMTP and NNTP.

That is not the type of place that an "expert" would want to
associate with.


> Thank you for reading this e-mail.


This is not an e-mail.


> Kind regards,


Go away spammer.


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


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

Date: Fri, 29 Jul 2005 18:53:21 GMT
From: Ignoramus27279 <ignoramus27279@NOSPAM.27279.invalid>
Subject: Timer/alarm clock module
Message-Id: <BWuGe.4988$xU.2665@fe69.usenetserver.com>

Is there some perl module for setting alarms? The use I have in mind
is as follows:

my $times = new AlarmModule( 600, sub { print "Hello" } );

that would make the timer wake up every 600 seconds and print hello.

Any suggestions?

i



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

Date: Fri, 29 Jul 2005 19:06:09 -0000
From: HaroldWho <hlarons@yahoo.com>
Subject: Re: Timer/alarm clock module
Message-Id: <slrndekvf6.1hq.hlarons@Beagle.mylocal.net>

On Fri, 29 Jul 2005 18:53:21 GMT, Ignoramus27279 wrote in comp.lang.perl.misc:
> Is there some perl module for setting alarms? The use I have in mind
> is as follows:
>
> my $times = new AlarmModule( 600, sub { print "Hello" } );
>
> that would make the timer wake up every 600 seconds and print hello.
>
> Any suggestions?

See the Time::HiRes module pod.

HTH,

HW
-- 
Powered by SuSE Linux 9.0 -- Kernel 2.6.11
News Reader slrn 0.9.8.1




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

Date: Fri, 29 Jul 2005 19:09:33 GMT
From: Ignoramus27279 <ignoramus27279@NOSPAM.27279.invalid>
Subject: Re: Timer/alarm clock module
Message-Id: <N9vGe.12486$ZZ5.9820@fe77.usenetserver.com>

On Fri, 29 Jul 2005 19:06:09 -0000, HaroldWho <hlarons@yahoo.com> wrote:
> On Fri, 29 Jul 2005 18:53:21 GMT, Ignoramus27279 wrote in comp.lang.perl.misc:
>> Is there some perl module for setting alarms? The use I have in mind
>> is as follows:
>>
>> my $times = new AlarmModule( 600, sub { print "Hello" } );
>>
>> that would make the timer wake up every 600 seconds and print hello.
>>
>> Any suggestions?
>
> See the Time::HiRes module pod.
>

Thanks, I was  looking for something object oriented that hides
$SIG{ALRM} and such.

i



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

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


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