[16596] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4008 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 14 09:05:38 2000

Date: Mon, 14 Aug 2000 06:05:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <966258316-v9-i4008@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 14 Aug 2000     Volume: 9 Number: 4008

Today's topics:
    Re: - Free ebooks and resources - (Matthew M. Huntbach)
    Re: Best practices.... <iltzu@sci.invalid>
    Re: chmod question (Mat)
    Re: chmod question (Colin Keith)
    Re: CHOMP not working nobull@mail.com
    Re: currency format (Colin Keith)
    Re: currency format nobull@mail.com
    Re: date manipulation <abe@ztreet.demon.nl>
    Re: DBM Files Going Haywire!!! HELP!!! (Malcolm Ray)
    Re: DBM Files Going Haywire!!! HELP!!! mlmguy@my-deja.com
        delete string from file? <ebu@pisem.net>
    Re: delete string from file? (Colin Keith)
    Re: Get the Time <as@if.com>
    Re: grep() optimisation (Mark-Jason Dominus)
    Re: grep() optimisation (fvw)
    Re: grep() optimisation (Martien Verbruggen)
    Re: grep() optimisation (Martien Verbruggen)
    Re: grep() optimisation <abe@ztreet.demon.nl>
    Re: Help: libs with Latin-1 or Unicode? <flavell@mail.cern.ch>
    Re: how can I optimize a tied hash for speed (Mark-Jason Dominus)
    Re: How to change Popup frame's URL (Colin Keith)
        How to execute perlscript from html site <pir9@hotmail.com>
    Re: How to execute perlscript from html site <lincolnmarr@europem01.nt.com>
        Linking the Page Number in Index Section <umungo01@shafika.vetri.com>
        Message board code gregosse2409@my-deja.com
    Re: Negativity in Newsgroup -- Solution (Anno Siegel)
        Net::SMTP is this package available for Win32 PERL? psb154@my-deja.com
        Newbie post problem. <georgec@webleicester.co.uk>
    Re: Newbie post problem. (Colin Keith)
    Re: Perl code for a newbie!! <craig.pugsley@mimesweeper.com>
    Re: Perl code for a newbie!! <flavell@mail.cern.ch>
    Re: Perl for Palm? (Colin Keith)
        rand() not random at all <Jonne.Viljanen@helsinki.fi>
    Re: rand() not random at all <lincolnmarr@europem01.nt.com>
    Re: set variable to results of regex (Mark-Jason Dominus)
        Substituting newlines for HTML equivalent <lincolnmarr@europem01.nt.com>
    Re: Where can I find Basic Perl Definitions? <lincolnmarr@europem01.nt.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 14 Aug 2000 12:06:00 GMT
From: mmh@dcs.qmw.ac.uk (Matthew M. Huntbach)
Subject: Re: - Free ebooks and resources -
Message-Id: <8n8nb8$9ki$4@beta.qmw.ac.uk>

sevensoft (info@sevensoft.net) wrote:
> Matthew M. Huntbach <mmh@dcs.qmw.ac.uk> wrote in message
> > COM Service (webmaster@swap-resources.com) wrote:

> > > I would like to know where I can find free ebooks and good resources
> > > about Java, Perl, Unix, ASP and Visual Basic.

> > There are huge amounts of material on these things available on the web.
> > Anyone with any competence would have no trouble finding them.

> so since you didn't post any such resources, -must- mean that you have
> little if any competence..

The following web page gives a collection of links I've built up for
the Java programming course I teach, including several on-line books:

http://www.dcs.qmw.ac.uk/~mmh/links.html

> asking on these newsgroups is a good way to start, so why not help out a
> little bit instead of trying to insult someone.

But it isn't a good way to start. A good way to start is to enter
something like "Java tutorials" into a search engine. Posting to a
news group means you waste a heck of a lot of other people's time
when for a few minutes work with a search engine you could have got
plenty of information.

Matthew Huntbach


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

Date: 14 Aug 2000 11:17:31 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Best practices....
Message-Id: <966249092.3436@itz.pp.sci.fi>

In article <6yqUOdNhqAAHDDxoguXX6WOM90lZ@4ax.com>, Lou Moran wrote:
>Apparently my code is ugly.  I would like to know where I can get a
>good best practices guide, lesson, clue, so that my code is less
>offensive.
>
 [snip]
>
>#!/usr/bin/perl -w
>use strict;
>
>my ($rate, $otrate, $regular, $overtime, $pay);
>
>print "Enter your hourly rate: \n";
>$rate = <STDIN>;
>chomp ($rate);
>
>print "Enter your regular hours: \n";
>$regular = <STDIN>;
>chomp ($regular);
>
>print "Enter your overtime hours: \n"; 
>$overtime = <STDIN>;
>chomp ($overtime);
>
>$otrate = $overtime * $rate * 1.5;
>$regular = $regular * $rate;
>$pay = $regular + $otrate;
>
>print "Your gross pay for this period is $pay. \n";


That short example looks quite good.  It seems a bit like "spaghetti
code", but that would only be a problem if it were longer.

Which is probably the issue here.  Your code is one unstructured chain
of statements.  This means that, to see what it does, one has to keep
in memory all of it at once: five variables (one of which is reused),
three inputs, three relationships and one output statement.

This is just fine.  Making it ten times longer would definitely not
be, since at that point there would be too much information for the
human brain to easily process simultaneously.


