[21688] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3892 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 1 11:05:49 2002

Date: Tue, 1 Oct 2002 08:05:10 -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           Tue, 1 Oct 2002     Volume: 10 Number: 3892

Today's topics:
        dynamic pattern matching <pef@trasig.noXX>
    Re: dynamic pattern matching <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
    Re: dynamic pattern matching (Tad McClellan)
        Error: Cannot start Word (Steve)
    Re: How can I count files in a directory? <isterin@nospam.com>
    Re: How would you do this (regexp)? <s.DONTwarhurstSPAM@rl.ac.MEuk>
    Re: How would you do this (regexp)? <kurzhalsflasche@netscape.net>
    Re: How would you do this (regexp)? (Tad McClellan)
    Re: How would you do this (regexp)? <Tassilo.Parseval@post.rwth-aachen.de>
    Re: How would you do this (regexp)? <dgething@eu.uu.net>
    Re: How would you do this (regexp)? (Tad McClellan)
    Re: I need a perl method that works like basedir <Tassilo.Parseval@post.rwth-aachen.de>
        permissions, ascii and ftp (S.Eeker)
    Re: permissions, ascii and ftp (Tad McClellan)
        problem with mod_auth_db in RedHat 7.3 (Dante Picca)
    Re: Question about srand <brittedg@student.gvsu.edu>
    Re: Question about srand news@roaima.freeserve.co.uk
    Re: Question about srand <wksmith@optonline.net>
        stand-alone embedding of perl to c++ <anni.hienola@helsinki.fi>
    Re: Substitution question <No_Mail_Address@cox.net>
    Re: validate csv file with regular expressions <member@dbforums.com>
    Re: validate csv file with regular expressions (Tad McClellan)
        Which .exe generator? <spikey-wan@bigfoot.com>
    Re: Which .exe generator? <tk@WINDOZEdigiserv.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 1 Oct 2002 13:26:43 +0200
From: "Brutus" <pef@trasig.noXX>
Subject: dynamic pattern matching
Message-Id: <anc0q5$7dn$1@oslo-nntp.eunet.no>

Usually pattern matching is hard coded, e.g.:
if (/ "expression" /)

But what if  "expression" is a scalar variable ?
I'm looking for the syntax for finding the occurance of an expression
( contained in a scalar ) in another scalar.

I've been looking in the books, without any luck so far.

Thankful for a pointer.
Brit Uthus








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

Date: Tue, 01 Oct 2002 13:40:58 +0200
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: dynamic pattern matching
Message-Id: <newscache$agwa3h$jx6$1@news.emea.compuware.com>

Brutus wrote (Tuesday 01 October 2002 13:26):

> Usually pattern matching is hard coded, e.g.:
> if (/ "expression" /)
> 
> But what if  "expression" is a scalar variable ?
> I'm looking for the syntax for finding the occurance of an expression
> ( contained in a scalar ) in another scalar.
> 
> I've been looking in the books, without any luck so far.
> 
> Thankful for a pointer.
> Brit Uthus

You can use /$my_regex/. This will interpolate nicely. But reading 'man 
perlre' is a Good Thing.

-- 
KP



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

Date: Tue, 01 Oct 2002 12:18:16 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: dynamic pattern matching
Message-Id: <slrnapj4ca.2f6.tadmc@magna.augustmail.com>

Brutus <pef@trasig.noXX> wrote:
> Usually pattern matching is hard coded, e.g.:
> if (/ "expression" /)
> 
> But what if  "expression" is a scalar variable ?


What happened when you tried it?


