[17626] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5046 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 6 14:05:48 2000

Date: Wed, 6 Dec 2000 11:05:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <976129513-v9-i5046@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 6 Dec 2000     Volume: 9 Number: 5046

Today's topics:
    Re: A sort of another color -- a Tale, not a question ; (Chris Fedde)
        and- Profanity Check <kcount@ardenhouse.com>
        Duplicate Unix's time program on Windows <ted_graham@my-deja.com>
    Re: Duplicate Unix's time program on Windows <jboes@eoexchange.com>
    Re: Duplicate Unix's time program on Windows (Anno Siegel)
    Re: Duplicate Unix's time program on Windows <jeff@vpservices.com>
    Re: getting upper bound of two dimensional arraydimens (Tad McClellan)
    Re: getting upper bound of two dimensional arraydimens (Anno Siegel)
    Re: Help with program <kjs404@hotmail.com>
    Re: How do you convert a Perl script to binary executab <someone@compugenx.com>
    Re: How to do 'sort -u' with Perl for windows? (Adam)
    Re: How to read files from the end? <wstsoi@hongkong.com>
    Re: How to read files from the end? (Anno Siegel)
        perl & graphics <nospam_Lex@peng.nl>
        perl under win98 but no win98 directory. <mjh@servicebidders.com>
        Problem with warn,next,if combinations <warren.dodge@tektronix.com>
    Re: Problems in embedded perl with LC_NUMERIC (Anno Siegel)
    Re: Profanity Check (Gary E. Ansok)
    Re: Profanity Check <kcount@ardenhouse.com>
    Re: Profanity Check <jboes@eoexchange.com>
        Reading Data from STDIN  <william.c.nelson@gte.net>
        regex, s and m, dice and elephants <anthony@notsoevil.com>
    Re: regex, s and m, dice and elephants (Tad McClellan)
    Re: regex, s and m, dice and elephants <anthony@notsoevil.com>
    Re: regex, s and m, dice and elephants <anthony@notsoevil.com>
    Re: regex, s and m, dice and elephants <anthony@notsoevil.com>
        rounding to nearest thousand <mike@a2zcables.com>
    Re: rounding to nearest thousand <t.geffert@gmx.de>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 06 Dec 2000 17:53:10 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: A sort of another color -- a Tale, not a question ;)
Message-Id: <a2vX5.5$B9.135400448@news.frii.net>

In article <slrn92sec8.phs.tadmc@magna.metronet.com>,
Tad McClellan <tadmc@metronet.com> wrote:
>The WebDragon <nospam@nospam.com> wrote:
>>In article <2lcX5.77$T3.170845184@news.frii.net>, 
>>cfedde@fedde.littleton.co.us (Chris Fedde) wrote:
>>
>> | Do you need to sort the 'huge body of data' each time that it is
>> | accessed?  If you write out the 'manufactured key' array as a flat
>> | file can it be re-loaded faster than it can be regenerated?
>> | 
>
>
>What Chris is suggesting is the standard technique of creating
>an "index" into the real data.
>
>

Indeed.  This approach begins to emulate what used to be called
ISAM (Indexed Sequential Access Method).  For each access ordering
you create an index file containing the access key and the offset
to the data record.  The index file is written in the sorted order.
For any given data file there may be several of these index files.
Each time the data file is updated the indexes must also be updated.

Another option that WebDragon could concider is simply to duplicate the
data file once for each of the necessary orderings.   Simply create the 
'manufactured key' array and write the data out in that order.
Still The 'huge body of data' must not be all that huge if WebDragon is
doing these sorts in memory and inside the CGI timeframe.
-- 
    This space intentionally left blank


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

Date: Wed, 6 Dec 2000 13:13:06 -0500
From: "kcount" <kcount@ardenhouse.com>
Subject: and- Profanity Check
Message-Id: <90lvej$ndi$1@news.warwick.net>

You may also want to create an array of words that you consider bad news,
and iterate over it.  this way you can just add to the list as you think of
more words instead of messing with the if statement everytime you have an
addition.

@badwords = ("heck", "damn", "poopie");

foreach $dirtyword (@badwords) {
    if ($FORM{'body'} =~ m/$dirtyword/i) {
            # do whatever you want with the body of the form here
             last; #break out of the loop
    }
}

Kip

#!/usr/bin/perl || die;




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