The problem, sometimes known as the Hrair limit, apparently after a
rather obscure reference to the novel _Watership Down_, in programming
as well as cognitive psychology in general, caused by the limited
capacity, approximately seven plus or minus two unrelated items,
according to research pioneered by G. Miller in the 1950's, of the
human short-term memory, is, at least to a first approximation, the
same as the one involved in parsing this, admittedly, but for a good
reason, contrived, sentence.


How would I rewrite your code then?  Well, I wouldn't, not if it was
going to stay this short.  But if I pretended that it was longer, I
would first try to eliminate the redundancy:

  #!/usr/bin/perl -w
  use strict;

  sub ask {
      my $question = shift;
      print "Enter your $question: ";
      my $answer = <STDIN>;
      chomp $answer;
      return $answer;
  }


  my $rate     = ask('hourly rate');
  my $normal   = ask('normal hours');
  my $overtime = ask('overtime hours');

  my $pay = $rate * ($normal + $overtime * 1.5);

  print "Your gross pay for this period is $pay.\n";

  __END__

I also reduced the calculation to a single expression, which is more
readable and avoids the need for temporary variables (or reusing the
same variable for multiple purposes, which is nearly always a sign
that you're doing something wrong).  If the calculation had been any
more complicated than that, I might've turned it into a function as
well, to keep the unnecessary details out of the main program.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method."  -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.



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

Date: Mon, 14 Aug 2000 10:51:12 GMT
From: mat@designsolution.co.uk (Mat)
Subject: Re: chmod question
Message-Id: <3997ce53.9867883@news.btconnect.com>

Eye opener..!  You did forget to mention that you may need to convert
the mode (octal) to decimal, using the oct function.  Perl manual
p149.

This is not in anyway to get the last word, what you wrote encouraged
me to pay a bit more attention to the perl manual.

Mat

On Sun, 13 Aug 2000 11:52:12 GMT, newsgroups@ckeith.clara.net (Colin
Keith) wrote:

>In article <39959107.7890480@news.freeserve.net>, u2o@u2orange.co.uk (u2orange) wrote:
>
>>system ("chmod 0777 $orderfile");
>
>Eww, icky. It even uses an incomplete file name :)
>Besides which, if that works then the Perl chmod() function will work since 
>they both use chmod(2) (afaik). 
>
>Could the OP say what file permissions they get set when using this? Does 
>the chmod fail? (it returns the number of files successfully changed, so in 
>your case, it should return 1).
>
>Dumb question, but just to check, you are using what you posted, 
>  chmod(0777, $filename);
>
>and the 0777 bit isn't quoted in anyway?
>  chmod('0777', $filename);
>and
>  $mode = '0777';
>  chmod($mode, $filename);
>
>will not set the permissions that you want.
>
>Finally, you do have the value you expect in $filename, don't you? If its 
>still not working, get verbose with something like this in your code:
>
>my($file) = '/etc/master.passwd';
>open(LOGFILE, ">>log") || die "barf ($!)";
>print LOGFILE  "chmod of $file : "
>               chmod(0777, $file) ? "Successful\n" : "Failed ($!)\n";
>
>maia% cat log
>chmod of /etc/master.passwd : Failed (Operation not permitted)
>
>
>Hmmm, that suggests two new error handling subs,
>hiccup()
>barf()
>
>Warning: Small hiccup at ./runme line 26. Retrying.
>Fatal:   Something barfed at ./runme line 30.
>
>:)
>
>Hmmm. crash() and burn() maybe? :)
>Col.
>
>
>---
>Colin Keith
>Systems Administrator
>Network Operations Team
>ClaraNET (UK) Ltd. NOC



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

Date: Mon, 14 Aug 2000 11:34:09 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: chmod question
Message-Id: <ROQl5.120$DT4.3604269@nnrp2.clara.net>

In article <3997ce53.9867883@news.btconnect.com>, mat@designsolution.co.uk (Mat) wrote:
>Eye opener..!  You did forget to mention that you may need to convert
>the mode (octal) to decimal, using the oct function.  Perl manual
>p149.

Ooh, mine doesn't have page numbers:) But it was omitted on purpose as these 
examples in the perlfunc man page show:

  $mode = '0644'; chmod $mode, 'foo';      # !!! sets mode to  --w----r-T
  $mode = '0644'; chmod oct($mode), 'foo'; # this is better
  $mode = 0644;   chmod $mode, 'foo';      # this is best

The last one is assigning a numeric value to $mode where the value has a 
leading 0. The leading 0 is taken by Perl to mean the number is octal. (see 
the section "Scalar value constructors" in perldata).

Since the OP had:
  chmod(0777, .. );

I decided not to comment. If they had 777 or '0777' then I would have :) 

>This is not in anyway to get the last word, what you wrote encouraged
>me to pay a bit more attention to the perl manual.

Likewise, simply to explain why I decided not to comment on that.

Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: 14 Aug 2000 13:35:37 +0100
From: nobull@mail.com
Subject: Re: CHOMP not working
Message-Id: <u9k8dkc95y.fsf@wcl-l.bham.ac.uk>

Todd Eddy <vrillusions@mail.com> writes:

> Here is the source in question:

Er, no it isn't - that's the output.

Please show us the source.

> --------------1E90B7231D8C82985C93E699
> Content-Type: text/html; charset=us-ascii
> Content-Transfer-Encoding: 7bit
> 
> <!doctype html public "-//w3c//dtd html 4.0 transitional//en">

If is not a binary newsgroup - please post plaintext only.

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


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

Date: Mon, 14 Aug 2000 11:58:44 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: currency format
Message-Id: <U9Rl5.121$DT4.3605344@nnrp2.clara.net>

In article <8n8chn$ho2$1@nnrp1.deja.com>, eastking@my-deja.com wrote:
>my $a = 1234567;
>I want to it be showed as 1,234,567
>How can I do it.

