[28092] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9456 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 12 14:10:13 2006

Date: Wed, 12 Jul 2006 11:10:07 -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, 12 Jul 2006     Volume: 10 Number: 9456

Today's topics:
        Perl analog to #include "..." ? <miguel@farah.cl>
    Re: Perl analog to #include "..." ? <glennj@ncf.ca>
    Re: Perl analog to #include "..." ? <miguel@farah.cl>
    Re: Problem when embedding 2 Perl interpreters in C++ <sgt19@tid.es>
    Re: Problem with Multi- threaded Server <1usa@llenroc.ude.invalid>
    Re: processing large numbers/values/figures <ruf@rawip.org>
    Re: processing large numbers/values/figures <sherm@Sherm-Pendleys-Computer.local>
        puzzling error in script that copies files before proce <r.ted.byers@rogers.com>
    Re: puzzling error in script that copies files before p <1usa@llenroc.ude.invalid>
    Re: Strange syntax error <sgt19@tid.es>
        testing or detecting valid "date" data type <jack_posemsky@yahoo.com>
    Re: testing or detecting valid "date" data type <mritty@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 12 Jul 2006 08:21:40 -0700
From: "Miguel Farah" <miguel@farah.cl>
Subject: Perl analog to #include "..." ?
Message-Id: <1152717699.988061.103940@35g2000cwc.googlegroups.com>

I'm currently working on a program to compute family relationships. A
Perl script reads a GEDCOM (.GED) file and extracts the relevant
information, writing stuff like this:

$father{"1"}="-1"; $mother{"1"}="-2"; $spouses{"1"}=",";
$children{"1"}=","; $sex{"1"}="M"; $name{"1"}="Fred Flintstone";
$father{"2"}="-3"; $mother{"2"}="-4"; $spouses{"2"}=",";
$children{"2"}=","; $sex{"2"}="F"; $name{"2"}="Vilma Flintstone";
$father{"3"}="-5"; $mother{"3"}="-6"; $spouses{"3"}=",";
$children{"3"}=","; $sex{"3"}="F"; $name{"3"}="Pebbles
Rubble-Flintstone";
$father{"4"}="-7"; $mother{"4"}="-8"; $spouses{"4"}=",";
$children{"4"}=","; $sex{"4"}="M"; $name{"4"}="Pete Ecanthropus
Flintstone";
[....]
$spouses{"1"}.="2,"; $spouses{"2"}.="1,";
$father{"3"}="1"; $mother{"3"}="2"; $children{"1"}.="3,";
$children{"2"}.="3,";
$father{"4"}="1"; $mother{"4"}="2"; $children{"1"}.="4,";
$children{"2"}.="4,";
[....]

This output comprises HALF of the source code for a second Perl script,
which is a main code block and a bunch of subroutines that compute and
track relationships.

As you can see, the first half of the source code depends on a
particular GEDCOM file, and needs to be generated each time a new
family
database is used, while the second won't change at all.

I want to keep both halves in separate files, but I don't know exactly
how. If this were PHP or C/C++, I'd just use include() or #include
respectively, but I'm in a stump here. What's the Perl way to do it?


Thanks in advance.



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

Date: 12 Jul 2006 15:32:37 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Perl analog to #include "..." ?
Message-Id: <slrneba5gl.m92.glennj@smeagol.ncf.ca>

At 2006-07-12 11:21AM, Miguel Farah <miguel@farah.cl> wrote:
[...]
>  I want to keep both halves in separate files, but I don't know exactly
>  how. If this were PHP or C/C++, I'd just use include() or #include
>  respectively, but I'm in a stump here. What's the Perl way to do it?

    do "first_half.pl";

-- 
Glenn Jackman
Ulterior Designer


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

Date: 12 Jul 2006 09:34:45 -0700
From: "Miguel Farah" <miguel@farah.cl>
Subject: Re: Perl analog to #include "..." ?
Message-Id: <1152722085.154662.129140@h48g2000cwc.googlegroups.com>