> I'm looking for the syntax for finding the occurance of an expression
> ( contained in a scalar ) in another scalar.


   $somepattern = ' "expression" ';
   if ( /$somepattern/ ) {


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


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

Date: 1 Oct 2002 06:19:40 -0700
From: haysmans@hunterlink.net.au (Steve)
Subject: Error: Cannot start Word
Message-Id: <2246e285.0210010519.748d1aa@posting.google.com>

Hi,

I have this cgi script below which I've been testing on the DOS
prompt. It opens a Word template, changes it, then "saves as"
something else. It works just fine on my win2000 machine, but when I
run it on an NT4 machine I get the error below - can't open Word.
The NT machine (office97) can access the Word doc ok, so I'm out of
ideas.. any help is welcome.

thanks in advance
Steve

Cannot start Word: Win32::OLE(0.1502) error 0x80080005: "Server
execution
failed"

#use diagnostics;
use CGI qw(:standard);
use Win32::OLE;
use Win32::ODBC;
# include constants for microsoft word
use Win32::OLE::Const 'Microsoft Word';

   $Title = 'Fred';
   # Open Word application ----
    my $Word = Win32::OLE->new('Word.Application', 'Quit')
      or print "Cannot start Word: " . Win32::OLE->LastError();
        # Watch what happens
        $Word->{Visible} = 1;

        # Open file ----
          $WdDSN = 'D:\\';
            my $Doc = $Word->Documents->Open($WdDSN ."report.dot")
            or print "Cannot open template: " .
Win32::OLE->LastError();

           # Navigate using bookmarks
            $Doc->GoTo({What =>wdGoToBookmark, Name =>'bTitle'});
            $Doc->Bookmarks('bTitle')->Range->{Text} = $Title;

           # Saveas and Close file
          $Doc->SaveAs($WdDSN . $Userid .".doc");
            $Doc->Close({SaveChanges => 0});
      # Disconnect OLE
      undef $Word;


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

Date: Tue, 1 Oct 2002 10:40:08 -0400
From: "Ilya Sterin" <isterin@nospam.com>
Subject: Re: How can I count files in a directory?
Message-Id: <ancc48$i3i15@eccws12.dearborn.ford.com>

my $dir = opendir("path/to/dir");

my $count;

$count++ while (readdir($dir));


"Rubber Duck" <rubberducky703@hotmail.com> wrote in message
news:anblvf$cktur$1@ID-116287.news.dfncis.de...
> How can I count files in a directory?
>
> Is their a module or a method in a perl module which will scan a top level
> directory and count the number of files in each of the folders/directories
> below it?
>
> I also need to check for the file index.html in each folder, any
> package/method which allows this would be ideal.
>
> Essentially, all I need is just a list of directory names and a number
> indicating the number of files in that specific folder.
>
> Any ideas?  Where should i be looking?
>
> Thanks
>
>




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

Date: Tue, 1 Oct 2002 12:48:19 +0100
From: "Bigus" <s.DONTwarhurstSPAM@rl.ac.MEuk>
Subject: Re: How would you do this (regexp)?
Message-Id: <anc225$1248@newton.cc.rl.ac.uk>

"Bigus" <s.DONTwarhurstSPAM@rl.ac.MEuk> wrote in message
news:anbpro$1bvo@newton.cc.rl.ac.uk...
[..]
> That is interesting because I've never been sure how to properly specify
> alternative characters in a regexp. That is, you have used "[& ]" to match
> either an ampersand or a space. I was writing that as "(&| )", which I had
> thought was the correct way of doing it (not sure why - most of my Perl
> knowledge comes in patchy fashion from website "tutorials"). Writing it
that
> way sometimes caused me problems in regexps where I wanted to extract a
> substring, rather than make a decision based on it, because anything
matched
> in round brackets get placed into a variable (if you see what I mean). In
> those instances I found that "[&| ]" worked, but it ddid seem a messy way
of
> doing it. So, I can forget the pipes & round brackets now :)

Actually, I think where I got the pipe thing from was that if you are
matching alternative phrases rather than characters... so, if you had 2
strings:

I like cats
I like dogs

and you wanted to match both of them, I would write:

if($string =~ /I like (cats|dogs)/){}

Is that the proper way to write it, or should it be:

if($string =~ /I like [cats|dogs]/){}