See the answer in perlfaq5 to the question 
"How can I output my numbers with commas added?"

Its a clear, well commented example that works, which is better than me 
reposting it and getting it wrong:)

Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: 14 Aug 2000 13:35:23 +0100
From: nobull@mail.com
Subject: Re: currency format
Message-Id: <u9lmy0c96c.fsf@wcl-l.bham.ac.uk>

eastking@my-deja.com writes:

> Hello ,every one here.

This usually translates as "I haven't read the FAQ".

> I have a currency number in a scalar, such as
> 
> my $a = 1234567;
> 
> I want to it be showed as 1,234,567

Yup, it's a FAQ.
 
> How can I do it.

Please see the answer to this question in the FAQ.

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


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

Date: Mon, 14 Aug 2000 14:31:41 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: date manipulation
Message-Id: <e8pfps8rncq1paat29i0ek0ha8oqvq9drk@4ax.com>

On Mon, 14 Aug 2000 10:00:10 GMT, Bart Lateur <bart.lateur@skynet.be>
wrote:

> Ilmari Karonen wrote:
> 
> >There seems to be a typo above.  Surely you meant:
> >
> >  int(time() / 86400) * 86400 + 86400/2
> >
> >And as far as I can tell the time returned is not _local_ noon, but
> >12:00 GMT, which sort of defeats the point of the exercise..
> 
> Sure. But you can comvert this time into a string using gmtime(), and
> *pretend* that it's noon local time. Dates in GMT and localtime run
> completely parallel.

Nope, GMT doesn't do daylight savings time (summer-/wintertime).

-- 
Good luck,
Abe


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

Date: 14 Aug 2000 11:07:57 GMT
From: M.Ray@ulcc.ac.uk (Malcolm Ray)
Subject: Re: DBM Files Going Haywire!!! HELP!!!
Message-Id: <slrn8pfkod.am2.M.Ray@carlova.ulcc.ac.uk>

On Sun, 13 Aug 2000 19:42:36 GMT, mlmguy@my-deja.com <mlmguy@my-deja.com>
wrote:
>Hello,
>
>I am new at Perl. I have created an FFA Links Page with 50 Links
>totally. I have tried storing the data in a text file but I dont like
>the results. I then tried to use DBM files using the following code. If
>you notice I have used a 'different' way of locking the process. The
>reason being I dont know any other way of locking. Anyway, now the
>logic of the new link being added on the top and the bottom one being
>deleted is working perfectly. However, strangely, my DBM data file
>keeps growing. It grew to a massive 4.5 MB in one day. But if I try to
>display the total number of records in it, it still shows 50. So what
>is the extra space holding??? Please HELP someone out there. Thanks in
>advance. Here is the code which I am using.

I haven't examined your code, but it may be that those files are not as
big as you think.  At least under Unix, some flavours of DBM will result
in sparse files.  In other words, while 'ls -l $file' will show what
appears to be a large file, much of that space is unallocated.  Use
'ls -s $file' to find out how many blocks the file is actually occupying
on disk.  Or, to return to Perl, look at the 'blocks' field returned
by stat.
-- 
Malcolm Ray                           University of London Computer Centre


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

Date: Mon, 14 Aug 2000 11:49:49 GMT
From: mlmguy@my-deja.com
Subject: Re: DBM Files Going Haywire!!! HELP!!!
Message-Id: <8n8mcs$o07$1@nnrp1.deja.com>

Thank you (both) for your replies. After I posted my question
yesterday, I also did some research for the same on this Forum. I came
to know that if you delete the records from a DBM file, it DOESNOT
remove the space occupied by record. However, in my case, I am NOT
deleting anything. Still the extra space. I tried this method and it
seems to be working for now. I know it may not be the best, but it is
helping me keep the file size in limits for now. Till I find a better
way. Here is what I am doing. I am simply counting the number of links
and when it reaches a pre-determinded level (like say 500), I am
reading the 50 records in an array and the deleting off the WHOLE file
using the unlink command and then create the file again using dbmopen
and then re-writing back the 50 records. I hope someone out there tells
me a better and more efficient method to solve the problem. The
platform where my script is being used is Unix/Linux (and not NT).
Thanks again for your help.

Regards,
mlmguy


In article <slrn8pfkod.am2.M.Ray@carlova.ulcc.ac.uk>,
  M.Ray@ulcc.ac.uk (Malcolm Ray) wrote:
> On Sun, 13 Aug 2000 19:42:36 GMT, mlmguy@my-deja.com <mlmguy@my-
deja.com>
> wrote:
> >Hello,
> >
> >I am new at Perl. I have created an FFA Links Page with 50 Links
> >totally. I have tried storing the data in a text file but I dont like
> >the results. I then tried to use DBM files using the following code.
If
> >you notice I have used a 'different' way of locking the process. The
> >reason being I dont know any other way of locking. Anyway, now the
> >logic of the new link being added on the top and the bottom one being
> >deleted is working perfectly. However, strangely, my DBM data file
> >keeps growing. It grew to a massive 4.5 MB in one day. But if I try
to
> >display the total number of records in it, it still shows 50. So what
> >is the extra space holding??? Please HELP someone out there. Thanks
in
> >advance. Here is the code which I am using.
>
> I haven't examined your code, but it may be that those files are not
as
> big as you think.  At least under Unix, some flavours of DBM will
result
> in sparse files.  In other words, while 'ls -l $file' will show what
> appears to be a large file, much of that space is unallocated.  Use
> 'ls -s $file' to find out how many blocks the file is actually
occupying
> on disk.  Or, to return to Perl, look at the 'blocks' field returned
> by stat.
> --
> Malcolm Ray                           University of London Computer
Centre
>


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


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