Glenn Jackman wrote:
> At 2006-07-12 11:21AM, Miguel Farah <miguel@farah.cl> wrote:
> [...]
> >  I want to keep both halves in separate files, but I don't know exactly
> >  how. If this were PHP or C/C++, I'd just use include() or #include
> >  respectively, but I'm in a stump here. What's the Perl way to do it?
> 
>     do "first_half.pl";

That was easy!

Thank you.



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

Date: Wed, 12 Jul 2006 16:54:29 +0200
From: Stephan Titard <sgt19@tid.es>
Subject: Re: Problem when embedding 2 Perl interpreters in C++
Message-Id: <e932f4$35j7@news.hi.inet>

ritesh escribió:
> Hi,
> 
> I'm facing a problem when embedding two perl interpreters in my C++
> code.
> 
> My code has 2 threads - the GUI and the Core thread.  The core thread
> initializes a Perl interpreter and all works fine here.  Both the
> threads communicate via Events.
> 
> In a particular scenario the GUI thread, invokes a function which
> further invokes a perl subroutine using the "perl_call_argv" call.
> Since the GUI thread dosen't have a perl interpreter running on it
> there are 2 options I have -
> 
> 1. Use the PERL_SET_CONTEXT macro within the function that the GUI
> thread calls, and then invoke the perl subroutine using the
> "perl_call_argv" call.  -- This works fine.
> 
> However I'm not sure if two threads should be sharing the same perl
> interpreter.
I believe not.

   The Core thread might also make some calls to
> "perl_call_argv" while the GUI thread is working.  Would the
> interpreter be intelligent enough to handle 2 threads?  I found a
> negative answer to this question at this link -
> modperlbookDOTorg/html/ch24_03DOThtml
> The text explicity states --> "This of course requires that each Perl
> interpreter instance is accessed
> by only one thread at any given time."
that makes sense to me
> 
> 2. In second scenario, I create a new perl interpreter within the
> function the GUI thread calls.  Creation and destruction of the
> interpreter happens within this function, since the interpreter is not
> required by the GUI thread after the function returns.  Here is the
> function -
> 
> void function_for_gui_thread(char * perlFnToCall)
> {
>         PL_perl_destruct_level = 1;  /* keep setting this value to 1
> before construction and destruction of the interperator for gui thread
> */
> 
>         PerlInterpreter * guiPerlInterp = 0;  /* this is the interp i
> create within the function for GUI thread */
>         perlInterp = perl_alloc();
>         PERL_SET_CONTEXT(guiPerlInterp);
>         perl_construct(guiPerlInterp);
>         PL_perl_destruct_level = 1;
>         perl_run(guiPerlInterp);
> 
> 
>         char ** perl_args = (char**)sgMalloc(2*sizeof(char*));
>         perl_args[0] = "";
>         perl_args[1] = 0;
>         perl_call_argv(perlFnToCall, G_DISCARD, perl_args);  /* for
> simplicity I've added the perlFnToCall variable in the function
> parameters, however it is determined in this function at runtime */
>         sgFree(perl_args);
> 
> 
>         PL_perl_destruct_level = 1;
>         perl_destruct(guiPerlInterp);
>         PL_perl_destruct_level = 1;
>         perl_free(guiPerlInterp);
>         PERL_SET_CONTEXT(corePerlInterpreter);  /* corePerlInterpreter
> is the interp initialized by the core thread */
> }
> 
> Note that I set the context of the interpretor to the new guiPerlInterp
> before I start using it.  When exiting the function I set the context
> back to corePerlInterpreter.
> 
> First question that comes to my mind is - Do I really need to set the
> context back to corePerlInterpreter for the GUI thread, since it
> dosen't need a perl interpreter after this function call?
> 
> Second when I run the program, the perl subroutine is invoked (i've
> verified this using print commands), then within the perl subroutine
> certain subroutines are invoked which use Perl XS routines.  When the
> control reaches the first such subroutine I get an error like this -
> 
> Usage : getReport(reportName)
> 
> and the program exits.  The "getReport(reportName)" is the XS function
> that the perl function invokes.
> 
> ------------------------------------
> 
> Could you please help me out with this.  The program works fine when I
> use the first scenario.  However I would like to use the second
> scenario.
> 
> Thanks,
> ritesh
> 
if you don'use dynamic loading (dlopen and such) you already pay the 
price of loading the perl library...
in that case maybe you could start the perl interpreter from the main 
program (thread) and mutex the calls to it from any thread (GUI or other...)

