[21971] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4193 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 28 09:05:43 2002

Date: Thu, 28 Nov 2002 06:05:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 28 Nov 2002     Volume: 10 Number: 4193

Today's topics:
    Re: a scope question <nobull@mail.com>
    Re: beginner in perl (krakle)
    Re: beginner in perl <bernard.el-hagin@DODGE_THISlido-tech.net>
        Can't open c:/foo/bar.xls. It may be in use or protecte (=?ISO-8859-1?Q?Mark_F=F6rster?=)
        checking script for perl version compliance (qanda)
    Re: command-line output re-direction in winNT <solo@isd.dp.ua>
    Re: Cookie Details Showing In Browser Window <dgardiner@houston.rr.com>
        DBI-Performance Problem <Henning.Meyer@bln1.siemens.de12345>
    Re: DBI-Performance Problem <rereidy@indra.com>
    Re: Getopt::Std - more info. (qanda)
    Re: help: multi-dimensional hash from flat array <usenet@tinita.de>
        Indenting with Data::Dumper::Dump() <cingram@pjocsNOSPAMORHAM.demon.co.uk>
    Re: Need help in using ftp. <nobull@mail.com>
    Re: Need help in using ftp. (Helgi Briem)
        Order form script <mark@NOSPAMwebwriter.co.uk>
    Re: Order form script <bernard.el-hagin@DODGE_THISlido-tech.net>
        Perl Validation (Gareth Glaccum)
    Re: Please take my two-minute software engineering surv <tassilo.parseval@post.rwth-aachen.de>
    Re: reg expression question (Gareth Glaccum)
    Re: Regular expression question <usenet@tinita.de>
    Re: rounding numbers <BROWNHIK@Syntegra.Bt.Co.Uk>
    Re: Sentence splitter (Caie)
    Re: Sentence splitter (Helgi Briem)
    Re: splitting with positive look-behind <jvandervloet@hotmail.com>
    Re: Teaching Perl complex data structures <usenet@tinita.de>
    Re: Teaching Perl complex data structures <comdog@panix.com>
    Re: trigger internal iis 5.0 services <clandos@web.de>
    Re: visible progress during loop? <andrew_harton@agilent.com>
    Re: What is $a,$b <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: What is $a,$b (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 28 Nov 2002 12:57:14 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: a scope question
Message-Id: <u9el9526ol.fsf@wcl-l.bham.ac.uk>

"Jürgen Exner" <jurgenex@hotmail.com> writes:

> derek chen wrote:
> > I can't understand why this would not work. $i is visible to test but
> > why test is not aware of $i's chnage?
> >
> > my $i=0;
> > for $i (1 .. 10){
> >     test();
> > }
> >
> > sub test
> > {
> >     print "$i\n";     # always print 0
> > }
> 
> The answer can be found in the man page for 'for' (perldoc perlsyn):

Actually it can't.  What the manual says is wrong.  Or rather the
manual describes the behaviour that I (and evidently the OP) would
consider to be "The Right Thing" but not the actual behaviour.

>     The `foreach' loop iterates over a normal list value and sets
>     the variable VAR [...]. If the variable was previously declared
>     with `my', it uses that variable instead of the global one, but
>     it's still localized to the loop.

The variable is not localized, at least not in the sense of the
special meaning of that word in relation to Perl.  If it were
localized then the code would have worked the way the OP expected.

What the manual could say to describe the actual behaviour is:

  If the variable is explicitly or _previously_ declared with `my',
  then it is implicity redeclared with my within the scope of the loop
  body.

IMNSHO this is a "Bad Thing".  I think it would be better if the
variable _was_ localized or failing that a warning should be emitted
if a lexical varible is used without an explict `my'.

This docuementation bug has, of course, been discussed before in the
thread surrounding message <u9lme64fj0.fsf@wcl-l.bham.ac.uk>.

http://groups.google.com/groups?selm=u9lme64fj0.fsf%40wcl-l.bham.ac.uk

As I said later in that thread, I've always considered it a bad thing
that lexicals can't be localized (and I'm in good company (LW)).  Why
should I be forced to use package variables just because I really do
(occasionally) want the semantics of local()?

Fortunately this will almost certainly be corrected in Perl6.  See current
thread "Dynamic scoping (take 2)" over in the Perl6 discussion groups.   

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 28 Nov 2002 05:17:33 -0800
From: krakle@visto.com (krakle)
Subject: Re: beginner in perl
Message-Id: <237aaff8.0211280517.72362d88@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:
> What you are asking for is the job of the Operating System,
> not the job of a programming language.

Oh god. Lighten up and pull the stick out of your ass Tad.
I'm sure the car dealership wouldn't tell the customer to contact Ford
to find out what tires are on the car when they know. You could of
used less bandwidth, key strokes and effort by just saying "crone
job".

> 
> You have an OS question, not a Perl question.
> 
> Ask in an OS newsgroup such as:
> 
>    comp.os.linux.*
>    comp.os.ms-windows.*
>    comp.os.apple