And if the round-bracket way is correct, then how would you get round this
problem:

Say you were looping through strings that read:

I like cats and my name is Fred
I like dogs and my name is George

and you wanted to match either of those phrases but extract the person's
name into a variable. Example code being:

@strings = ("I like cats and my name is Fred","I like dogs and my name is
George");

foreach $string(@strings)
{
  @name = $string =~ /I like (cats|dogs) and my name is (\w+)/;
  print "$name[1]\n";
}

That would result in the names Fred and George being printed out, however,
the first array position $name[0] in each case would be "cats" and "dogs"
respectively. What if you don't want cats & dogs to appear in that array -
that is you simply want to match them rather than extract them. how would
that be done? (I hope that makes sense - I know what I mean, anyway ;-)

Bigus







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

Date: Tue, 01 Oct 2002 14:09:27 +0200
From: Dominik Seelow <kurzhalsflasche@netscape.net>
Subject: Re: How would you do this (regexp)?
Message-Id: <3D999077.9070506@netscape.net>

Bigus announced:


SNIP!

> 
> And if the round-bracket way is correct, then how would you get round this
> problem:
> 
> Say you were looping through strings that read:
> 
> I like cats and my name is Fred
> I like dogs and my name is George
> 
> and you wanted to match either of those phrases but extract the person's
> name into a variable. Example code being:
> 
> @strings = ("I like cats and my name is Fred","I like dogs and my name is
> George");
> 
> foreach $string(@strings)
> {
>   @name = $string =~ /I like (cats|dogs) and my name is (\w+)/;
>   print "$name[1]\n";
> }

foreach (@strings)
{
  my (undef,$name) = /I like (cats|dogs) and my name is (\w+)/;
  print "$name\n";
}

> 
> That would result in the names Fred and George being printed out, however,
> the first array position $name[0] in each case would be "cats" and "dogs"
> respectively. What if you don't want cats & dogs to appear in that array -
> that is you simply want to match them rather than extract them. how would
> that be done? (I hope that makes sense - I know what I mean, anyway ;-)
> 
> Bigus
> 


HTH,
Dominik



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

Date: Tue, 01 Oct 2002 12:18:15 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How would you do this (regexp)?
Message-Id: <slrnapj43b.2f6.tadmc@magna.augustmail.com>

Bigus <s.DONTwarhurstSPAM@rl.ac.MEuk> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnaph0o7.30v.tadmc@magna.augustmail.com...
>> Bigus <s.DONTwarhurstSPAM@rl.ac.MEuk> wrote:


>> Or does your real code use memory parens?
> 
> Not sure what you mean.


I mean anything matched in round brackets get placed into a variable :-)


> That is interesting because I've never been sure how to properly specify
> alternative characters in a regexp. 


By using a "character class" (the thing in square brackets).


> That is, you have used "[& ]" to match
> either an ampersand or a space. I was writing that as "(&| )", which I had
> thought was the correct way of doing it

> Writing it that
> way sometimes caused me problems in regexps where I wanted to extract a
> substring, 


Now you've changed the problem.

First you said "alternative characters". Character classes are
the Right Tool for working with _characters_.

There are other tools for working with _strings_ ( index(), m// ).


> rather than make a decision based on it, because anything matched
> in round brackets get placed into a variable (if you see what I mean). 


You can put char classes in memory parenthesis too:   ([& ])


> In
> those instances I found that "[&| ]" worked, 
                                       ^^^^^^

But it does something different.

It allows any of _3_ characters, the other code allowed any
of 2 characters. Vertical bar is not "meta" in char classes,
it matches a literal vertical bar character.


> So, I can forget the pipes & round brackets now :)


Unless you are working with strings or patterns rather than characters.


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


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

Date: 1 Oct 2002 12:23:37 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: How would you do this (regexp)?
Message-Id: <anc449$5jg$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Dominik Seelow:

>> Say you were looping through strings that read:
>> 
>> I like cats and my name is Fred
>> I like dogs and my name is George
>> 
>> and you wanted to match either of those phrases but extract the person's
>> name into a variable. Example code being:
>> 
>> @strings = ("I like cats and my name is Fred","I like dogs and my name is
>> George");
>> 
>> foreach $string(@strings)
>> {
>>   @name = $string =~ /I like (cats|dogs) and my name is (\w+)/;
>>   print "$name[1]\n";
>> }
> 
> foreach (@strings)
> {
>   my (undef,$name) = /I like (cats|dogs) and my name is (\w+)/;
>   print "$name\n";
> }

You could even avoid the undef() and the first pair of capturing parens:

    my ($name) = /I like (?:cards|dogs) and my name is (\w+)/;

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: Tue, 1 Oct 2002 13:34:52 +0100
From: "David Gethings" <dgething@eu.uu.net>
Subject: Re: How would you do this (regexp)?
Message-Id: <3d99966d$0$8506$cc9e4d1f@news.dial.pipex.com>


"Bigus" <s.DONTwarhurstSPAM@rl.ac.MEuk> wrote in message
news:anc225$1248@newton.cc.rl.ac.uk...
>
> Actually, I think where I got the pipe thing from was that if you are
> matching alternative phrases rather than characters... so, if you had 2
> strings:
>
> I like cats
> I like dogs
>
> and you wanted to match both of them, I would write:
>
> if($string =~ /I like (cats|dogs)/){}
To match the string "cats" or "dogs" the above is more accurate

>
> Is that the proper way to write it, or should it be:
>
> if($string =~ /I like [cats|dogs]/){}
This too will match the above strings, but will also match:

I like acst
I like dgos

>
> And if the round-bracket way is correct, then how would you get round this
> problem:
>
> Say you were looping through strings that read:
>
> I like cats and my name is Fred
> I like dogs and my name is George
>
> and you wanted to match either of those phrases but extract the person's
> name into a variable. Example code being:
>
> @strings = ("I like cats and my name is Fred","I like dogs and my name is
> George");
>
> foreach $string(@strings)
> {
>   @name = $string =~ /I like (cats|dogs) and my name is (\w+)/;
>   print "$name[1]\n";
> }
use ?: which is used for grouping without making backreferences. So the
above regex becomes /I like (?:cats|dogs) and my name is (\w+)/. That way
only the first element of the array @name is set.

You seems to have a resonably good jist of regex's so I suggest you read
perlre (you can use 'perldoc perlre' from the command line to do this). Or
if you're more inclined to pay for your learning buy Mastering Regular
Expressions, which covers regexs into great depth and has a section just for
Perl's regex implimentation.

>
> That would result in the names Fred and George being printed out, however,
> the first array position $name[0] in each case would be "cats" and "dogs"
> respectively. What if you don't want cats & dogs to appear in that array -
> that is you simply want to match them rather than extract them. how would
> that be done? (I hope that makes sense - I know what I mean, anyway ;-)
You made sense to me too, at least.

Regards

Dg




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

Date: Tue, 01 Oct 2002 12:50:35 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How would you do this (regexp)?
Message-Id: <slrnapj5pl.2jp.tadmc@magna.augustmail.com>

Bigus <s.DONTwarhurstSPAM@rl.ac.MEuk> wrote:

> if you had 2
> strings:


> and you wanted to match both of them, I would write:
> 
> if($string =~ /I like (cats|dogs)/){}
> 
> Is that the proper way to write it, 


Yes.


> or should it be:
> 
> if($string =~ /I like [cats|dogs]/){}


That is exactly the same as:

   if($string =~ /I like [|acdgost]/){}

and it matches only *one character* after the "like ".


> And if the round-bracket way is correct, then how would you get round this
> problem:

>   @name = $string =~ /I like (cats|dogs) and my name is (\w+)/;
>   print "$name[1]\n";


> That would result in the names Fred and George being printed out, however,
> the first array position $name[0] in each case would be "cats" and "dogs"
> respectively.


   @name = $string =~ /I like (?:cats|dogs) and my name is (\w+)/;
                              ^^^
                              ^^^ non-capturing parenthesis

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


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

Date: 1 Oct 2002 10:41:31 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: I need a perl method that works like basedir
Message-Id: <anbu4r$so3$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Roland Reichenberg:

> does anybody know if there is a function like "basedir" in perl?
> 
> I have a variable containing "/path/to/my/directory/file.log". I want to 
> devide this variable into path ("/path/to/my/directory") and filename 
> ("file.log").
> 
> Any ideas?

Besides the hand-crafted solution by the others, you could also use the
File::Basename module:

    use File::Basename;
    my ($file, $path) = fileparse("/path/to/my/directory/file.log");

This has the benefit of being portable and will even work on such odd
systems like VMS and the like.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: 1 Oct 2002 05:16:25 -0700
From: nowantrubbish@hotmail.com (S.Eeker)
Subject: permissions, ascii and ftp
Message-Id: <47f94041.0210010416.7e8004b5@posting.google.com>

Hi. I am new to perl and apache. I thought this group might better
answer my newbie questions although Apache is involved.

Apache and perl are installed on a win 98 machine. The vhosts are
recognised fine. An environment.pl script works in a console window,
 .pl is a added in httpd.conf.

The script will not work in Netscape nor IE when called. I have tried
different things in httpd.conf but just get different error messages.
I tried another script and same things, work in console but not in
browsers.

Am I right in thinking this is a permission and ascii problem?

If I ftp a perl script to a cgi-bin on a paid provider, I can chmod it
and it works. But if the web server is sitting on my computer, how in
the ether do I ftp a script to my own machine so that I can
a) chmod it and 
b) send it as ascii?

I haven't encountered any ftp facilities in Apache or password, so how
would I configure my ftp program to send perl scripts to myself in the
first place?

At the edge of despair,
can anyone enlighten me?


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

Date: Tue, 01 Oct 2002 12:50:36 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: permissions, ascii and ftp
Message-Id: <slrnapj6ed.2jp.tadmc@magna.augustmail.com>


S.Eeker <nowantrubbish@hotmail.com> wrote:

> I am new to perl and apache. I thought this group might better


Better than what?


> answer my newbie questions although Apache is involved.


I think you have a server configuration problem, which should
be asked in a newsgroup that has something to do with the WWW,
such as:

      comp.infosystems.www.authoring.cgi
      comp.infosystems.www.servers.mac
      comp.infosystems.www.servers.misc
      comp.infosystems.www.servers.ms-windows
      comp.infosystems.www.servers.unix


> I tried another script and same things, work in console but not in
> browsers.


   perldoc -q browser

      "My CGI script runs from the command line but not the
       browser.  (500 Server Error)"


> Am I right in thinking this is a permission and ascii problem?


I doubt it.

You need to find out how to setup your server for CGI programs.


> If I ftp a perl script to a cgi-bin on a paid provider, I can chmod it
> and it works. 


FTP does 2 things for you in that case:

   transfers the file

   convert line endings in text files if OSes are different


> But if the web server is sitting on my computer, 


Then you can use the OS's "copy" or "cp" to transfer the file,
and there is no need for any line ending translations.

You do not need FTP at all.


> At the edge of despair,
> can anyone enlighten me?


You are looking in the wrong place. You don't have a Perl problem.


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


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

Date: 1 Oct 2002 05:34:40 -0700
From: dpicca@hochfeiler.it (Dante Picca)
Subject: problem with mod_auth_db in RedHat 7.3
Message-Id: <93687142.0210010434.58967480@posting.google.com>

Hi,
I'm in trouble with mod_auth_db and/or dbmmanage and/or Linux RedHat
7.3:

I've upgraded my server from Redhat 6.2 to redhat 7.3. This is the
list of relevant packets I've installed with linux server
db3-3.3.11-6
gdbm-1.8.0-14
db2-devel-2.4.14-10
db3-utils-3.3.11-6
nss_db-2.2-14
db1-1.85-8
db2-2.4.14-10
db1-devel-1.85-8
db3-devel-3.3.11-6
db3x-3.2.9-4
gdbm-devel-1.8.0-14
perl-DB_File-1.75-34.99.6
perl-5.6.1-34.99.6

I've also recompile apache to the last version:
SSL_BASE=/path/to/openssl ./configure 朴refix=/path/to/httpd
--enable-module=ssl
--activate-module=src/modules/perl/libperl.a --enable-module=all
--enable-shared=max --bindir=/path/to/bin --sbindir=/path/to/sbin
--libexecdir=/path/to/modules

now mod_auth_db works fine on all my old db files, but when I try to
work on a
preexisting db using dbmmanage I got the following error:
Can't tie users: at /usr/bin/dbmmanage line 202.

If I create a new db using dbmmanage it works fine, but apache doesn't
accept it
((22)Invalid argument: could not open db auth file:).

Using the file command on the two dbs I receive the following output:
oldfile: Berkeley DB 2.X Hash/Little Endian (Version 5, Logical
sequence number:
file - 0, offset - 0, Bucket Size 4096, Overflow Point 2, Last Freed
0, Max
Bucket 3, High Mask 0x3, Low Mask 0x1, Fill Factor 0, Number of Keys
0)

newfile:Berkeley DB 2.X Hash/Little Endian (Version 7, Logical
sequence number:
file - 0, offset - 0, Bucket Size 4096, Overflow Point 2048, Last
Freed 0, Max
Bucket 2, High Mask 0x0, Low Mask 0x0, Fill Factor 0, Number of Keys
0)

I've tried to use mod_auth_dbm but nothing changes.

Those are the lines printed during the compilation phase
gcc -c  -I../../os/unix -I../../include   -DLINUX=22
-I/usr/include/db1
-DMOD_SSL=208110 -DMOD_PERL -DUSE_HSREGEX -DEAPI -DUSE_EXPAT
-I../../lib/expat-lite `../../apaci` -fpic -DSHARED_MODULE
mod_auth_dbm.c && mv
mod_auth_dbm.o mod_auth_dbm.lo
gcc -shared -o mod_auth_dbm.so mod_auth_dbm.lo
gcc -c  -I../../os/unix -I../../include   -DLINUX=22
-I/usr/include/db1
-DMOD_SSL=208110 -DMOD_PERL -DUSE_HSREGEX -DEAPI -DUSE_EXPAT
-I../../lib/expat-lite `../../apaci` -fpic -DSHARED_MODULE
mod_auth_db.c && mv
mod_auth_db.o mod_auth_db.lo
gcc -shared -o mod_auth_db.so mod_auth_db.lo

I don't know if it's a redhat, dbmmanage, apache or my problem 
does any one know the origin of my problem ?
Thank you
               Dante


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

Date: Tue, 01 Oct 2002 09:50:26 -0400
From: David Britten <brittedg@student.gvsu.edu>
Subject: Re: Question about srand
Message-Id: <B9BF2062.4B63%brittedg@student.gvsu.edu>

On 10/1/02 2:58 AM, in article
newscache$0eja3h$4v6$1@news.emea.compuware.com, "Koos Pol"
<koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote:

> David Britten wrote (Tuesday 01 October 2002 07:10):
> 
>> I've got a feeling the answer is no, but if I were to use srand to seed
>> two different systems (i.e. different OS, architecture) with the same seed
>> value, is there any chance that rand will generate the same sequence of
>> numbers on those two systems? In other words, does Perl have its own built
>> in random number generator that will produce consistent results, or does
>> it just use whatever is on the host system? I suppose I could always write
>> my own random number generator to ensure consistency, but even a simple
>> algorithm might make my program too large to be any fun to look at.
>> 
>> I'm being optimistic, because this will be a really cool little program if
>> it will work on more than just my machine...
>> 
>> 
>> -David Britten
> 
> Didn't 'perldoc -f srand' give any clues?

It didn't really tell what it's using to generate random numbers. It could
be built in to Perl; it could be a system dependent routine. I guess I'll
just have to try my code on one of the university's Linux machines later and
see what happens.


-David Britten



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

Date: Tue, 1 Oct 2002 15:35:32 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: Question about srand
Message-Id: <krbcna.iu2.ln@moldev.cmagroup.co.uk>

David Britten <brittedg@student.gvsu.edu> wrote:
> I've got a feeling the answer is no, but if I were to use srand to seed two
> different systems (i.e. different OS, architecture) with the same seed
> value, is there any chance that rand will generate the same sequence of
> numbers on those two systems?

That sounds like you really want a predictable number generator that
appears to provide statistically random results (!)

> I'm being optimistic, because this will be a really cool little program if
> it will work on more than just my machine...

The following one-liner produces the same result using "perl v5.6.1
built for i686-linux" and "perl v5.6.0 built for sun4-solaris":

    $ perl -e 'srand 123; print rand, rand, rand' | cksum
    3990100614 49

Chris
-- 
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}


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