Date: Mon, 14 Aug 2000 13:20:35 +0200
From: "Женя Бушуев" <ebu@pisem.net>
Subject: delete string from file?
Message-Id: <966248542.693404@ipt2.iptelecom.net.ua>

How to delete string or change it while parsing file like
open(FP,"+</tmp/dump");
   while (<FP>){
#here i need substitute or delete $_ and put it in file.
}





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

Date: Mon, 14 Aug 2000 12:03:59 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: delete string from file?
Message-Id: <PeRl5.122$DT4.3605595@nnrp2.clara.net>

In article <966248542.693404@ipt2.iptelecom.net.ua>, "Женя Бушуев" <ebu@pisem.net> wrote:
>How to delete string or change it while parsing file like
>open(FP,"+</tmp/dump");
>   while (<FP>){
>#here i need substitute or delete $_ and put it in file.
>}

By looking at the answer given in the PerlFAQ's that came with your 
installation of Perl. PerlFAQ5, section

  "How do I change one line in a file/delete a line in a file/insert a line 
  in the middle of a file/append to the beginning of a file?"

The answers given in the FAQs have been used by thousands of people and 
any bugs/conditions where it doesn't work have been expanded upon. They are 
a good source of clearly written and commented code on many answers that 
people frequently ask.

Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Mon, 14 Aug 2000 12:32:05 GMT
From: "Kermit" <as@if.com>
Subject: Re: Get the Time
Message-Id: <9FRl5.148304$Gh.2334953@news20.bellglobal.com>

Thanks for the feedback,

It's funny how pretty much everyone had something positive to say or at
least were kind in pointing out that it was perhaps too simple a post,
however you managed to once again show how vast your knowledge of Perl is
compared to all these petty people, also your sad attempt at sarcasm is so
original, funny and amazing, you must really be bright.

Cheers.


> Wow! Impressive! I bet noone else figured this one out!
>
>
>
> Abigail
> --
> perl -wlne '}print$.;{' file  # Count the number of lines.




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

Date: Mon, 14 Aug 2000 10:45:59 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: grep() optimisation
Message-Id: <3997cde7.3c98$31e@news.op.net>

[Mailed and posted]

In article <966231197VVC.fvw@var.cx>, fvw <fvw+usenet@var.cx> wrote:
>$b=join('|', @b);
>@c=grep(/([^:]*:){6}.*($b)/i, @a);
>
>but since I have to do this several times, it takes quite some time.
>Anybody got any suggestions?