"How can I make a Perl script run on a schedule"
They would send you here buddy because I'm pretty sure non-perl users
and non-programmers wouldn't know how to execute a perl script.


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

Date: Thu, 28 Nov 2002 13:26:43 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: beginner in perl
Message-Id: <slrnauc674.7am.bernard.el-hagin@gdndev25.lido-tech>

Snap, krakle and pop wrote:

> tadmc@augustmail.com (Tad McClellan) wrote in message news:
>> What you are asking for is the job of the Operating System,
>> not the job of a programming language.
> 
> Oh god. Lighten up and pull the stick out of your ass Tad.


I'm sure that Tad is not into that kinky stuff. Don't assume people
enjoy the same hobbies as you do.


> I'm sure the car dealership wouldn't tell the customer to contact Ford
> to find out what tires are on the car when they know. You could of


That's "could have", not "could of". Common mistake, but then again
you seem so...common.


> used less bandwidth, key strokes and effort by just saying "crone
> job".


There is no such thing as a "crone job". Unless that's more of that
kinky stuff you're so obviously into.


>> You have an OS question, not a Perl question.
>> 
>> Ask in an OS newsgroup such as:
>> 
>>    comp.os.linux.*
>>    comp.os.ms-windows.*
>>    comp.os.apple
> 
> "How can I make a Perl script run on a schedule"
> They would send you here buddy because I'm pretty sure non-perl users
> and non-programmers wouldn't know how to execute a perl script.


That sentence makes no sense. Not surprising, really.


Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: 28 Nov 2002 03:33:35 -0800
From: chulinn@gmx.de (=?ISO-8859-1?Q?Mark_F=F6rster?=)
Subject: Can't open c:/foo/bar.xls. It may be in use or protected.
Message-Id: <c7d3a90.0211280333.116767b6@posting.google.com>

Hi,

I have already searched google etc. for this message but did not find
anything so far. I have written a perl script which uses
Spreadsheet::Writeexcel to produce a sequence of excel files on a
local disk. On 2 computers it runs fine, on a third computer I always
get the same error message when trying to write file number 91:

Can't open c:/foo/bar_91.xls. It may be in use or protected.
 at C:/Perl/site/lib/Spreadsheet/WriteExcel/Workbook.pm line 528
        (in cleanup) Can't open c:/foo/bar_91.xls. It may be in use or
protected.
 at C:/Perl/site/lib/Spreadsheet/WriteExcel/Workbook.pm line 528

The specs for all 3 systems are:
Windows 2000 Workstation with 256 MB RAM
ActivePerl 5.6.1 with some modules (e.g. WriteExcel Version 0.37).

I have already checked the filesystem, there are no NTFS permission
problems with file c:/foo/bar_91.xls, and there is noone accessing the
file. If I tell the script to start with file c:/foo/bar_91.xls, it
will fail after 91 files and reports an error with c:/foo/bar_181.xls.
There is always only one filehandle open, they are immediately closed
after writing so I cannot see why I can only produce 90 files.

-> Why is the script running fine on 2 systems and not on another? Or
what can I do to isolate the problem?

Cheers,
Mark


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

Date: 28 Nov 2002 04:32:54 -0800
From: fumail@freeuk.com (qanda)
Subject: checking script for perl version compliance
Message-Id: <62b4710f.0211280432.45d30ac5@posting.google.com>

Hi all

is there a tool that can be used to check what versions of perl a perl
script will work correctly with?

For example if I wrote script.pl I'd like to run something like pvchk
script.pl
and be told that the earliest version the script would work safely
with is n.n.

cheers.


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

Date: Thu, 28 Nov 2002 10:47:43 +0200
From: Serge Olkhowik <solo@isd.dp.ua>
Subject: Re: command-line output re-direction in winNT
Message-Id: <uznrursgg.fsf@isd.dp.ua>

On 22 Nov 2002 13:44:53 -0800
 Malcolm Dew-Jones (Malcolm) wrote:


 Malcolm> I will guess the above is basically equivalent to

 Malcolm> 	C:> start dosbox-for-perl.pif > outfile

 Just the easiest way is to wrap your .pl into .bat|.cmd.
 Works fine and handles both stdout and stderr normally.

-- 
ISD Configuration Management Team
solo@isd.dp.ua 2:464/227@fidonet ICQ:74383178


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

Date: Thu, 28 Nov 2002 10:12:02 GMT
From: Douglas Gardiner <dgardiner@houston.rr.com>
Subject: Re: Cookie Details Showing In Browser Window
Message-Id: <3DE5D245.2020209@houston.rr.com>



The Herbs Place wrote:

>I have written a subroutine to go into an existing shopping cart script.
>The subroutine checks to see if  a persons order is over $40.00 if so then
>it shows them lower prices for their order (the form statement takes them to
>a special copy of the script that uses total weight field for the wholesale
>prices).  If not it gives them an error page called Oops and advises them to
>back up with their browser button.
>
>Currrently, I am just trying to get the error message to print without the
>cookie details being shown on the screen below the error message.  That is
>why I have commented out the if test until the message prints correctly.  At
>the very bottom are the cookie details that need to not be printed.
>
>Please tell me what I am doing wrong.  Thanks in advance for your help.
>
>Randal
>
>*************
>sub check_member {
>#if ($form{'totalweight'} < 40 && $form{'ordertype'} == "M") {
>print "Content-type: text/html\n\n";
>    print "<html><head><title>Error Page</title></head><body
>bgcolor=\"#FFFFFF\">\n";
>
>    print "<center><font face=\"Verdana, Arial, Helvetica, sans-serif\"><hr
>size=5 width=400 noshade>";
>    print    "<br><h1>Oops!</h1>There was a problem processing the last
>request.  <br>Your Member Total must be over \$40.00 to use the member
>prices.<br>";
>   print     "Just hit the browser back button to add to your
>order.<BR><BR>";
>    print "We apologize for any inconvenience this may cause.";
>     print "<br><br><br><font face=\"Courier New, Courier, mono\"><hr size=5
>width=400 noshade>";
>  }   
>#} 
>************
>
>
>Cookie Details
>
>************
>
>Content-Type: text/html Set-Cookie: surfshop_user_id=1036360184_3939;
>expires=Wed, 13-Nov-2002 17:54:26 GMT;
>
>************
>  
>
Needs to be in the header, not the body of the text.  Other words, send 
it first

>  
>



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

Date: Thu, 28 Nov 2002 11:30:35 +0100
From: Henning Meyer <Henning.Meyer@bln1.siemens.de12345>
Subject: DBI-Performance Problem
Message-Id: <3DE5F04B.F8EB0728@bln1.siemens.de12345>

Hello,

I use Perl 5.6.0, DBI 1.30 and DBD-Oracle 1.12.
While checking the performance, my Oracle-Tools discovered, that the
Database does two prepares for every execute.

My Perl-Code looks like this:

        my $cur=$dbh->prepare($call);
        die "Prepare-Error: $DBI::err\n$call\n$DBI::errstr\n" if
($DBI::err);
        $cur->execute(@$vars);
        die "Execute-Error: $DBI::err\n$call\n$DBI::errstr\n" if
($DBI::err);
        my @res=();
        while (my $href=$cur->fetchrow_hashref) {
                die "Fetch-Error: $DBI::err\n$call\n$DBI::errstr\n" if
($DBI::err);
                for(keys %$href) {
                        $href->{$_}=~s/[\s]*$//;
                        $href->{$_}=~s/^[\s]//;
                }
                push(@res,$href);
        }
        $cur->finish;
        return(\@res);

How could it be, that there is an prepare/execute ratio of 2?

I have execute much equal statements with bind-Values, and its very
annoying that there are 400 prepares for 200 executes instead of one
prepare.

Any hints?

Henning





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

Date: Thu, 28 Nov 2002 06:30:05 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: DBI-Performance Problem
Message-Id: <3DE61A5D.5AF15743@indra.com>

Henning Meyer wrote:
> 
> Hello,
> 
> I use Perl 5.6.0, DBI 1.30 and DBD-Oracle 1.12.
> While checking the performance, my Oracle-Tools discovered, that the
> Database does two prepares for every execute.
> 
> My Perl-Code looks like this:
> 
>         my $cur=$dbh->prepare($call);
>         die "Prepare-Error: $DBI::err\n$call\n$DBI::errstr\n" if
> ($DBI::err);
>         $cur->execute(@$vars);
>         die "Execute-Error: $DBI::err\n$call\n$DBI::errstr\n" if
> ($DBI::err);
>         my @res=();
>         while (my $href=$cur->fetchrow_hashref) {
>                 die "Fetch-Error: $DBI::err\n$call\n$DBI::errstr\n" if
> ($DBI::err);
>                 for(keys %$href) {
>                         $href->{$_}=~s/[\s]*$//;
>                         $href->{$_}=~s/^[\s]//;
>                 }
>                 push(@res,$href);
>         }
>         $cur->finish;
>         return(\@res);
> 
> How could it be, that there is an prepare/execute ratio of 2?
> 
> I have execute much equal statements with bind-Values, and its very
> annoying that there are 400 prepares for 200 executes instead of one
> prepare.
> 
> Any hints?
> 
> Henning
Henning,

I cannot find anything that would suggest why this would happen, nor
have I ever seen this before.

What output do you get if you set DBI tracing at level 3 or 4?  This may
illuminate this problem more.
-- 
Ron Reidy
Oracle DBA


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

Date: 28 Nov 2002 01:37:12 -0800
From: fumail@freeuk.com (qanda)
Subject: Re: Getopt::Std - more info.
Message-Id: <62b4710f.0211280137.506f8657@posting.google.com>

Thanks a lot, that answered by original question.

This is just a skeleton I'm using while learning perl, presentation,
variable names, use of globals etc are for speed and quick testing, I
certainly wouldn't write something like this in a commercial
environment.

As for setting exit code, I thought every time the script ended
upexpectedly would be some kind of error so would therefore call the
usage function.  Passing the code in just seems a bit cleaner than
calling exit lots of times.

I'm only beginning to learn the basics of perl, once I've done that,
as with any language I need to learn the idioms.  What are your
thoughts on using the END block?