Date: Wed, 06 Dec 2000 17:02:25 GMT
From: Ted <ted_graham@my-deja.com>
Subject: Duplicate Unix's time program on Windows
Message-Id: <90lres$g4l$1@nnrp1.deja.com>

I'm trying to duplicate Unix's time command in Perl.  I was going to
write it in C++, but since I'm learning Perl...

For those that don't know, time is used for timing a command.  For
example:
Sun Microsystems Inc.   SunOS 5.7       Generic October 1998
$ time
usage: time [-p] utility [argument...]
$ time find . -name somethinghardtofind
real        5.6
user        0.5
sys         3.6
$

So I need to read the system clock, execute a system call, and get the
clock again.  Benchmark is designed for a different problem, time only
has single second resolution, Time::HiRes isn't available everywhere
(I'm looking for a portable solution).  times sounded like my solution,
but the following code always shows a time difference of 0:

my($startUser) = (times)[0];
system(@ARGV) == 0 or die "system @ARGV failed: $?";
my($endUser) = (times)[0];
$timeDifference = $endUser-$startUser;

I've tried all 4 components of times, but they are all the same before
and after my system call.

Suggestions?

Ted



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 06 Dec 2000 13:38:14 -0500
From: "Jeff Boes" <jboes@eoexchange.com>
Subject: Re: Duplicate Unix's time program on Windows
Message-Id: <3a2e8801$0$29999$44a10c7e@news.net-link.net>

Unless my newsreader has been taken over by the Illuminati, I think "Ted"
<ted_graham@my-deja.com> babbled:

> So I need to read the system clock, execute a system call, and get the
> clock again.  Benchmark is designed for a different problem, time only
> has single second resolution, Time::HiRes isn't available everywhere
> (I'm looking for a portable solution).  

If Time::HiRes isn't available because it won't build, then you're
screwed: it implies that the OS has no timer features that will give you
a granularity less than a second. My advice is to rely on Time::HiRes.



-- 
Jeff Boes <jboes@eoexchange.com>          Tel:  (616) 381-9889 x.18
Sr. Software Engineer, EoExchange, Inc.   http://www.eoexchange.com/
Search, Monitor, Notify.                  http://www.eomonitor.com/


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

Date: 6 Dec 2000 18:55:32 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Duplicate Unix's time program on Windows
Message-Id: <90m234$545$1@lublin.zrz.tu-berlin.de>

Ted  <ted_graham@my-deja.com> wrote in comp.lang.perl.misc:
>I'm trying to duplicate Unix's time command in Perl.  I was going to

[...]

>my($startUser) = (times)[0];
>system(@ARGV) == 0 or die "system @ARGV failed: $?";
>my($endUser) = (times)[0];
>$timeDifference = $endUser-$startUser;
>
>I've tried all 4 components of times, but they are all the same before
>and after my system call.

The timing should be in (times)[ 2, 3] (the children's times),
because system() forks a subprocess, and that is how it works
for me.  What command have you run for the test?

Hmm... come to think of it, are you doing this on something
windowish?  If so, I wouldn't necessarily expect times() to
be 100% compatible.

Anno


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

Date: Wed, 06 Dec 2000 11:00:01 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Duplicate Unix's time program on Windows
Message-Id: <3A2E8CB1.C65E2AA4@vpservices.com>

Ted wrote:
> 
> Time::HiRes isn't available everywhere

It's on activeState:

C:\WINDOWS> ppm search Time-HiRes
Packages available from
soap://www.ActiveState.com/cgibin/SOAP/ppmserver.plex?cl
ass=PPM::SOAPServer:
Time-HiRes [01.20] High resolution ualarm, usleep, and gettimeofday
C:\WINDOWS>

-- 
Jeff


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

Date: Wed, 6 Dec 2000 11:09:52 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: getting upper bound of two dimensional arraydimens
Message-Id: <slrn92sp6g.q25.tadmc@magna.metronet.com>

dts@netkonnect.net <dts@netkonnect.net> wrote:

>I am trying to retrieve both dimensions of a 2D array.


Have you had a look at perlreftut.pod yet?


>I have read in a Perl book that with the following I can get the
>dimension of a 1D array:
>
>@result=(1,2,4);
>$rows=$#result;
         ^^^^^^   There is the "name" of the array


>but I cannot find a way to do it for a 2D array.


Replace the name of the array with a block that returns a
reference to an array:

   $rows=$#{ $foo[5][2] };


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


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

Date: 6 Dec 2000 17:41:45 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: getting upper bound of two dimensional arraydimens
Message-Id: <90ltop$4t7$1@lublin.zrz.tu-berlin.de>

 <dts@netkonnect.net> wrote in comp.lang.perl.misc:
>I am trying to retrieve both dimensions of a 2D array.
>
>I have read in a Perl book that with the following I can get the
>dimension of a 1D array:
>
>@result=(1,2,4);
>$rows=$#result;

Well, not quite.  The number of rows is one more than that.  It
is more reliably found using @result in a scalar context:

$rows = @result;

>but I cannot find a way to do it for a 2D array.
>
>any suggestions would be most appreciated

From the subject (not from the body of your article) I conclude
that you are aware that in Perl a 2-dimensional array is just
a collection of (references to) 1-dimensional arrays, each of which
can have a different length.  So the dimension (this isn't quite the
right term) isn't well defined, the best we can do is find the
maximum (not an upper bound) of the lengths of the individual
arrays.

Now, if @result is a 2-dimensional array, like

@result = ( [ 1, 2, 3], [ 4, 5], [ 6, 7, 8, 9] );

we can loop through the array, evaluating the individual arrays
in scalar context and assigning the length to a variable $dim if
the current $dim is smaller:

my $dim = 0; for ( @result ) { $dim = @$_ if $dim < @$_ }

Here, $_ walks through the individual array references, so
@$_ walks through the arrays.  Using this in scalar context,
we are talking about the array lengths in each case.

Anno


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

Date: Thu, 7 Dec 2000 07:59:14 +1300
From: "Kelvin Sim" <kjs404@hotmail.com>
Subject: Re: Help with program
Message-Id: <Q2wX5.3013$Fn.101253361@news.xtra.co.nz>

Try entering another alpha code eg GS or XS

Chris Fedde <cfedde@fedde.littleton.co.us> wrote in message
news:xnjX5.90$T3.170653696@news.frii.net...
> In article <mGiX5.2841$Fn.104726739@news.xtra.co.nz>,
> Kelvin Sim <kjs404@hotmail.com> wrote:
> >Bugger... Sorry Chris
> >
> >#! \perl\bin\
> >#
> ># Setting up the FarmCentre Store Codes
> >#
>
> Your program seems to work on my unix box.
>
>     $ perl farmenabler
>     Enter the date:
>     asdf
>     Enter the FarmCentre Warehouse Code:
>     ds
>     You have entered the following date asdf
>     You have entered the following FarmCentre ds Enabler Store
>     Code = 0201
>
> Maybe I'm misunderstanding your question.
>
> chris
> --
>     This space intentionally left blank




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

Date: Wed, 6 Dec 2000 11:25:58 -0500
From: "Jimmy" <someone@compugenx.com>
Subject: Re: How do you convert a Perl script to binary executable in Linux?
Message-Id: <90lpev$6mc$1@bob.news.rcn.net>

You will hear alot of people say "Why would you compile, it will be buggy"
This was very true in the past, but I have found an extremely good compiler.
It is called perl2exe and it is located at

http://www.indigostar.com/perl2exe.htm



This does more than just "embed" perl into c and compile it.  Although that
is how it all started, it currently makes stand alone perl exe's for unix,
and on win32 you will require 1 dll.  The executable will be much fatter
than your script, but that is because it is compiling things such as regex
libs.  However if your intent is to distribute your code much like any other
exe, the size you will have is negligable (sp?).  My full scale network
servers using regex usually compile down to about 1.5 MB


-jimmy



Craig Manley <c.manley@chello.nl> wrote in message
news:3A2E2063.BB5F5200@chello.nl...
> Hi,
>
> I'm looking for a way to convert my Perl CGI scripts to binaries to
> speed up processing time. I've tried converting the Perl scripts to C
> but the C code doesn't compile. I'm not too familiar with Linux but
> there should be a way to dump a binary image of the compiled Perl script
> in memory to a file and make that file executable (similar to Perl2Exe
> in Windows). I've heard about udump but read that it's a deprecated
> utility. The target OS is I'm using is Red Hat Linux 7.0.
>
> -Craig Manley.




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

Date: Wed, 06 Dec 2000 18:07:45 GMT
From: adamf@box43.gnet.pl (Adam)
Subject: Re: How to do 'sort -u' with Perl for windows?
Message-Id: <3a2e7f54.5326354@nntp.lucent.com>

On Mon, 04 Dec 2000 04:20:11 GMT, cfedde@fedde.littleton.co.us (Chris
Fedde) wrote:

>In article <975902166.439730@news.aei.ca>, DH <huyv@usa.net> wrote:

>>I would like to have the equivalent of Unix command  'sort  -u' to run  on
>>windows.

>
>The quickest thing to do would be to look at the perl power tools site.
>and grab a perl implementation of sort:
>
>    http://language.perl.com/ppt/
>
>Another approach would be to grap the cygwin packages and use it's
>implementation of sort:
>
>    http://cygwin.com/

or you can make use of the 'GNU utilities for Win32' package:
http://www.weihenstephan.de/~syring/win32/UnxUtils.html

--
Adam.


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

Date: Thu, 7 Dec 2000 01:41:34 +0800
From: "Lucas" <wstsoi@hongkong.com>
Subject: Re: How to read files from the end?
Message-Id: <90ltnk$kc51@imsp212.netvigator.com>

Thanks!!

I just want to ask more, usually we read the file
from its begining to end:

open(FILE, $filename);
while(<FILE>){
    do whatever I like
}
close(FILE);


is it possible to read it from end to start?
i.e. the last nth line, and (n-1)th line, and
(n-2)th line ....

because most times I can't really know where
the log is, and the search priority is the nearer
date.

Thanks again....


----- Original Message -----
From: "LimboStar" <dontspamme@awdang.com>
Newsgroups: comp.lang.perl.misc
Sent: Wednesday, December 06, 2000 8:35 PM
Subject: Re: How to read files from the end?


> "Lucas" <wstsoi@hongkong.com> wrote...
> >
> > For some reasons, I need to read some recent logs from the log
> > files, how could I read the logs from the end of file, but not the
> > start?
>
>   local *FILE;
>   open( FILE, $filename );
>   seek( FILE, -500, 2 ); # 500 bytes before EOF
>   my @lines = <FILE>;
>   shift @lines; # remove half-eaten line
>
> Assuming you know roughly the length of each line, you can return roughly
> the correct amount of lines (or, if all the lines are exactly the same
> width, you can remove the shift and return an exact number of lines).
>
> Or you could just use tail(1) from your favorite shell:
>
>   ~/$ tail -50 myfile
>
> ...which will display the last 50 lines of the file.
>
> Incidentally, you could do that in perl, too:
>
>   local *FILE;
>   open( FILE, "tail -$numlines $filename |" );
>   my @lines = <FILE>;
>   close( FILE );
>
> But that's not very portable.
>
> --sjd;
>
>




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

Date: 6 Dec 2000 18:00:24 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to read files from the end?
Message-Id: <90luro$4vf$1@lublin.zrz.tu-berlin.de>

You posted your reply before the quoted text.  Don't do that.

Lucas <wstsoi@hongkong.com> wrote in comp.lang.perl.misc:
>Thanks!!
>
>I just want to ask more, usually we read the file
>from its begining to end:
>
>open(FILE, $filename);
>while(<FILE>){
>    do whatever I like
>}
>close(FILE);
>
>
>is it possible to read it from end to start?
>i.e. the last nth line, and (n-1)th line, and
>(n-2)th line ....
>
>because most times I can't really know where
>the log is, and the search priority is the nearer
>date.

You can probably find the time span a log file covers by inspecting
its first row (oldest) and the change date of the file (newest).
This makes a few assumptions, however (the files haven't been copied,
the dates logged refer to the system clock).

If you really must, there is a module on cpan that reads files last
line first.  A cpan search for "backwards" should find it.

Anno


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

Date: Wed, 06 Dec 2000 17:54:57 GMT
From: "Lex Thoonen" <nospam_Lex@peng.nl>
Subject: perl & graphics
Message-Id: <R3vX5.93788$Ae1.1280374@zwoll1.home.nl>

Hi,

I'm a non-programmer, but I've managed to get some scripts to work together
and what they do is this: from a (flatfile) database webpages are built, and
the database is easy to maintain online.

Graphics are uploaded easily and they are given the correct names etc.

My question:

If somebody uploads a .jpg file, I need as well a thumbnail of it. Until
today, I've instructed clients on how to make a thumbnail, because when you
do this via html, you do not really make the image smaller, only show it
smaller. Is there a way (with perl) to really copy the image and make (the
copy) smaller? If so, could you tell me how or where I can find details?

Thanks for reading,


Lex
http://www.peng.nl/index-peng.html




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

Date: Wed, 6 Dec 2000 11:40:12 -0500
From: "Michael J. Habashy" <mjh@servicebidders.com>
Subject: perl under win98 but no win98 directory.
Message-Id: <90lpnh$7j8$1@bob.news.rcn.net>

Can anyone helpp...please...looking for a way to run perl script on a
machine that is formated with win98 but does not have win98 on it.  The DOS
5.0 perl that I have seems to blow up..for no reason...can anyone help..can
I compile this script into an executable..?  or something like that?

thanks
mjh




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

Date: Wed, 06 Dec 2000 18:06:23 GMT
From: Warren L Dodge <warren.dodge@tektronix.com>
Subject: Problem with warn,next,if combinations
Message-Id: <3A2E801E.28F0A16D@tektronix.com>

I have the following script which does not act the way I thought it would.

The second foreach loop does not print the warning message but it does do the
next.

I have tried this on multiple versions of perl5 with the same results.

Does anyone have an idea why?

Email is best for me as far as answers.


To run the script just

script_name   non-existant-file

#!/usr/bin/perl
{
  $where = "first   ";
  foreach $file ( @ARGV) 
  {
    warn "> $where\n";
    chomp $file;         
    if ( ! -f "$file" )
    {
      warn "  $where skipping file that does not exist: $file\n" ; 
      next;
      warn "  $where bad place\n";
    }
  }
  $where = "second  ";
  foreach $file ( @ARGV)                                           
  {
    chomp $file;                                                   
    warn "> $where\n";
    warn "  $where skipping file that does not exist: $file\n",next if ( ! -f
"$file" );
    warn "  $where bad place\n";
  }
  $where = "third   ";
  foreach $file ( @ARGV)                                           
  {
    chomp $file;                                                   
    warn "> $where\n";
    warn "  $where skipping file that does not exist: $file\n" if ( ! -f
"$file" );
    next        if ( ! -f "$file" );
    warn "  $where bad place\n";
  }
}


-- 
Warren Dodge,   Application Engineer phone - (503) 627-4888
Tektronix Inc.  MS 39-645            fax   - (503) 627-5587
14180 S.W. Karl Braun Drive          Email - warren.dodge@tektronix.com
P.O. Box 500    Beaverton, OR 97077


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

Date: 6 Dec 2000 16:26:36 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Problems in embedded perl with LC_NUMERIC
Message-Id: <90lpbs$4o6$1@lublin.zrz.tu-berlin.de>

Frodo Baggins  <thehobbit@altern.org> wrote in comp.lang.perl.misc:
>Hi all,
>  I have a funny problem...  If executed with a LANG variable who
>forces using comma instead of dot for decimal point, the following
>embedded perl program fail, stating that 
>
>Perl lib version (5.00503) doesn't match executable version (5,00503)
>at /usr/lib/perl5/5.005/i386-linux/Config.pm line 7.
>
>(note the comma in executable version....) that's weird:) Everithing
>goes well if I set LC_NUMERIC to C... Anyone encountred it before?
>Should I fill a bug report? 

It's a bug, no doubt.  However, in 5.6 the version isn't treated as a
number anymore (not a good idea in the first place), so this bug was
apparently fixed, if not by accident, then in a general hygienic measure.

You will probably be able to trivially fix the problem in Config.pm
locally (supposing this is "your" perl).

Anno


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

Date: 6 Dec 2000 17:23:20 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Profanity Check
Message-Id: <90lsm8$4d7@gap.cco.caltech.edu>

In article <90lfst$5k3$1@nnrp1.deja.com>,
Teacher Guy  <habfan2@my-deja.com> wrote:
>Hello.  I have set up a Perl message board on our school's website and
>I need to add a profanity check to subject and body sections.  I need
>code that will check for all instances of a word.  For example, I need
>to account for mixed upper and lower case possibilites  (ex. BAStard,
>BASTARd, Bastard, etc.).   Here is the code that works so far:
>
>Can I convert all data to uppercase prior to checking for words????

You can put the "i" modifier on your regexps -- /word/i will match word
whether it appears in upper or lower case.  See "perldoc perlre" for 
more info.

You might want to consider using the \b element to only match entire
words -- /word/ will match "longwords", but /\bword\b/ won't.  If you
don't use the \b, then you'll catch more profanity, but you're also more
likely to match text that should be left alone.  Imagine someone wanting
to discuss Charles Dickens, for example.

For example, look what one censorship script did (from RISKS 20.68):

> Hmmm. So I tried sending...
>
> >"I hope you still have your appetite for scraps of dickens when I bump
> >into you in class in Scunthorpe, Essex on saturday"
>
> Yes! It replied...
>
> >"I hope you still have your appetite for s****s of dickens when I ***p
> >into you in class in S****horpe, Es*** on sa****ay"
>
> Missed the t**, the a** and the d*** though.  [* This line PGN-ed]

-- Gary


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

Date: Wed, 6 Dec 2000 12:51:32 -0500
From: "kcount" <kcount@ardenhouse.com>
Subject: Re: Profanity Check
Message-Id: <90lu61$pl8$1@news.warwick.net>

teacher guy,

use 'i' after the regular expression to ignore case, this way it will match
any combination of upper and lowercase.

ex.

if (($FORM{'body'} =~ /fuck/i)||($FORM{'body'} =~ /asshole/i)||($FORM
{'body'} =~ /slut/i)|


hope this helps.

kip

#!/usr/bin/perl || die;






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

Date: Wed, 06 Dec 2000 13:08:41 -0500
From: "Jeff Boes" <jboes@eoexchange.com>
Subject: Re: Profanity Check
Message-Id: <3a2e80fb$0$30002$44a10c7e@news.net-link.net>

Unless my newsreader has been taken over by the Illuminati, I think
"Jozxyqk" <jfeuerst@eecs.tufts.edu> babbled:

>> Along with finding "false hits" where you reject when there isn't
>> really any profanity.
> 
> Yeah, especially when youre trying to catch letter combinations like
> "ass". Your cl*** won't be able to write alot of normal words. ;)

Heh. In my job I had to tweak a filter that was emailing search results
to clients. The boss wanted the bad words filtered out, including 'sex'.
Then wondered why we weren't picking up hits for Middlesex (England), and
so on...

A lot of it will have to do with judicious use of the \b pattern
metacharacter. Good luck!

-- 
Jeff Boes <jboes@eoexchange.com>          Tel:  (616) 381-9889 x.18
Sr. Software Engineer, EoExchange, Inc.   http://www.eoexchange.com/
Search, Monitor, Notify.                  http://www.eomonitor.com/


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

Date: Wed, 06 Dec 2000 18:05:35 GMT
From: Bill Nelson <william.c.nelson@gte.net>
Subject: Reading Data from STDIN 
Message-Id: <3A2E7F53.8D1CDD1B@gte.net>

If I do not know how big data coming in from STDIN is, how can I use the
read() command (or other similar command) to get the data from STDIN?

Note:  I cannot use a while(<>) or @array = <STDIN> because I do not see
end of file in the data.

I am passing data from a web page form to a port on a server which is
not running a web server.  I have a perl script read the data from STDIN
and this is where I am having problems.  If I specify a length of that
data I can read it just fine.  Problem is that I do not know the length
of the data so I cannot do this accurately.

any help would be most appreciated!

thanks,

bill nelson





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

Date: Wed, 06 Dec 2000 16:39:09 GMT
From: Anthony Bouvier <anthony@notsoevil.com>
Subject: regex, s and m, dice and elephants
Message-Id: <39577732.E8752A14@notsoevil.com>

Taking the following code, how should I change it into a loop that will execute
RollDice for each match of something like:

//roll 4 5

and substitute appropriately?

# scan for dice roll
if ($message =~ m#//roll (\d{1,2} \d{1,2})#) {
 $printdice = &RollDice($1);
 $message =~ s#//roll \d{1,2} \d{1,2}#$printdice#;
}

if $message is simple, like:
"blah blah blah //roll 4 5"
$printdice becomes the set of rolled dice (1 5 6 3)
so $message substitutes $printdice for the roll 'command', once.

but, how would I go about getting it to work
if $message has multiple roll commands like:
blah //roll 4 5 blah blah //roll 6 7

setting /g replaces all instances of the roll command,
but only with the first set of results.

Any ideas?

-- 
anthony bouvier
notsoevil philosopher
--


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

Date: Wed, 6 Dec 2000 11:06:42 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: regex, s and m, dice and elephants
Message-Id: <slrn92sp0i.q25.tadmc@magna.metronet.com>

Anthony Bouvier <anthony@notsoevil.com> wrote:
>Taking the following code, how should I change it into a loop that will execute
>RollDice for each match of something like:
>
>//roll 4 5
>
>and substitute appropriately?
>
># scan for dice roll
>if ($message =~ m#//roll (\d{1,2} \d{1,2})#) {
 

   while ($message =~ m#//roll (\d{1,2} \d{1,2})#g ) {
   ^^^^^                                         ^
   ^^^^^                                         ^

> $printdice = &RollDice($1);
> $message =~ s#//roll \d{1,2} \d{1,2}#$printdice#;
>}

>but, how would I go about getting it to work
>if $message has multiple roll commands like:
>blah //roll 4 5 blah blah //roll 6 7


You do not need a loop nor an if()!

   $message =~ s#//roll (\d{1,2} \d{1,2})# RollDice($1) #ge;


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


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

Date: Wed, 06 Dec 2000 17:35:47 GMT
From: Anthony Bouvier <anthony@notsoevil.com>
Subject: Re: regex, s and m, dice and elephants
Message-Id: <39578471.15083460@notsoevil.com>

> You do not need a loop nor an if()!
> 
>    $message =~ s#//roll (\d{1,2} \d{1,2})# RollDice($1) #ge;
> 

Egads!  That is what I was originally trying, but I forgot the /e modifier!

Thanks.

-- 
anthony bouvier
notsoevil philosopher
--


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

Date: Wed, 06 Dec 2000 18:00:42 GMT
From: Anthony Bouvier <anthony@notsoevil.com>
Subject: Re: regex, s and m, dice and elephants
Message-Id: <39578A3B.952A1020@notsoevil.com>

you know, actually, after running that code (thought it does work), the result
set is the larger than it should be.  Example

$message = "blah //roll 4 5";
$message =~ s#//roll (\d{1,2} \d{1,2})#&RollDice($1)#ge;

# $message eq "blah 1 2 3 4";

$message = "blah //roll 4 5 blah //roll 6 7";
$message =~ s#//roll (\d{1,2} \d{1,2})#&RollDice($1)#ge;

# $message eq "blah 1 2 3 4 blah 1 2 3 4 5 6 7 9 10";
# it appears that the first numbers immediately after //roll
# are being added together to create a larger number of 'dice' rolled
# (4 + 6 = 10).  This could be coincidence, however.

-- 
anthony bouvier
notsoevil philosopher
--


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

Date: Wed, 06 Dec 2000 18:22:43 GMT
From: Anthony Bouvier <anthony@notsoevil.com>
Subject: Re: regex, s and m, dice and elephants
Message-Id: <39578F5B.7D81D6DC@notsoevil.com>

Oh, nevermind.  Scope problem in RollDice().

-- 
anthony bouvier
notsoevil philosopher
--


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

Date: Wed, 06 Dec 2000 18:41:07 GMT
From: Mike Gardner <mike@a2zcables.com>
Subject: rounding to nearest thousand
Message-Id: <3A2E8B89.F2A72BD5@a2zcables.com>

Sounds simple, but for the life of me I can't figure out how to round a
number to the nearest thousand in my script.  Isn't there a module
available or a simple line of code that accomplishes this?

example, i need this:  946 rounds to 1000, 432 rounds to 500

Thanks!

Mike Gardner
mike@a2zcables.com
http://www.a2zcables.com
(607) 257-8897



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

Date: 06 Dec 2000 19:59:44 +0100
From: Thomas Geffert <t.geffert@gmx.de>
Subject: Re: rounding to nearest thousand
Message-Id: <m3k89d1ilb.fsf@cal056202.student.utwente.nl>

Mike Gardner <mike@a2zcables.com> writes:

> Sounds simple, but for the life of me I can't figure out how to round a
> number to the nearest thousand in my script.  Isn't there a module
> available or a simple line of code that accomplishes this?
> 
> example, i need this:  946 rounds to 1000, 432 rounds to 500

I'm not sure, what you want really to do, as with 'rounding to the nearest 
thousand', I should not expect 432 to be rounded to 500.

But try this and change it to your needs:

$base=1000; # or 500 for the above example
$rounded = int($number/$base+1)*$base;

If you want to round really to the nearest number and to the bigger one, use

$rounded = int($number/$base+0.5)*$base;


 Thomas


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 5046
**************************************


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