sorry I cannot help more on this, I haven't hooked perl into C++
maybe you could post this on p5p, if nobody else answers

hth
--stephan


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

Date: Wed, 12 Jul 2006 15:56:10 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Problem with Multi- threaded Server
Message-Id: <Xns97FE798492BCDasu1cornelledu@127.0.0.1>

Ben Morrow <benmorrow@tiscali.co.uk> wrote in
news:ls7eo3-ne3.ln1@osiris.mauzo.dyndns.org: 

> 
> Quoth "A. Sinan Unur" <1usa@llenroc.ude.invalid>:
>> xhoster@gmail.com wrote in news:20060711202743.217$qZ@newsreader.com:
>> 
>> > perl -le 'use threads; my @x=1..10; foreach (1..10000) { async {
>> > sleep}->detach; warn $_ unless $_%100; }'
>> > 
>> > This seg-faulted at 1200, and took annoying long to get there.
>> 
>> Under WinXP SP2, went aaaaalll the way up to 115 (quickly ;-).
>> > 
>> > perl -le 'use threads; my @x=1..10; foreach (1..10000) { fork or
>> > sleep; warn $_;}'
>> > 
>> > This ran out of processes at 6100, very quickly.
>> 
>> Hmmm ... Just stopped creating processes at 64. The program was still
>> running though. Had to use CTRL-C.
> 
> This is hardly a sensible benchmark on Win32, as fork is implemented
> with ithreads anyway... 

I should have put a smiley somewhere there ...

>> Under cygwin, it went up to 256.
> 
> Do you know if cygwin provides its own fork emulation, and if perl
> uses it or ithreads?

I am not sure. I checked the cygwin fork.cc source code, and it makes a 
CreateProcess call. I do not know if Perl uses cygwin's fork, or its own 
fork emulation on Windows. 

Sinan
-- 
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: 12 Jul 2006 19:36:03 +0100
From: Lukas Ruf <ruf@rawip.org>
Subject: Re: processing large numbers/values/figures
Message-Id: <slrnebaco3.huh.ruf@pc-4082.ethz.ch>

> Tad McClellan [Tue, 11 Jul 2006 16:31:01 -0500]:
>
>  Lukas Ruf <ruf@rawip.org> wrote:
> >> Tad McClellan [Tue, 11 Jul 2006 07:51:46 -0500]:
> >>
> >>  Lukas Ruf <ruf@rawip.org> wrote:
> >>
> >> >         $hsh{$key} += @record{$index};
> >>
> >>
> >>  You should always enable warnings when developing Perl code.
> >>
> >
> > meanwhile, I do.
>
>
>  You should not ignore the warnings that perl emits when developing
>  Perl code.
>

perl does not emit any warning anymore -- did you refer to my
mistyping of

> >> >         $hsh{$key} += @record{$index};

instead of

               $hsh{$key} += @record[$index];

??

But anyway: I make use of sth like the following code:

  use strict;
  use warnings;

  my $inline = "";
  my @record;
  my %hsh = ();
  my $key = 0;
  my $index = 0;

  open(INFILE, "< $FILENAME") || die "can't open $FILENAME" ;
  print(STDERR "$FILENAME opened\n");

  while (defined($inline = <INFILE>))
  {
    chomp $inline;  # remove '\n'
    $inline =~ s/\s+//g;
    @record = split(/,/, $inline);

    $record[$index]++;
    $hsh{$key} += $record[$index];
  }