Yes.  Perl is going to work very hard to try to find a way to make the
regex match, even when it doesn't.  I suggest something like this
instead:

        @c = grep { (tr/:// >= 6) and /$b/oi } @a;

tr/:// counts the number of colons in $_.  This is sure to me a lot
more efficient than treying to match /([^:]*:){6}/.  Then if there are
at least six colons, you go and look for one of the strings from @b.
If there are fewer than 6 colons, you don't bother with the pattern
match at all.

This solution is incorrect if the @b stuff might occur in the part of
the string that contains the colons.  For example, suppose one of the
@b elements is 'dog', and one of the @a elements is

        fish:dog:carrot::::blah-de-blah

and suppose that you *don't* want to include such an item in @c,
because you only want items where the dog is in the 'blah-de-blah'
part.  Then the solution above won't work. 

This will probably be a little slower, but will work in more cases:

        @c = grep { my @q = split /:/, $_, 7; $q[6] =~ /$b/oi } @a;

This breaks up the items of @a into seven fields each, at the first
six colons, and then checks the seventh item (everything after the
sixth colon) to see if it matches $b.

I think trying to do it with one big regex is probably a mistake.
There are much more efficient ways to find six colons than to use
/([^:]*:){6}/.

Disclaimer: I have not benchmarked anything because I do not know what
your data looks like.



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

Date: Mon, 14 Aug 2000 11:20:46 GMT
From: fvw+usenet@var.cx (fvw)
Subject: Re: grep() optimisation
Message-Id: <966252069UBK.fvw@var.cx>

<3997cde7.3c98$31e@news.op.net> (mjd@plover.com):
>In article <966231197VVC.fvw@var.cx>, fvw <fvw+usenet@var.cx> wrote:
[snip good solution for a different case]

My apologies, I have not been clear enough. My data always consists
of 6 colon-terminated strings, followed by a string that I have to
check for matching of substrings. so tr/:// would end up always end up
>=6. The reason I've added the ([^:]:){6} to the beginning of the regexp
is to stop anything from $b from matching anywhere in the first fields
of the string. After advice from someone in this group, I've already
added a ^ to the beginning of it (resulting in a huge speed gain), which
might make it a bit more clear that all I want to do is ignore the first
six colon-terminated fields, while still preserving them in the result
of the grep().

-- 

                        Frank v Waveren
                        fvw@var.cx
                        ICQ# 10074100


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

Date: 14 Aug 2000 11:48:36 GMT
From: mgjv@martien.heliotrope.home (Martien Verbruggen)
Subject: Re: grep() optimisation
Message-Id: <slrn8pfmd2.vgf.mgjv@martien.heliotrope.home>

On 14 Aug 2000 01:40:50 -0500,
	Logan Shaw <logan@cs.utexas.edu> wrote:
> In article <966233370GGX.fvw@var.cx>, fvw <fvw+usenet@var.cx> wrote:
> >Yay, 1 second off, 15 to go. (Don't we all want computation in 0 secs?
> >:-) ).
> 
> That's why I've written a special version of sleep()
> that accepts negative arguments.  Just pass it a -10
> and it returns 10 seconds before you called it.
> 
> Of course, nobody will ever use it, since temporal anomalies
> will lead to buggy programs -- if the function returns 10
> seconds before you called it, then the memory you allocated 5
> seconds ago to store the result of the function call hasn't
> been allocated yet, and that's sure to cause problems.

That's what premalloc is for

RTFM: # man premalloc

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: 14 Aug 2000 12:03:34 GMT
From: mgjv@martien.heliotrope.home (Martien Verbruggen)
Subject: Re: grep() optimisation
Message-Id: <slrn8pfnf9.vgf.mgjv@martien.heliotrope.home>

On Mon, 14 Aug 2000 07:09:52 GMT,
	fvw <fvw+usenet@var.cx> wrote:
> <x73dk8z5q0.fsf@home.sysarch.com> (uri@sysarch.com):
> >post some of the input and search strings.
> All lines consist of n:nn:nn:nn:nn:url:string, with n being a decimal
> digit, url being a http url without the http:// part, and string
> being the title of a tv show (don't ask :-) ).
> The strings in @b are substrings of the title.

If it's really that restrictive:

#!/usr/local/bin/perl -w
use Benchmark;

chomp(@a = <DATA>);
$b = 'of a';

timethese( 1 << 16, {
  re1 => sub{@c=grep(/^([^:]*:){6}.*$b/io, @a);},
  re2 => sub{@c=grep(/^\d:\d\d:\d\d:\d\d:\d\d:[\da-zA-Z.-]*:.*$b/io, @a);},
});

__DATA__
1:23:45:67:89:www.foo.bar.com:Title of a film
1:23:45:67:89:www.foo.bar.com:another title, not a film
1:23:45:67:89:www.foo.bar.com:This shouldn't match
1:23:45:67:89:www.foo.bar.com:this of a should
1:23:45:67:89:www.foo.bar.com:And this doesn't

Benchmark: timing 65536 iterations of re1, re2...
    re1:  6 wallclock secs ( 4.17 usr +  0.01 sys =  4.18 CPU) @
	   15678.47/s (n=65536)
    re2:  3 wallclock secs ( 2.59 usr +  0.00 sys =  2.59 CPU) @ 
       25303.47/s (n=65536)

With 500 elements (@a = (@a) x 100;)

Benchmark: timing 1024 iterations of re1, re2...
    re1:  6 wallclock secs ( 5.67 usr +  0.00 sys =  5.67 CPU) @
       180.60/s (n=1024)
    re2:  4 wallclock secs ( 3.25 usr +  0.00 sys =  3.25 CPU) @ 
       315.08/s (n=1024)

The more specific you are, the faster the regex engine can be.. More or
less.. as a rule of thumb.

If you want to allow underscores and / in the URL, adapt that charcter
class a bit. Maybe a simple .+ would do there. If there is never an
empty field, a + is going to be slightlybetter than a .*.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: Mon, 14 Aug 2000 14:09:38 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: grep() optimisation
Message-Id: <ljmfpsctprlv08t9tct81i323cveunjvn6@4ax.com>

On Mon, 14 Aug 2000 05:35:23 GMT, fvw+usenet@var.cx (fvw) wrote:

> According to the FAQ, the best way to make your code run faster
> is optimize the algorithm, However I can't find any way to
> make it run any faster, I'd appreciate any suggestions the group
> might have:
> 
> I have an array @a, containing ~70 lines. I also have a string @b,
> containing ~50 strings. I want to get an array (@c) containing the 
> lines of @a that match 6 colons (':'), followed by a string from @b 
> (case insensitive). I'm currently doing: 
> 
> $b=join('|', @b);
> @c=grep(/([^:]*:){6}.*($b)/i, @a);
> 
> but since I have to do this several times, it takes quite some time.
> Anybody got any suggestions? TIA.

I'm not sure what you mean by 'string', I interpreted that as 'word'
(which is equally vague :-). My thought was to match the words in the
remainder of the line (after the six colons) against the words from @b.
If this is what you are after, maybe my approach might help (it's more
strict then yours though):

#!/usr/bin/perl -w
use strict;

my @b = qw(word2 line2 LINE4);

my %lookup;
@lookup{ map lc $_ => @b } = (1) x @b;

my @a = <DATA>;

my @c = grep { 
	/^(?:[^:]*:){6}(.*)/;
	$1?@lookup{ split ' ', lc $1 }?$_:undef:undef } @a;

print "$_" for @c;

__DATA__
::::::word1 wjfawe jnfalwei we fjaweiju we fmnwieufnlkjdgjk word2
:::::line2 hjsrdfblsdf sdfhjkdfj gdfhjhj hjksdfg jfh jkasdfl njklasdf
::::::word3 jklasdfjklasdfn fasnjk jklasd asefjkl sertui
::::::Line4 should match

-- 
Good luck,
Abe


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

Date: Mon, 14 Aug 2000 13:06:33 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Help: libs with Latin-1 or Unicode?
Message-Id: <Pine.GHP.4.21.0008141240080.28149-100000@hpplus03.cern.ch>

On Sat, 12 Aug 2000, I wrote:

> If you're dealing with coded character data, then a given file is
> meant to be in one and only one character coding.  If it's utf-8 then
> it can't also be iso-8859-1 and vice versa.

I should have added here that in the special case where the data is in
us-ascii, then you could pretend that it's in utf-8, or in any of the
iso-8859-* codes, or any of various other codes which have us-ascii as
a subset.  But I guess we can all agree that this is a degenerate
case.

> AFAIK all unicode codings are self-identifying, or at least can be
> made so by starting the datastream in a specific way (the coded
> representation of a zero-width non joiner, IIRC?).
                                 ^^^^^^^^^^

This was wrong, sorry.  It's the "zero width no-break space", U+FEFF,
which when used in this capacity is also known as a "byte order mark",
BOM.  When encoded into utf-8 this becomes the three-byte sequence EF
BB BF.

> utf-8 has a built-in consistency check, in as much as each multibyte
> sequence defines its own length.  The probability of an arbitrary
> iso-8859-* file of any size passing this test is miniscule.

As Czyborra remarks in relation to utf-8 benefits:

 + detectability 
     You can detect that you are dealing with UTF-8 input 
     with high probability if you see the UTF-8 signature
     =EF=BB=BF , or if you see valid UTF-8 multibyte
     characters since it is very unlikely that they
     accidentally appear in Latin1 text.

http://czyborra.com/utf/ as I recommended before.

all the best.



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

Date: Mon, 14 Aug 2000 11:00:58 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: how can I optimize a tied hash for speed
Message-Id: <3997d169.3d18$1db@news.op.net>

In article <1efbcgl.1g90i0if6hxtsN%kpreid@attglobal.net>,
Kevin Reid <kpreid@attglobal.net> wrote:
>> foreach (keys %h) {do some simple sorting and printing}
>
>That builds a list of every key in the hash, then iterates over it. It
>is much more efficient to use while and each():

Probably not.   each() is usually slower than keys() because you have
to dispatch more opcodes.  keys() just dumps the key list on the stack
and the code to do this is written in C.

You use each() as a *space* optimization.  It takes less memory but
more time.  When the hash is very large, each() runs faster because it
doesn't make your program thrash.  That is unlikely to be occurring in
this case.




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

Date: Mon, 14 Aug 2000 12:23:09 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: How to change Popup frame's URL
Message-Id: <NwRl5.123$DT4.3606324@nnrp2.clara.net>

In article <rZNl5.69$q57.9251@read2.inet.fi>, "Pekka Siiskonen" <remove.NoSpam.from.@e-mail.address> wrote:
>In Windows enviroment (w. Outlook) one can send a html page displayed on
>browser by clicking the browser (explorer) window with "file/send/page by
>e-mail...".

I would imagine you can do this with an MAPI compliant e-mail client, but 
this is comp.lang.*perl*.misc

>Is there any other way to control the URL of the popup window/frame else
>than with a hot link on the first page (instead of submit button)?

*sigh* Please, don't do this. This question has *nothing* to do with Perl.  
The fact that the program producing this HTML is written in Perl is 
entirely irrelevant to this question. The problem lies with your browser - 
to get the source it re-requests the information to display it in the source 
viewer (notepad in IE4, in-built in NS4). This request for the information 
doesn't send any variables which is good because if you'd just used a script 
to ... I dunno "delete the last mail in my account" if you resubmit the page 
with the same variables, you'll again delete the last mail in your account 
 .

If you want to seperate these then you can play with your code so it calls 
your script under another name, even just take the HTML and put it in a 
 .html and have the CGI script called by that.

I would suggest saving the source and using that, or pasting what you see on 
screen. If that doesn't satisfy you, try asking in more relevant group (and 
one that cares) like one of microsoft.publich.inetexplorer.ie4.*

*not impressed*
Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Mon, 14 Aug 2000 11:54:15 GMT
From: "Pierre" <pir9@hotmail.com>
Subject: How to execute perlscript from html site
Message-Id: <H5Rl5.95$Hk.7766@nntp1.chello.se>

Hi All!
I have a simple question.
How can I start perlscript from htm site?

Hope anybody can answer my question, Pierre




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

Date: Mon, 14 Aug 2000 14:51:47 +0200
From: "Marr, Lincoln [HOOF:4713:EXCH]" <lincolnmarr@europem01.nt.com>
Subject: Re: How to execute perlscript from html site
Message-Id: <3997EB63.88128260@europem01.nt.com>

That's not a perl question. 
Just do <A HREF="http://myserver.com/script.cgi">script name</A>.
Make sure the perl script is executable.

Pierre wrote:
> 
> Hi All!
> I have a simple question.
> How can I start perlscript from htm site?
> 
> Hope anybody can answer my question, Pierre


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

Date: Mon, 14 Aug 2000 11:29:47 GMT
From: Govindaraj <umungo01@shafika.vetri.com>
Subject: Linking the Page Number in Index Section
Message-Id: <spfm1b77n4t36@corp.supernews.com>

Hello,

I am in the process of Linking the Page Number in the Index Section(Section 
which is present at the end of the book).

for eg.
    Testing, 3 (testing purpse)
    
    This should be converted to:
    Testing <JL>3</JL> (testing purpse)

I would like to write the Perl Programme in a Generic 
Format.  There is a lot of cases like below:
    Testing, 3, 4, 5.
    testing
    Testing 1992, 3 (here 1992 should not be linked)
In the above case, number 1992 should not be linked....any pointer or help 
to capture all the link in the Index Section.

Thanks,
Govindaraj

--
Posted via CNET Help.com
http://www.help.com/


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

Date: Mon, 14 Aug 2000 12:11:46 GMT
From: gregosse2409@my-deja.com
Subject: Message board code
Message-Id: <8n8nm0$ort$1@nnrp1.deja.com>

I will soon start to developp a message board (forum) in Perl.
It will only use text files (no database).
But I'm sure that some of you have already done such things...

All URLs, sources and advices... are welcome !

Thanks,
Greg


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


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

Date: 14 Aug 2000 12:15:28 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Negativity in Newsgroup -- Solution
Message-Id: <8n8nt0$er0$1@lublin.zrz.tu-berlin.de>

Steve Leibel <stevel@bluetuna.com> wrote in comp.lang.perl.misc:
>In article <3997421D.94F8C927@attglobal.net>, care227@attglobal.net wrote:
>> "Randal L. Schwartz" wrote:

[...]
 
>> >   3) recognize that this is not a help desk: it's volunteers that are doing
>> >      this for free because they *want* to help
>
>Not to mention an incorrect spelling of "its" in item #3.  "It's" is a
>contraction of "it is," which Randall would have known if he had bothered
>to read the Oxford English Dictionary in its entirety before posting.