Date: Tue, 1 Oct 2002 10:43:51 -0400
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Question about srand
Message-Id: <mxim9.43425$9d3.1841857@news4.srv.hcvlny.cv.net>


"David Britten" <brittedg@student.gvsu.edu> wrote in message
news:B9BEA67F.4B39%brittedg@student.gvsu.edu...
--snip--
> just use whatever is on the host system? I suppose I could always write my
> own random number generator to ensure consistency, but even a simple
> algorithm might make my program too large to be any fun to look at.
>
> I'm being optimistic, because this will be a really cool little program if
> it will work on more than just my machine...



If you only need one sequence and it must be machine independent, you could
generate it and put it in a file, or append it to your script as DATA.

Sorry I cannot answer your question, but my suggestion may allow your
program to keep its coolness without worrying about the answer

Bill.




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

Date: Tue, 01 Oct 2002 17:58:51 +0300
From: Anni <anni.hienola@helsinki.fi>
Subject: stand-alone embedding of perl to c++
Message-Id: <3D99B82B.6020505@helsinki.fi>

Hello,

I'm working with win98 and using VisualC++ 6 compiler. I've embedded 
ActivePerl (perl56.lib) to my application as described in perlembed and 
it compiles and works fine. However, when I transport the app to a 
'naive' computer, it asks for perl56.dll (why, btw? I thought the 
perl56.lib is enough). I've then provided the dll with perl.exe and my 
app does not complain about missing libraries anymore.
When perl_parse() gets called, it returns an error (integer 9, actually) 
  and when the first call_pv() comes, my app just dies without any 