My questions:
- is it correct that all newly created hash-values are initialized
  to zero by Perl automagically?
- or do I need to initialize them manually?  If so, how?

Thanks in advance.

wbr,
Lukas
-- 
Lukas Ruf   <http://www.lpr.ch> | Ad Personam
rbacs      <http://wiki.lpr.ch> | Restaurants, Bars and Clubs
Raw IP   <http://www.rawip.org> | Low Level Network Programming
<http://lists.lpr.ch/muttprint> | muttprint mailing list


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

Date: Wed, 12 Jul 2006 13:50:01 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: processing large numbers/values/figures
Message-Id: <m23bd6emra.fsf@Sherm-Pendleys-Computer.local>

Lukas Ruf <ruf@rawip.org> writes:

> perl does not emit any warning anymore -- did you refer to my
> mistyping of
>
>> >> >         $hsh{$key} += @record{$index};
>
> instead of
>
>                $hsh{$key} += @record[$index];

Not that I want to be redundant, but the above is exactly why the posting
guidelines suggest copy-and-pasting your code instead of retyping it. It
helps avoid errors such as these.

It also helps avoid "read the posting guidelines" responses. :-)

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: 12 Jul 2006 08:25:25 -0700
From: "Ted" <r.ted.byers@rogers.com>
Subject: puzzling error in script that copies files before processing them
Message-Id: <1152717925.077056.8820@p79g2000cwp.googlegroups.com>

I have a script that copies certain files before processing them.  Here
is what I have tried:

#  $copy_cmd = "copy $holdings_source $holdings_dest";
#  qx/$copy_cmd/;
  copy( $holdings_source, $holdings_dest ) or die "Copy failed: $!";

#  $copy_cmd = "copy $transactions_source $transactions_dest";
#  qx/$copy_cmd/;
  copy( $transactions_source, $transactions_dest ) or die "Copy failed:
$!";


In one trial, I used the set of statements that are commented out, and
in the second, I use the other two.  The result is the same.

Parameter format not correct - "FVA".
Parameter format not correct - "FVA".

Obviously, there is one error statement for each attempt to copy a
file.

The contents of the variables holding the file names are:

holdings destination file = C:/FVA/data/univeris/IGBPRODS.txt
transactions destination file = C:/FVA/data/univeris/IGBTRANS.txt

holdings source file =
C:/FVA/data/univeris/univeris0608/IGBPRODS.053006.txt
transactions source file =
C:/FVA/data/univeris/univeris0608/IGBTRANS.053006.txt

The path "C:/FVA/data/univeris" is read from a configuration file, so I
have the script print the file names just so I can ensure the computed
file names are correct (which they are).

Of course, at the beginning of the script I have the following:
use warnings "all";
use File::Copy;

What makes this especially puzzling is that I have similar code in
another script, and it uses the same configuration file, and it works
fine.

Any ideas as to what has gone awry, and how to fix it?

Thanks,

Ted



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

Date: Wed, 12 Jul 2006 15:51:59 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: puzzling error in script that copies files before processing them
Message-Id: <Xns97FE78CEF54D8asu1cornelledu@127.0.0.1>

"Ted" <r.ted.byers@rogers.com> wrote in
news:1152717925.077056.8820@p79g2000cwp.googlegroups.com: 

> I have a script that copies certain files before processing them. 
> Here is what I have tried:
> 
> #  $copy_cmd = "copy $holdings_source $holdings_dest";
> #  qx/$copy_cmd/;
>   copy( $holdings_source, $holdings_dest ) or die "Copy failed: $!";
> 
> #  $copy_cmd = "copy $transactions_source $transactions_dest";
> #  qx/$copy_cmd/;
>   copy( $transactions_source, $transactions_dest ) or die "Copy
>   failed: $!";

Please read the posting guidelines for information on how to effectively 
post in this group.

> In one trial, I used the set of statements that are commented out, and
> in the second, I use the other two.  The result is the same.
> 
> Parameter format not correct - "FVA".
> Parameter format not correct - "FVA".