Oh, and if you had bothered to read the post you are replying to in its
entirety, you might have noticed that Randal's name contains only one "l",
and that his use of "it's" is perfectly valid.

Anno


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

Date: Mon, 14 Aug 2000 11:18:37 GMT
From: psb154@my-deja.com
Subject: Net::SMTP is this package available for Win32 PERL?
Message-Id: <8n8kib$mr3$1@nnrp1.deja.com>

Hello,

Can someone point me at an ftp/http site where I can download the
package:
net:smtp

for Win32 PERL please.

Thank you for your help
--Paul Butterfield.


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


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

Date: Mon, 14 Aug 2000 11:23:52 +0100
From: "George Crane" <georgec@webleicester.co.uk>
Subject: Newbie post problem.
Message-Id: <%GPl5.1218$nX5.36480@news1-hme0>

Hi,

I have written a perl script that PGP encodes a message from a form and
sends it all from a secure server. Now all I need to do is to return to the
non secure area of the site with a little information - i.e. that the
message was successfully sent and some of the information gathered from the
form.

I can do this by using the get method under the "location:" thingy and add
all my information as a querystring something like:

print "location: backtotheserver.htm?allmyinformation=here"

However, if I do that Im gonna get an ugly string across the location field
in the browser. Ideally, I want to use the Post method but I cant figure out
how to return to a page on the normal server using post and add all the
relevant headers for field content.