complaints.

What is this error I'm receiving (no documentation available!) and what 
am I missing here? Should I compile the perl56.lib totally from scratch 
and if yes, with what flags/options to make it a standalone library?


Anni H.



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

Date: Tue, 01 Oct 2002 14:13:22 GMT
From: Fred Hare <No_Mail_Address@cox.net>
Subject: Re: Substitution question
Message-Id: <3D99AD99.C7093E62@fheer.com>

Steven Kuo wrote:
> 
> On Tue, 1 Oct 2002, Fred Hare wrote:
> 
> > ...
> > I now use 4 times the same s///g;
> >
> > s/_(.*?")/ $1/g ;
> > s/_(.*?")/ $1/g ;
> > s/_(.*?")/ $1/g ;
> > s/_(.*?")/ $1/g ;
> >
> > print STDOUT $_, "\n";
> >
> > I am sure there is a shorter line solution...?
> >
> > --
> > Fred
> 
> Try the look-ahead assertion:
> 
>         s/_(?=.*")/ /g;
> 
> --
> Regards,
> Steven

Works great. Had not known Lookahead Assertion before. Thank you,
--
Fred


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

Date: Tue, 01 Oct 2002 11:37:14 +0000
From: rumito <member@dbforums.com>
Subject: Re: validate csv file with regular expressions
Message-Id: <1876491.1033472234@dbforums.com>


10x Tad about the infoto,
i went there (PERLDOC..) but it didn't help me, because i'm not
using Perl, and more - there is no example or sth like that to split
multiple lines except with \s or \S, which doesn't help me,
whatever, i fixed the problem with the following match:

"(\n")+" and that's works :)))


regards: rumi

--
Posted via http://dbforums.com



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

Date: Tue, 01 Oct 2002 14:06:31 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: validate csv file with regular expressions
Message-Id: <slrnapjasu.2vp.tadmc@magna.augustmail.com>

rumito <member@dbforums.com> wrote:
> 
> 10x Tad about the infoto,


Can you decode that? I dunno what you are trying to say.


> i'm not
> using Perl, 


This _is_ the Perl newsgroup you know.


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


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

Date: Tue, 1 Oct 2002 10:51:44 +0100
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Which .exe generator?
Message-Id: <anbr8p$f90$1@newshost.mot.com>

Guys,

I'm now at the point where I'm going to be shipping out my Perl script to
other users!

Obviously, even if the did have Perl installed, the chance of them having
all the modules I used is small, so I need to create a self contained .exe
file.

It seems that there are 2 main contenders, Active State's Dev kit, and
perl2exe.

I was wondering what the general opinion of these is, to help me with my
decision, being a newbie and all that.

Generally I want to be able to create self contained programmes that will
run on a variety of operating systems, but would like to be able to generate
them all from the same scripts that I have written on my PC, on W2K.

Also, ease of getting updates would be useful, as I'm sure my company will
be upgrading us all to XP pro or similar at some point, so something that I
can get for a one off payment with free updates would save me a lot of
trouble.

Thanks.

R.





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

Date: Tue, 01 Oct 2002 12:54:01 GMT
From: tk <tk@WINDOZEdigiserv.net>
Subject: Re: Which .exe generator?
Message-Id: <jj6jpuk2td8kotrktk3ejvcs2qja2llcga@4ax.com>

In a fit of excitement, "Richard S Beckett" <spikey-wan@bigfoot.com>
managed to scribble:

| Guys,
| 
| I'm now at the point where I'm going to be shipping out my Perl script to
| other users!
| 
| Obviously, even if the did have Perl installed, the chance of them having
| all the modules I used is small, so I need to create a self contained .exe
| file.
| 
| It seems that there are 2 main contenders, Active State's Dev kit, and
| perl2exe.
| 
| I was wondering what the general opinion of these is, to help me with my
| decision, being a newbie and all that.
| 
| Generally I want to be able to create self contained programmes that will
| run on a variety of operating systems, but would like to be able to generate
| them all from the same scripts that I have written on my PC, on W2K.
| 
| Also, ease of getting updates would be useful, as I'm sure my company will
| be upgrading us all to XP pro or similar at some point, so something that I
| can get for a one off payment with free updates would save me a lot of
| trouble.
| 
| Thanks.
| 
| R.
| 
| 

I've not tried AS Dev Kit yet, but I've had no issues with Perl2Exe. You
have the option of either including the DLL required in the actual
compiled file, or seperate. There's about a 600k difference, so if you
were sending many compiled scripts to a certain person, it might be more
beneficial to send the DLL seperate, and save them 600k per upgrade,
plus any other scripts that are compiled and run on that system will use
the same DLL.. minimising diskspace and filesize in the long run.


Regards,

  tk

--
+--------------------------+
|     digiServ Network     |
|      Web solutions       |
| http://www.digiserv.net/ |
+--------------------------+

  Remove WINDOZE to reply


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

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.  

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


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