Half way through your post, and we have no idea what module you are 
using, version of Perl, OS etc etc

Don't comment out code. If necessary, provide separate scripts.

> holdings destination file = C:/FVA/data/univeris/IGBPRODS.txt
> transactions destination file = C:/FVA/data/univeris/IGBTRANS.txt

OK, so you are using a DOS-like system. Try to enter the copy command on 
the command line, and see what happens.

While Perl can deal with '/' in paths internally with no problem, there 
is no reason to assume the command line utility 'copy' can do so.

Simple solution:

#!/usr/bin/perl

use strict;
use warnings;

use File::Spec::Functions qw( canonpath );

my $src = 'C:/FVA/data/univeris/univeris0608/IGBPRODS.053006.txt';
my $dest = 'C:/temp/dest.txt';

my $cmd = join(' ', 'copy', canonpath($src), canonpath($dest));
my $output = qx/$cmd/;
$output =~ /cannot find/ and warn $output, "\n";
__END__


-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Wed, 12 Jul 2006 16:29:00 +0200
From: Stephan Titard <sgt19@tid.es>
Subject: Re: Strange syntax error
Message-Id: <e930vb$35p9@news.hi.inet>

Mumia W. escribió:
> On 07/12/2006 04:53 AM, Stephan Titard wrote:
>> Mumia W. escribió:
>>> [...]
>>> Don't use Switch.
>>>
>> actually switch (as perl6 given) is already in 5.9.4-to-be
>> so don't despair we will have it soon
>>
>> I wonder if it can be wrapped up in a stand-alone module for the 
>> impatient (a good question for p5p)
>>
>> hth
>> --stephan
> 
> There is already a Switch::Perlish on CPAN, and I even wrote a switch 
> subroutine once. However, most of the time, Perl's other constructs to 
> simulate switch are adequate.
> 
Right. My point was that once you have a switch in the core, that is the
syntax you want to stick to, and if you ever want to use it for 
production code, it would be nice to have it backported
or have a standalone version that works for previous versions of perl
(quite doable actually if I followed correctly p5p on the subject)

I don't use any switch, but I might use *given*
hth
--stephan


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

Date: 12 Jul 2006 08:43:51 -0700
From: "Jack" <jack_posemsky@yahoo.com>
Subject: testing or detecting valid "date" data type
Message-Id: <1152719031.827189.126620@p79g2000cwp.googlegroups.com>

Hi folks,

I am looking to find some code that tests a string as being a valid
"date" data type.. I tried this but it doesnt seem to work

$ENV{TZ} = 'PST';
use Date::Manip;
$datetest = '1111';
$date = ParseDate($datetest);
print $date;

This program returns: 1111010100:00:00
which is not a valid date for example, obviously.

Any help would be appreciated



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

Date: 12 Jul 2006 08:51:38 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: testing or detecting valid "date" data type
Message-Id: <1152719493.155171.238300@b28g2000cwb.googlegroups.com>

Jack wrote:
> I am looking to find some code that tests a string as being a valid
> "date" data type.. I tried this but it doesnt seem to work

It *works* exactly as it's supposed to.  It just doesn't do what you
*want* it to do.

> $ENV{TZ} = 'PST';
> use Date::Manip;
> $datetest = '1111';
> $date = ParseDate($datetest);
> print $date;
>
> This program returns: 1111010100:00:00
> which is not a valid date for example, obviously.

You have a different definition of "obviously" than I do.  That is the
date January 1, 1111, at 12:00:00am.  That is what happens when you
pass only a year to ParseDate.  If you'd read the documentation for the
module you're using, you'd probably have found that a four-digit year
is an acceptable argument to ParseDate.

I don't think Date::Manip is the module you should be using.  Instead,
figure out what your possible date formats are, and then use a module
such as Regexp::Common::time
http://search.cpan.org/~roode/Regexp-Common-time-0.01/time.pm

Paul Lalli



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

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


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