Can anyone help out??

Thanks in advance




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

Date: Mon, 14 Aug 2000 12:52:14 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: Newbie post problem.
Message-Id: <2YRl5.124$DT4.3607755@nnrp2.clara.net>

In article <%GPl5.1218$nX5.36480@news1-hme0>, "George Crane" <georgec@webleicester.co.uk> wrote:
>However, if I do that Im gonna get an ugly string across the location field
>in the browser. Ideally, I want to use the Post method but I cant figure out

You can't tell the browser how to send data and in theory it matters little 
to either end which method is used, except that URL's are *supposed* to have 
a maximum length (256characters?). Also what you're trying to do is tell the 
browser where to find the resource at its new location, not resubmit the 
information .. I dunno its all confusing but you can't afaik :)

Anyway, if you don't want to see that stuff the best I can suggest is 
Cookies ;) You can set the time out for say .. 10 seconds and use that to 
store the data and call your script without a querystring. 

See perldoc CGI::Cookie for details for this stuff.

Alternatively (and equally as crap - this one depends upon your server:) try 
exploiting the PATH_INFO - path information included after the name of the 
script you're trying to access.

Apache versions > 1.1.1 set these environmental variables so that:
 "http://$SERVER_NAME:$SERVER_PORT$SCRIPT_NAME$PATH_INFO" will always be an
 accessible URL that points to the current script,"

To dig them out with Perl, just use:

  $ENV{SCRIPT_NAME}  and $ENV{PATH_INFO}
or 
  use Env;
  $SCRIPT_NAME and $PATH_INFO

So you can just play with something like:
  my($id);
  if($ENV{PATH_INFO} =~ /^([A-Z0-9]+)$/){
    $id = $1;  # now untained .. (but add extra checks)
    if( -e "$pgpsigsdir/$db" &&                 # it exists and
      ((-M "$pgpsigsdir/$db")*3600*24) < 600 ){ # created <10 mins ago

      ...
    }
  }

Security is left up to you.

Col.  


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Mon, 14 Aug 2000 12:00:28 +0100
From: "Craig Pugsley" <craig.pugsley@mimesweeper.com>
Subject: Re: Perl code for a newbie!!
Message-Id: <gjQl5.4454$pR4.88801@news6-win.server.ntlworld.com>

I share your sentiments exactly. One of the major things I've found while
exploring the <delights> of the more tecky side of the internet communities,
is that everyone knows what they are talking about. Or are too arrogant to
admit they don't know something. They then make something up that covers
their tracks, but only serves to put the solution off-course much further.
The people who do know everything, expect everyone else too. WRONG. For
goodness sake, get some savvy on human interaction and learn some social
skills. Not everyone is hovering around the same level of demi-god status
they seem to thing they exist on...

(sorry! Rant over)

CraigP


"Keith Calvert Ivey" <kcivey@cpcug.org> wrote in message
news:39975e65.4586589@news.newsguy.com...
> Bart Lateur <bart.lateur@skynet.be> wrote:
> >Larry Rosler wrote:
> >
> >>>     delete ($file[$linenum]);
> >>
> >>It took half a dozen subsequent posts before this blatant error was
> >>revealed.
> >
> >Have you seen the quote from perlfunc posted by Abe Timmerman?
> >Apparently, those Perl implementing geeks keep adding new stuf, and
> >aren't telling anyone.
>
> I'm glad I wasn't the only one bitten by that.  I still think
> that giving bleeding-edge code to a newbie is cruel, especially
> when there's a simple alternative -- splice() -- that's likely
> to actually work on the newbie's system.  Perl 5.6 is still new,
> and code that requires it should be clearly indicated.
>
> --
> Keith C. Ivey <kcivey@cpcug.org>
> Washington, DC




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