I've just started on the camel book so have lots of reading to do,
until I learn more any help you can give as far as perlisms would be
helpful.

One more question, can we suppress the 'Unknown option: ' message from
getopts?

thanks again for your help.


"John W. Krahn" <krahnj@acm.org> wrote in message news:<3DE51942.34D7A9E3@acm.org>...
> qanda wrote:
> > 
> > Thanks for all the replies but I'm still confused.
> > I thought of using @ARGV but still don't see how I can KNOW when I
> > have the extra argument, ARGV seems to change after getopts.
> 
> Yes it does.  getopts removes all valid arguments from @ARGV.
> 
> 
> > Here's a sample script. (critism appreciated - come from C background
> > - still learning perl).  Sorry for the length, I've cut out most of
> > the comments and body to keep it shorter.
> > 
> > *** START OF SCRIPT ***
> > 
> > #!/usr/bin/perl -w
> > 
> > use warnings;
> > use strict;
> > 
> > use vars qw( $arg_a $arg_b $ec );
> 
> Ick.  Would you use global variables in your C programs?
> 
> 
> > init();
> > parse_args();
> > 
> > # Use end block to set exit value for program.
> > END
> > {
> >     $? = $ec;
> > }
> 
> Is there any reason that you can't just use "exit $ec" in the
> appropriate places?
> 
> 
> > # Initialise global exit code.
> > sub init
> > {
> >     $ec = 0;
> > }
> > 
> > sub usage($)
> > {
> >     $ec = $_[0];
> 
> [snip]
> 
> > EOF
> >     }
> > }
> > 
> > sub parse_args
> > {
> >     use Getopt::Std;
> >     our( $opt_a, $opt_b, $opt_h, $opt_m );
> > 
> >     # Print usage if we have no arguments.
> >     if( @ARGV == 0 )
> >     {
> >         print STDERR "Arguments are mandatory.\n";
> >         usage(1);
> >     }
> > 
> >     # Print usage if we have invalid options.
> >     getopts('a:b:hm') or usage(2);
> 
> getopts() has now removed all valid options from @ARGV.
> 
>       if ( @ARGV ) { # or @ARGV != 0
>           print STDERR "Extra arguments found.\n";
>           usage( 7 );
>       }
> 
> 
> >     # Print usage if we have help option.
> >     if( defined $opt_h )
> >     {
> >         usage(3);
> >     }
> 
> [snip]
> 
> 
> 
> John


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

Date: 28 Nov 2002 11:34:51 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: help: multi-dimensional hash from flat array
Message-Id: <as4v0r$oen5a$1@fu-berlin.de>

Damian James <damian@qimr.edu.au> wrote:
> On Wed, 27 Nov 2002 04:10:38 -0500, Chef Tako said:
>>evil yes; but necessary. i found myself in a hole where
>>i need to create flat variable names (through a cgi- web page form) and 
>>need to get it uniquely back into my session hash.
>>...
>>What do you percieve and suggest as an elegant solution?

> I think this works in more cases than the other response in this
> thread, which doesn't respect existing values.

it does... maybe you haven't read my second posting.

reagards, tina
-- 
http://www.tinita.de/        \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/      \     / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/   \    \ _,_\ __/\ __/_| /__/ perception


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

Date: Thu, 28 Nov 2002 13:00:14 -0000
From: "Clyde Ingram" <cingram@pjocsNOSPAMORHAM.demon.co.uk>
Subject: Indenting with Data::Dumper::Dump()
Message-Id: <as53tt$bkv$1$8302bc10@news.demon.co.uk>

The Dump() method in Data::Dumper.pm can be configured with the variable
$Data::Dumper::Indent to select the style on indenting of a structure that
you dump.

For example, (using 4-space indent as suggested by perlstyle), I define this
hash reference:

$fruit = {
    yellow => [ banana, lemon ] ,
    red_coloured_skin_tone => {
        hard_texture => apple,
        soft_texture => [ strawberry, raspberry ]
    }
};

Dump() produces something resembing:

$fruit = {
              yellow => [
                                banana,
                                lemon
                        ] ,
              red_coloured_skin_tone => {
                                                            hard_texture =>
apple,
                                                            soft_texture =>
[

strawberry,

raspberry
                                                                            
  ]
                                 }
                     };

which quickly line wraps in my editor.

Is there any easy way (short of my re-writing my copy of
Data::Dumper::Dump() ) to get back to 4-space indent, and also to make the
closing braces/brackets line up with first character of the key which
indexes the block (Kernighan & Ritchie style)?





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

Date: 28 Nov 2002 08:39:50 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Need help in using ftp.
Message-Id: <u9isyi11hg.fsf@wcl-l.bham.ac.uk>

"Franklin Lee" <pengtaoli@hotmail.com> writes:

> I want to use ftp in my Perl program.

You need to analyse your problem a bit more.  Do you mean you want to
use the program ftp or the protocol FTP?  These are quite different
desires.
 
> In Ksh, I can write: ftp -vin <<EOF
> open aaa
> user user1 aaa
> put bbb
> bye
> EOF
> 
> But in Perl, I don't know how to do it.

There are two alternative approches depending on what you want.  If
you want to use the ftp program as in ksh then what you are really
asking is how to spawn external programs under Perl and feed them
stuff on STDIN:

  perldoc -f open
  perldoc perlipc

This, of couse, has nothing to do with FTP.

The alternative approach is to use Net::FTP.

> I didn't have Net::Ftp

So you've solved your problem already.  Why did you hit send?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 28 Nov 2002 10:22:00 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Need help in using ftp.
Message-Id: <3de5ecd1.3740891287@news.cis.dfn.de>

On Thu, 28 Nov 2002 14:59:31 +0800, "Franklin Lee"
<pengtaoli@hotmail.com> wrote:

>Hello,
>I want to use ftp in my Perl program.
>
>In Ksh, I can write:
>ftp -vin <<EOF
>open aaa
>user user1 aaa
>put bbb
>bye
>EOF
>
>But in Perl, I don't know how to do it.
>I didn't have Net::Ftp 

Then install it.


-- 
Regards, Helgi Briem
helgi AT decode DOT is

                           A: Top posting
                           Q: What is the most irritating thing on Usenet?
                                           - "Gordon" on apihna


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

Date: Thu, 28 Nov 2002 10:02:48 -0000
From: "CamelChops" <mark@NOSPAMwebwriter.co.uk>
Subject: Order form script
Message-Id: <dRlF9.10337$bV3.2567@news-binary.blueyonder.co.uk>

Would anyone happen to know of an Order Form script that auto calculates to
reach a pre defined number?

For example:

A card company sells boxes of 12 Christmas cards on the web. You can choose
which out of eight designs you'd like in your box.

So selecting 2 of the first design leaves 10 available from the others.
Selecting 4 more cards from the second design leaves six
remaining cards to choose from, and so on. It won't let you order 11 or 13 -
just 12.

Many thanks for your help!

Mark
mark @ webwriter . co . uk




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

Date: Thu, 28 Nov 2002 10:04:01 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Order form script
Message-Id: <as4pmh$nba$1@korweta.task.gda.pl>

In article <dRlF9.10337$bV3.2567@news-binary.blueyonder.co.uk>,
CamelChops wrote:
> Would anyone happen to know of an Order Form script that auto
> calculates to reach a pre defined number?


What is your Perl question, son?


Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: 28 Nov 2002 03:58:14 -0800
From: verycoldpenguin@hotmail.com (Gareth Glaccum)
Subject: Perl Validation
Message-Id: <991491a9.0211280358.3032479d@posting.google.com>

Are there any standards or validations that perl has passed?
For example, has the code been tested to a def-stan?
I have seen comments about it being used for the UK Air traffic
control, did this happen, and how was it validated safe for use?
Gareth


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

Date: 28 Nov 2002 08:55:10 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Please take my two-minute software engineering survey!
Message-Id: <as4lle$c6d$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Malcolm Dew-Jones:

> Jeremy Leipzig (jnleipzi@unity.ncsu.edu) wrote:
>: http://zigster.com/survey.html
> 
> perl -S get. zigster.com/survey.html | grep -i perl
> 
> => no output from grep <=
> 
> Why is this in a perl group?

If you replace perl with most of the other languages you wont get any
output from grep either. Does that mean that it would belong in no
newsgroup at all?

Sure, it's off-topic for this group and still, posting this to some
computer language newsgroups seems reasonable to me. Unless you know a
better way to reach people somewhat being in the programming business.

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: 28 Nov 2002 05:42:18 -0800
From: verycoldpenguin@hotmail.com (Gareth Glaccum)
Subject: Re: reg expression question
Message-Id: <991491a9.0211280542.30388014@posting.google.com>

North Lilly <nlilly@slis.kent.edu> wrote in message news:<3DE53A2B.2080901@slis.kent.edu>...
> Can a regular expression be used to take a variable string and add a 
> character to it (ie 1234 -> 12:34)?  If so what is the syntax?


at a guess:
$a="1234";
$a=~s/([0-9][0-9])([0-9][0-9])/$1:$2/;
       ^^^^^^^^^^  ^^^^^^^^^^
         |             /
Or whatever-----------+
Gareth


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

Date: 28 Nov 2002 11:55:12 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Regular expression question
Message-Id: <as5070$o1rvi$1@fu-berlin.de>

Steven May <stevenm@blackwater-pacific.com> wrote:
> North Lilly wrote:
>> 
>> Can a regular expression be used to take a string and add a character to 
>> it (ie 1234 -> 12:34)?  If so what is the syntax?
>> 

> given the above:

> #! /usr/bin/perl -w
> use strict;
> my $string = '1234';
> $string =~ s/(\d\d)(\d\d)/\1:\2/;
> print "string is $string\n";
> exit 0;

> results:

> string is 12:34

which perl version are you using? i get:
\1 better written as $1 at -e line 6.
\2 better written as $2 at -e line 6.
string is 12:34

\<digit> is deprecated on the right hand side of s///

regards, tina
-- 
http://www.tinita.de/        \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/      \     / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/   \    \ _,_\ __/\ __/_| /__/ perception


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

Date: Thu, 28 Nov 2002 13:05:29 -0000
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: rounding numbers
Message-Id: <as54mt$sjq$1@pheidippides.axion.bt.co.uk>


"Helgi Briem" <helgi@decode.is> wrote in message
news:3de4a382.3656581255@news.cis.dfn.de...
> On Wed, 27 Nov 2002 10:35:15 -0000, "Kevin Brownhill"
> <BROWNHIK@Syntegra.Bt.Co.Uk> wrote:
>
> >> sprintf() works for all numbers.
> >>
> >But it is sometimes wrong, eg.
>
> No, it is not.
>
> >    sprintf("%.2f", 4.005)
> >returns "4.00"
> >when the correct answer is "4.01"
>
> No it is not.  See the" ANSI/IEEE Std 754-1985, IEEE
> Standard for Binary Floating-Point Arithmetic, IEEE, New
> York, 1985." for example:
> http://www.psc.edu/general/software/packages/ieee/ieee.html
>
> >I am not re-answering any FAQ, I am answering the original question which
> >was  "does anyone know how to round numbers with lots of decimal places
to a
> >certain amount. eg 2 decimal places or 0 decimal places"
>
> But you are answering it incorrectly, which is *ungood*.
>
> >The question others seem to be answering is "how do you print a string
> >representation of a number rounded to n places". This may be what is
really
> >wanted, but is not the question asked.
> >
> >Has anyone read the phrase - "there's more than one way to do it"?
>
> Yes, but in this case, there is a right way ( sprintf or
> printf) and a wrong way (yours). Make the call.


As you have quoted IEEE, here is part of what the IEEE says:
"Therefore round(0.5) is 0 and round(-1.5) is -2."

This is one way of rounding, and is the way sprintf() does it. However it is
inconsistent - somtimes it rounds away from zero and other times toward
zero.

If you want to specify how rounding should be done, the arithmetic way is
the best way.
If you want perl to do it its way, then sprintf() is better.





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

Date: 28 Nov 2002 04:36:57 -0800
From: caie@elixa.co.uk (Caie)
Subject: Re: Sentence splitter
Message-Id: <9fd5216f.0211280436.6efe4a0f@posting.google.com>

helgi@decode.is (Helgi Briem) wrote in message news:<3de352ce.3570379193@news.cis.dfn.de>...
> On 25 Nov 2002 16:32:21 -0800, caie@elixa.co.uk (Caie)
> wrote:
> 
> >I'm currently making an "Automated Plagiarism Detector" as a project
> >for my final year project.  To do so, I am reading in a text file,
> >analysing each sentence for "well-written-ness" and producing an HTML
> >page with the results of this analysis.  One major hurdle I have run
> >into is splitting the given text into sentences.  I am using
> >ActivePerl (the computer I must work on is Win98) and downloaded the
> >Lingua::EN::Sentence-0.23 module.  Unfortunatly this crashes the PC I
> >am working on and therefore I need a different method.
> 
> I find that very hard to believe.  I just installed and 
> tested Lingua::EN::Sentence and it works just fine.
> 
> How can a Perl module crash your computer, even something
> as fragile as Win98?  Which part crashes?  Downloading,
> installing or running?  How are you downloading, installing
> and running it?
> 
> The source code of Lingua::EN::Sentence seems perfectly
> straightforward, simple Perl.  For the life of me I fail to 
> see how its use could crash any OS.

Hi, thanks for replying!

I installed the module through the Perl Package Manager PPM - looked
nice and simple and there were no errors generated in the process. 
The crash occurs at run-time.  If I add the code:

use Lingua::EN::Sentence qw ( get_sentences )

in any of the script, or continue on to add more of it's methods in
the parenthesis and try and use them at some other point Windows
crashes with the error "Perl caused an invalid page fault at:" - then
a load of hex registers.

If I comment out the "use Lingua::...." line then the only errors are
generated as the module hasn't been called and methods are therefore
unavailible.  Even if I don't actually try to use any of
Lingua::EN::Sentences methods I get the same crash message.

I've got two PCs here - a P3 450 under Win98 SE with ADSL, a Geforce
graphics card, network card and a whole load of software all over the
hard drives.  My girlfriends PC on the other hand is a Viglen P3 800
which has barely been touched out of the box, save adding a copy of
Office 2000 and a few Word documents.  The exact same problem happens
when I install ActivePerl and this module on her box.  Argh!

I agree that it is odd that a Perl module should do anything like this
- even on Windows98, and it would suggest that I'm unique in this
problem as the module has had 25 revisions!

I'm pretty close to giving up on this one and putting on my thinking
cap to revise my regex so I can write my own splitter.  Ideas and
thoughts are always welcome lads and gents,

Cheers,

Caie


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

Date: Thu, 28 Nov 2002 12:54:36 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Sentence splitter
Message-Id: <3de60f74.3749759609@news.cis.dfn.de>

On 28 Nov 2002 04:36:57 -0800, caie@elixa.co.uk (Caie)
wrote:

>If I comment out the "use Lingua::...." line then the only errors are
>generated as the module hasn't been called and methods are therefore
>unavailible.  Even if I don't actually try to use any of
>Lingua::EN::Sentences methods I get the same crash message.

<SNIP>

What happens if you use Lingua::EN::Sentences
on its own, without any extra code?  Something like:

#!perl
use warnings;
use strict;
use Lingua::EN::Sentence qw(get_sentences);
my $text = 'Hello, world.  I am a computer program that 
separates sentences.  I use a module.';
my $sentences=get_sentences($text);    
foreach my $sentence (@$sentences) 
{
print "\n$sentence\n########";                  
}
__END__

>I agree that it is odd that a Perl module should do anything like this
>- even on Windows98, and it would suggest that I'm unique in this
>problem as the module has had 25 revisions!
>

There is definitely something fishy going in, but
I have difficulty testing as our company has no
Win95/98/Me machines.  We use only NT/2K/XP.

>I'm pretty close to giving up on this one and putting on my thinking
>cap to revise my regex so I can write my own splitter.  Ideas and
>thoughts are always welcome lads and gents,

The whole module is only about a 100 lines.

You could always cut and paste the relevant code
from it.
-- 
Regards, Helgi Briem
helgi AT decode DOT is

                           A: Top posting
                           Q: What is the most irritating thing on Usenet?
                                           - "Gordon" on apihna


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

Date: Thu, 28 Nov 2002 08:58:40 GMT
From: "joeri" <jvandervloet@hotmail.com>
Subject: Re: splitting with positive look-behind
Message-Id: <4VkF9.24041$Ti2.4813@afrodite.telenet-ops.be>

Thanks a lot! I knew that the "[^ ]" was for characters. But I tried so many
different
things and nothing worked, so I posted my last, desperate attempt. :)