Date: Mon, 14 Aug 2000 13:13:21 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Perl code for a newbie!!
Message-Id: <Pine.GHP.4.21.0008141309030.28149-100000@hpplus03.cern.ch>

On Mon, 14 Aug 2000, Craig Pugsley hung upside-down from a news
server and blurted out to the foregathered multitude:

> I share your sentiments exactly.

And then quoted three different people who had been holding a
discussion on a particular technical detail.

It's hard to see how one can hold all three points of view
simultaneously.  Maybe if you'd learn to quote...?

-- 

      A patent application requires an implementation, 
      which is impossible due to the lack of sufficently 
      dense material to make one that would work.
       - Glenn Randers-Pehrson discussing specification for a clue-stick




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

Date: Mon, 14 Aug 2000 12:54:53 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: Perl for Palm?
Message-Id: <x_Rl5.125$DT4.3607797@nnrp2.clara.net>

In article <PrKl5.78890$6y5.52226580@news2.rdc2.tx.home.com>, "Thomas" <mnysurf@home.comREMOVE> wrote:
>Can Perl be run on the Palm OS?

No one has ported it there yet:

http://www.cpan.org/ports/index.html#none

Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Mon, 14 Aug 2000 15:17:13 +0300
From: Jonne Viljanen <Jonne.Viljanen@helsinki.fi>
Subject: rand() not random at all
Message-Id: <3997E349.938F9F88@remove_this_from_address.helsinki.fi>

Hi,

I'm trying to get a simple random number to specify a filename, but
whenever the script is run, I always get the same "random" number
(AUG3VRM6) as an output. What could be wrong?

---clip

#create a random name having 8 characters
my @chars = ( 'A'..'Z', 0..9 );
my $len = 8 || shift;
my $random_name   = '';

$random_name .= $chars[int rand(@chars)] while length $random_name <
$len;

#open the file for writing
open(MAILFILE, ">sys:/smtpmail/$random_name.101");


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

Date: Mon, 14 Aug 2000 14:48:33 +0200
From: "Marr, Lincoln [HOOF:4713:EXCH]" <lincolnmarr@europem01.nt.com>
Subject: Re: rand() not random at all
Message-Id: <3997EAA1.7C1DEE4@europem01.nt.com>

See
http://www.perl.com/pub/doc/manual/html/pod/perlfaq4.html#Why_aren_t_my_random_numbers_ran

for a description about this and links to other solutions.

Jonne Viljanen wrote:
> 
> Hi,
> 
> I'm trying to get a simple random number to specify a filename, but
> whenever the script is run, I always get the same "random" number
> (AUG3VRM6) as an output. What could be wrong?
> 
> ---clip
> 
> #create a random name having 8 characters
> my @chars = ( 'A'..'Z', 0..9 );
> my $len = 8 || shift;
> my $random_name   = '';
> 
> $random_name .= $chars[int rand(@chars)] while length $random_name <
> $len;
> 
> #open the file for writing
> open(MAILFILE, ">sys:/smtpmail/$random_name.101");


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

Date: Mon, 14 Aug 2000 10:56:11 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: set variable to results of regex
Message-Id: <3997d04a.3cfd$32d@news.op.net>

In article <057c3986.d349978f@usw-ex0104-028.remarq.com>,
glued2  <glued2NOglSPAM@hotmail.com.invalid> wrote:
>Admitted perl novice here...
>
>I have a reg exp that extracts a string from between two
>matching patterns when reading a file .... it works, I can print
>it:
>
>while (<SF>){
>	print if /$STARTPATTERN/ .. /$ENDPATTERN/ ;
>}
>
>Instead of printing the results (to the screen in this case;
>it's a cgi script), I want to set a variable to equal the string
>in between the patterns....

$var = '';
while (<SF>){
	$var .= $_ if /$STARTPATTERN/ .. /$ENDPATTERN/ ;
}

I would have mailed this, but I don't understand what your email
address is.



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

Date: Mon, 14 Aug 2000 14:44:32 +0200
From: "Marr, Lincoln [HOOF:4713:EXCH]" <lincolnmarr@europem01.nt.com>
Subject: Substituting newlines for HTML equivalent
Message-Id: <3997E9B0.1C8B5C6A@europem01.nt.com>

I have a textarea in my web form, and when submitted the form puts the
info in a pipe-delimited text file, which I later split on pipes and
newlines. The problem is, if a user hits the 'enter' key in the textarea
then the file gets a whole bunch of newlines in it, which disrupt the
script pretty badly.
I was thinking of using something like:

$field =~ s/\n/<BR>/g

But the thing is, I want one newline to be replaced with <BR> but 2
consecutive newlines to be replaced with <P>. Is this possible? Also are
there any other characters I need to watch out for when letting people
enter things into a textarea (eg dollar symbols, ampersands etc)?




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

Date: Mon, 14 Aug 2000 13:27:26 +0100
From: "Marr, Lincoln [HOOF:4713:EXCH]" <lincolnmarr@europem01.nt.com>
Subject: Re: Where can I find Basic Perl Definitions?
Message-Id: <3997E5AD.172EF4DE@europem01.nt.com>

Thanks very much guys....



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

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


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