Anyway, I've got it working now. Thanks again.

J.


"Jeff 'japhy' Pinyan" <pinyaj@rpi.edu> wrote in message
news:Pine.A41.3.96.1021126111714.43984A-100000@vcmr-104.server.rpi.edu...
> On Tue, 26 Nov 2002, Jeff 'japhy' Pinyan wrote:
>
> >  my $rx = qr{
> >    (?<=
> >      (?:
> >        (?<! Mr | Ms )
> >        (?<! M\.D | inc | e\.g )
> >      )
> >      [.?!]
> >    )
> >    \s+
> >  }x
>
> THat (?: ... ) was useless.
>
>   my $rx = qr{
>     (?<=
>       (?<! M[rs] )
>       (?<! M\.D | inc | e\.g )
>       [.!?]
>     )
>     \s+
>   }x;
>
> --
> Jeff "japhy" Pinyan      RPI Acacia Brother #734      2002 Acacia Senior
Dean
> "And I vos head of Gestapo for ten     | Michael Palin (as Heinrich
Bimmler)
>  years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead
Bye-Election
>  Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
>




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

Date: 28 Nov 2002 11:01:41 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Teaching Perl complex data structures
Message-Id: <as4t2l$nk2jo$1@fu-berlin.de>

Derek Thomson <derek@wedgetail.com> wrote:

> I was wondering if anyone could advise me on how best to explain the 
> concept of arrays of references to arrays to someone learning Perl.

> Let's say that the person in question is already familiar with Python. 
> In that language, everything is pretty much just a reference, so you can 
> simply say:

> list = [ 'one', 'two', 'three', 'four']
> list[2] = [ 'first', 'second', 'third' ]

> ... to end up with [ 'one', 'two', [ 'first', 'second', 'third' ], four'].

> Because of Perl's behaviour, I can't just do this:

> @list = ( 'one', 'two', 'three', 'four' );
> $list[2] = ( 'first', 'second', 'third' );

> ... because I end up with ( 'one', 'two', 'first', 'four').

no, you don't. you end up with qw(one two third four).

> Now, I understand why that happens, but as you can imagine this causes 
> some confusion.

> Obviously, I need to do this

> @list = ( 'one', 'two', 'three', 'four' );
> $list[2] = [ 'first', 'second', 'third' ];

well, array elements can only be scalars (or references,
which are scalars, too). the same goes with hash values.
once you keep that in mind it's easy to deal with nested
data structures in Perl. IMHO.
but it's also a matter of taste. i don't like that python
thing that everything is a reference. but this wouldn't stop
me from learning it (well, if i had the time)

hth, tina
-- 
http://www.tinita.de/        \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/      \     / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/   \    \ _,_\ __/\ __/_| /__/ perception


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

Date: Thu, 28 Nov 2002 08:03:51 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: Teaching Perl complex data structures
Message-Id: <281120020803517169%comdog@panix.com>

In article <bjjF9.31$_27.782@news.optus.net.au>, Derek Thomson
<derek@wedgetail.com> wrote:

> Because of Perl's behaviour, I can't just do this:

> @list = ( 'one', 'two', 'three', 'four' );
> $list[2] = ( 'first', 'second', 'third' );

> ... because I end up with ( 'one', 'two', 'first', 'four').

are you sure you end up with that?  did you try it?


> Now, I understand why that happens, but as you can imagine this causes 
> some confusion.


> How can I convince people that this is sensible?

sensible has no place here.  that's how it does it.  you don't
have to infer anything because it is arbitrary and documented.
it is just the way Perl does it.  :)

-- 
brian d foy, comdog@panix.com


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

Date: Thu, 28 Nov 2002 12:24:32 +0100
From: "Carsten L." <clandos@web.de>
Subject: Re: trigger internal iis 5.0 services
Message-Id: <3de6040b$0$362$4d4ebb8e@read.news.de.uu.net>


"Helgi Briem" <helgi@decode.is> schrieb im Newsbeitrag
news:3de4c11b.3664159002@news.cis.dfn.de...
> On Wed, 27 Nov 2002 13:42:39 +0100, "Carsten L."
> <clandos@web.de> wrote:
>
> >I want to start and stop, resume "internal-web-site"s within
> >the iis ervice.
> >What I do now is to start and stop the W3SVC . This stops
> >unfortenuately all eb sites at once.
>
> Why on earth are you posting this to a Perl newsgroup ?!?

because I do it now with Win32::Service::StopService(hostName, serviceName)
!?


>
> >Can anyone give me a hint a I can do this?
>
> Try a web server newsgroup or the fine manual.
> I suggest the newsgroup
> comp.infosystems.www.servers.ms-windows
>
> or MS's own IIS web page:
> www.microsoft.com/windows2000/community/centers/iis/default.asp
> --
> Regards, Helgi Briem
> helgi AT decode DOT is
>
>                            A: Top posting
>                            Q: What is the most irritating thing on Usenet?
>                                            - "Gordon" on apihna




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

Date: Thu, 28 Nov 2002 12:07:02 -0000
From: "Andrew Harton" <andrew_harton@agilent.com>
Subject: Re: visible progress during loop?
Message-Id: <1038485226.644365@cswreg.cos.agilent.com>

D wrote:
> Is there any way to have it print something to my screen like, "100
> strings processed".... and then a few minutes later, "200 strings
> processed"....and then a few minutes later, "300t strings
> processed"... you get the idea.
>
> Here's my rough draft (which obviously needs help):
>
> $counter = 0;
> print "starting code";
>   if blah { do this
>             if this { do that
>                       if this { do stuff
>                               $counter = $counter + 1;
>                               if ($counter = 100) { print "100";
>                               $counter = 0;
>                               }
>                       }
>             }
>   }
> print "finished."
>

Setting $| =1 has already been mentioned to un-buffer the output.  To get
the number of strings, use this instead;

  if this { do stuff
      if (++$counter % 100 == 0) { print "$counter\n";}
      }

Now $counter isn't reset, and can be used to keep a running total.

Here's the section from perlop that describes this operator;
Binary ``%'' computes the modulus of two numbers. Given integer operands $a
and $b: If $b is positive, then $a % $b is $a minus the largest multiple of
$b that is not greater than $a. If $b is negative, then $a % $b is $a minus
the smallest multiple of $b that is not less than $a (i.e. the result will
be less than or equal to zero). Note than when use integer is in scope,
``%'' gives you direct access to the modulus operator as implemented by your
C compiler. This operator is not as well defined for negative operands, but
it will execute faster.

Hope that helps.

Andrew

--
$s="acehJklnoPrstu ";$_="4dbce078c32ae92a6e30152a";
split//;for(0..$#_){print substr($s,hex $_[$_],1);}




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

Date: Thu, 28 Nov 2002 08:05:49 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: What is $a,$b
Message-Id: <as4iot$9re$1@korweta.task.gda.pl>

In article <85789064.0211272339.d2a55b2@posting.google.com>, derek chen wrote:
> I tried the snippets below and the interpreter said it ok. But error
> message will show if I use variable names other than $a,$b. Does this
> mean $a, $b are default global variables in main:: ? For what reason ?
> Thanks.


perldoc -f sort
perldoc perlvar



Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: Thu, 28 Nov 2002 07:42:28 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What is $a,$b
Message-Id: <slrnauc7a4.24g.tadmc@magna.augustmail.com>

Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net> wrote:
> In article <85789064.0211272339.d2a55b2@posting.google.com>, derek chen wrote:

>> Does this
>> mean $a, $b are default global variables in main:: ? For what reason ?


> perldoc perlvar


I've always been annoyed that $a and $b were "special" but
were not mentioned anywhere in perlvar.pod.

We're supposed to know to look in the "func" docs to find
out about a "var"? Blech!

I was so happy to see it added to perlvar in v5.8.0.


For those of you that haven't upgraded yet, here's what it says:

--------------------------
=item $a

=item $b

Special package variables when using sort(), see L<perlfunc/sort>.
Because of this specialness $a and $b don't need to be declared
(using local(), use vars, or our()) even when using the strict
vars pragma.  Don't lexicalize them with C<my $a> or C<my $b>
if you want to be able to use them in the sort() comparison block
or function.
--------------------------


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


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

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


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