[17650] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5070 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 9 06:05:31 2000

Date: Sat, 9 Dec 2000 03:05:10 -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: <976359909-v9-i5070@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 9 Dec 2000     Volume: 9 Number: 5070

Today's topics:
    Re: "open" and file cache (David Efflandt)
    Re: "open" and file cache (Martien Verbruggen)
    Re: ($fastest) ? "perl_on_Linux" : "perl_on_Windows" theredviper@my-deja.com
    Re: Algorithm::Diff -- why does diff() return LOLOL ins (Mark-Jason Dominus)
    Re: Algorithm::Diff -- why does diff() return LOLOL ins (Mark-Jason Dominus)
    Re: Anything wrong with this code? (David Efflandt)
    Re: career advice needed (language? platform?) (Chris Fedde)
        CGI und Perl-Spezialisten gegen Bezahlung gesucht (Beatforge)
    Re: count number of occurrences in string <lincmad001@telecom-digest.zzn.com>
    Re: count number of occurrences in string (Tad McClellan)
    Re: count number of occurrences in string <lincmad001@telecom-digest.zzn.com>
    Re: dynamic require & new on variable package (Chris Fedde)
    Re: eval() performance (Tad McClellan)
    Re: eval() performance <spam@klamath.dyndns.org>
    Re: eval() performance (Mark-Jason Dominus)
    Re: eval() performance (Mark-Jason Dominus)
    Re: eval() performance (Daniel Chetlin)
    Re: FAQ 4.57:   How do I sort a hash (optionally by val <bkennedy99@home.com>
    Re: FAQ 4.57:   How do I sort a hash (optionally by val (Steven Smolinski)
    Re: FAQ 4.57:   How do I sort a hash (optionally by val <bkennedy99@home.com>
    Re: File writing problem (Tad McClellan)
    Re: HELP PLEASE! (David Efflandt)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 9 Dec 2000 10:00:27 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: "open" and file cache
Message-Id: <slrn9340l5.3l5.efflandt@efflandt.xnet.com>

On Wed, 6 Dec 2000 21:33:14 +0100, rs232 <rs232@kerkerker.de> wrote:
>Hi,
>
>I noticed the following symptom under Linux Redhat 7.0:
>
>My perlscript reads every 5 seconds a file
>If I delete this file it reads it anyway.
>
>Only if I restart the script it notices that the file doesn't extists.

I was going to ask if you close the file before rereading it, because once
you open a file you still have access to the contents, even if deleted by
another process, since the actual data is not deleted, just the directory
listing.  But when I got to the end, I realized you are remotely reading a
file from a totally different OS and that is a whole different ball of
worms.

>I want to update the file through another program. But if the perl script
>doesn't check the existenz of the file how can it read the file actual
>contents ?
>
>My config:
>Linux Redhat 7.0
>The File which should be read is on a Windows NT Server (mounted via
>mount -t smbfs....)
>
>Probably this has nothing do with perl rather than with the linux file cache
>?

You are probably half right, it has nothing to do with Perl, but is
probably a fluke of that other OS and its smb communications.  If you ran
the script on a Win box accessing the remote file, you might experience
the same thing.  There is a time lag (as much as 15 minutes) involved in
remote updates.  For example after people at work shut down their Win
boxes and go home, their boxes still show up in Network Neighborhood for
some time after that.

A somewhat related example is that when I had trouble getting Word .doc
files to download at all from a IIS server (they would just hang), I tried
deleting one of those files from ftp and it refused to go away when I did
a dir listing.  Then eventually (maybe when the hung download finally
died) the file suddenly disappeared.  But that donated web host is the
extent of my experience with NT, so I do not know how its file system
works.

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Sat, 9 Dec 2000 22:06:11 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: "open" and file cache
Message-Id: <slrn9344h3.20m.mgjv@martien.heliotrope.home>

On Sat, 09 Dec 2000 03:25:33 GMT,
	Bob Walton <bwalton@rochester.rr.com> wrote:
> rs232 wrote:
> ...
>> 
>> My config:
>> Linux Redhat 7.0
>> The File which should be read is on a Windows NT Server (mounted via
>> mount -t smbfs....)
>
>                                            And it doesn't really care if
> the file is on a foreign file system.

All of what you wrote is true, but this is maybe not entirely complete.
For mounted file systems, the unix kernel and its I/O operations don't
care that it is on a remote system. However, the various file systems
that can be mounted, and the various drivers do make a difference.
Whether a file system is mounted directly as ufs, e2fs, or vxfs makes a
difference in the behaviour. From a high level like this, you hardly
ever wil notice. However, when a file system is mounted via NFS or
smbfs, there are definitely differences in behaviour, and one should
take note of those when relying on behaviour that works on a locally
mounted unix-type file system. Locking is one of the big differences. If
your NFS client and daemon are implemented in user space, as opposed to
kernel space, locking may not work atomically at all. If your remote
file system lives on a box that has mandatory locking, then you might
have to deal with those issues on your mounted file system as well. If
the protocol in use has lags and local caching issues (as smbfs does)
you need to be aware of these too.

None of these questions should be answered in a Perl group [1], or even
in an OS group. To find out how exactly smbfs works in this respect, ask
in comp.protocols.smb.

Martien

[1] and if they are, you should verify them. This is not the
athoritative place to get information on samba.
-- 
Martien Verbruggen              | 
Interactive Media Division      | That's funny, that plane's dustin'
Commercial Dynamics Pty. Ltd.   | crops where there ain't no crops.
NSW, Australia                  | 


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

Date: Sat, 09 Dec 2000 09:58:18 GMT
From: theredviper@my-deja.com
Subject: Re: ($fastest) ? "perl_on_Linux" : "perl_on_Windows"
Message-Id: <90svnp$74j$1@nnrp1.deja.com>

In article <slrn932e4b.1v7.tim@degree.ath.cx>,
  tim@degree.ath.cx (Tim Hammerquist) wrote:
> theredviper@my-deja.com <theredviper@my-deja.com> wrote:
> > This is sure to generate flame, but I have good intentions. <evil
> > grin>.  I have just a general question that has probably already
been
> > answered 100 times.   I have my opinion on which is fastest (you
> > probably guessed), but is there one of these that is generally
faster on
> > a certain platform with similiar hardware configurations or is it
> > primarily dependant on the type of processes being done?  Just
curious
> > as to what other people have noticed.  And yes I realize that my
> > description of the operating systems is vague.  tia.
>
> Well, "redviper", not only is your question vague with way too many
> variables, but your logic in your subject is faulty.
>

I agree that I was reaching on the subject, but it was merely a code
snippet to suggest that if $fastest was true then the result would be
"perl_on_Linux".  My apologies; I was trying to keep the subject short,
but at the same time convey my opinion and give an idea of what the
question was about.

$fastest = "1";
print (($fastest)?"perl_on_Linux":"perl_on_Windows");



> In any case: Linux is more stable, for organized, and takes better
> advantage of the 32 bit processor instructions that Windoze ever has.
> (Mandrake Linux 6.0-7.2)  Add to that the fact that Perl originated on
> the Unix platforms;  More code is required in the Win32 ports of Perl
to
> interface Perl's unix-centric methods to Win32's backwards methods,
> which means it takes slightly more time to do too many things.  This
> difference may be insignificant in most cases, but it can add up in
> large applications.
>
> So, in my admittedly biased opinion:
>
> 	$perl->speed('linux') > $perl->speed('win32')
>
>

Thanks for the response.  I use perl on Windows NT and Redhat Linux 6.2
at work and I was surprised by the better performance on Linux than NT
although the NT machine was much much beefier.

-theredviper


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


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

Date: Sat, 09 Dec 2000 07:22:10 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Algorithm::Diff -- why does diff() return LOLOL instead of LOL?
Message-Id: <3a31dda1.5c7c$7@news.op.net>

In article <iowa88_song88.remove_eights-0812001312100001@121.salt-lake-city-08-09rs.ut.dial-access.att.net>,
Weston Cann <iowa88_song88.remove_eights@hotmail.com> wrote:
>I'm looking at the documentation about Algorithm::Diff, and I don't
>quite get why the list returned from diff is a list of lists of lists,
>rather than simply a list of lists. 

1. Because that is closest to the way the standard 'diff' command does it.

2. Because it corresponds most naturally to our well-understood
   notions of what it means to edit a document:  Each 'chunk' in the
   output value corresponds to a single addition, deletion, or change
   of a set of contiguous lines.  

   In some sense, a document that has simply had a long chunk of text
   tacked onto the end has been changed less than one that has
   suffered many small changes and rearrangements.  The return from
   Algorithm::Diff reflects this: By counting the chunks, you can get
   a sense of the degree of difference between the two inputs that may
   more meaningful than meaningful than what you would get by just
   counting the lines.

3. The existing behavior is more useful than what you suggest.  It's
   trivial to flatten the existing output of Algorithm::Diff into a
   simple list.  But this operation throws away information, so
   reversing it is mumch more complicated.  It's foolish to build a
   module that throws away possibly useful information; it's better to
   let the programmer throw it away if that is what is wanted.

>why couldn't we simply have:

We could, and we can.  With the existing interface, you can have what
you want very simply:

        sub flat_diff {
          my @flat;
          for my $chunk (diff(@_)) {
            push @flat, @$chunk;
          }
          @flat;
        }
          
But if I had done it your way to begin with, someone who wanted it the
other way would have a lot of trouble to get it.



-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Sat, 09 Dec 2000 07:36:32 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Algorithm::Diff -- why does diff() return LOLOL instead of LOL?
Message-Id: <3a31e100.5d00$b2@news.op.net>

In article <976317794.25617@itz.pp.sci.fi>,
Ilmari Karonen  <usenet11299@itz.pp.sci.fi> wrote:
>In article <iowa88_song88.remove_eights-0812001312100001@121.salt-lake-city-08-09rs.ut.dial-access.att.net>, Weston Cann wrote:
>>I'm looking at the documentation about Algorithm::Diff, and I don't
>>quite get why the list returned from diff is a list of lists of lists,
>>rather than simply a list of lists. For the example:
>
>Presumably because the original author (MJD) wanted it that way.

I hope this doesn't sound nasty, but I think that is a very poor
answer, because it answers nothing:  "Why did MJD want it that way, then?"

Software design is an engineering discipline.  We make design
tradeoffs and balance factors such as time and memory efficiency,
familiarity, convenience, intuitiveness, flexibility, and so on.
Sometimes we make base our engineering decisions on whims, but more
often there is a technical reason, as was the case here.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Sat, 9 Dec 2000 10:13:23 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Anything wrong with this code?
Message-Id: <slrn9341dd.3l5.efflandt@efflandt.xnet.com>

On 09 Dec 2000 04:25:30 GMT, Fryar386 <fryar386@aol.com> wrote:
>My server keeps giving me errors for this code, all it says is premature end. 
>I don't see anything wrong with it, do you?

One thing wrong is that you will never see your 'die' statements unless
you have access to the server logs.  If you want to see them in your
browser, put this near the beginning of your script:

use CGI::Carp qw(fatalsToBrowser);

That may not catch fatal precompile errors, but at least tells you why you
cannot open files.  But to know that, you have to include the variable
$! in your die string.

The second problem is that you appear to be using the obsolete cgi-lib.pl
and I would suggest learning the current CGI module instead.  But whatever
works for you (does it?).  To learn more about CGI.pm, on any system with
Perl5 type:  perldoc CGI

>print &PrintHeader;
>open FILE, ">> /serverfiles/test.txt"  
>or die "Error, Please contact Fryar386@aol.com\n";
>flock FILE, 2    
>or die "Couldn't acquire an exclusive lock on test.txt: $!\n";
>print FILE <<ENDOFTEXT;
><P>
>Username: $input{username}
>Password: $input{password}
>E-mail: $input{e-mail}
>Attacks: $input{basic1}
>Main Goal: $input{main_goal}
>Planet: $planet
>AIM: $input{aim}
>Race: $input{race}
>Speed: $speed
>Defence: $defence
>Attack: $attack
>KI: $KI
>Health: $health
>MaxHealth: $maxhealth
>Intellegence: $intellegence
>Peri(money): $peri
>Power Level: $powerlevel
>ENDOFTEXT
>close FILE    
>or warn "test.txt didn't close nicely: $!\n";
>
>
>All I know is that the error is in those lines of programming
>
>
>
>Thanks
>


-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Sat, 09 Dec 2000 05:55:26 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: career advice needed (language? platform?)
Message-Id: <iPjY5.81$B9.180112896@news.frii.net>

In article <90s6pe$lh0$1@nnrp1.deja.com>,  <joemorris101@my-deja.com> wrote:
>
>So, my question is, should I endeavor, over the 5-week Christmas break,
>to learn one of the scripting languages (which language?????).

Yes. (lots of them)

>
>What should I concentrate on over the next 6 months or so that gives
>the best chance at a job?
>

To quote Joseph Campbell: "Follow your bliss." 

chris

-- 
    This space intentionally left blank


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

Date: Sat, 09 Dec 2000 09:13:52 GMT
From: beatforge@hotmail.com (Beatforge)
Subject: CGI und Perl-Spezialisten gegen Bezahlung gesucht
Message-Id: <3a33f7b4.390907565@news.claranews.com>

Hallo, ich suche dringenst jemanden, der gegen Bezahlung ein paar
Seiten implementieren kann.

1. Eine Html-Seite, die auch lokal auf dem Rechner gespeichert wird,
und mit der man registrationslos Emails verschicken kann.
Die Emails haben dann einen bestimmten festen Absender und man kann
auch Attachments damit verschicken.
Auch einzutragen sind: Betreff, Body und variabler Werbefooter.
Das dürfte ja nicht so schwierig sein??

Auch wünschenswert wären leicht zu administrierbare Foren,
Gästebücher,
Mailempfehlungen (mail this page to a friend usw.)

Das ganze wäre für das Projekt Null Grad Celsius.

Hier die URL: www.nullgradcelsius.de 

Angebote bitte nur per Email an elmar@nullgradcelsius.de

P.S. Sorry wegen dem Absendernamen dieser MSG.


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

Date: Fri, 08 Dec 2000 21:52:11 -0800
From: Linc Madison <lincmad001@telecom-digest.zzn.com>
Subject: Re: count number of occurrences in string
Message-Id: <081220002152110268%lincmad001@telecom-digest.zzn.com>

In article <1r4s0ed55p.fsf@video.bsd.uchicago.edu>, John Hunter
<jdhunter@nitace.bsd.uchicago.edu> wrote:

> >>>>> "Tad" == Tad McClellan <tadmc@metronet.com> writes:
> 
>     Tad> John Hunter <jdhunter@nitace.bsd.uchicago.edu> wrote:
>     >> What is the best way to count the number of times a specific
>     >> character occurs in a string.
> 
> 
>     Tad>    $count = $addr =~ tr/@//;
> 
> Perfect, thanks.

Actually,

   $count = $addr =~ tr/@/@/;

will achieve the same effect, but not alter the string.


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

Date: Sat, 9 Dec 2000 00:28:19 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: count number of occurrences in string
Message-Id: <slrn933gnj.32p.tadmc@magna.metronet.com>

Linc Madison <lincmad001@telecom-digest.zzn.com> wrote:
>In article <1r4s0ed55p.fsf@video.bsd.uchicago.edu>, John Hunter
><jdhunter@nitace.bsd.uchicago.edu> wrote:
>> >>>>> "Tad" == Tad McClellan <tadmc@metronet.com> writes:
>>     Tad> John Hunter <jdhunter@nitace.bsd.uchicago.edu> wrote:

>>     >> What is the best way to count the number of times a specific
>>     >> character occurs in a string.
>> 
>>     Tad>    $count = $addr =~ tr/@//;
>> 
>> Perfect, thanks.
>
>Actually,
>
>   $count = $addr =~ tr/@/@/;
>
>will achieve the same effect, but not alter the string.


Actually actually,

   $count = $addr =~ tr/@//;

does not alter the string either  :-)


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


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

Date: Sat, 09 Dec 2000 00:46:43 -0800
From: Linc Madison <lincmad001@telecom-digest.zzn.com>
Subject: Re: count number of occurrences in string
Message-Id: <091220000046433271%lincmad001@telecom-digest.zzn.com>

In article <081220002152110268%lincmad001@telecom-digest.zzn.com>, Linc
Madison <lincmad001@telecom-digest.zzn.com> wrote:

> In article <1r4s0ed55p.fsf@video.bsd.uchicago.edu>, John Hunter
> <jdhunter@nitace.bsd.uchicago.edu> wrote:
> 
> > >>>>> "Tad" == Tad McClellan <tadmc@metronet.com> writes:
> > 
> >     Tad> John Hunter <jdhunter@nitace.bsd.uchicago.edu> wrote:
> >     >> What is the best way to count the number of times a specific
> >     >> character occurs in a string.
> > 
> > 
> >     Tad>    $count = $addr =~ tr/@//;
> > 
> > Perfect, thanks.
> 
> Actually,
> 
>    $count = $addr =~ tr/@/@/;
> 
> will achieve the same effect, but not alter the string.

OOPS. I suppose I should read the documentation first.

tr/SEARCHLIST/REPLACEMENTLIST/cds
If the REPLACEMENTLIST is null, the SEARCHLIST is replicated.

In other words, tr/@// and tr/@/@/ do exactly the same thing.


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

Date: Sat, 09 Dec 2000 06:10:25 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: dynamic require & new on variable package
Message-Id: <l1kY5.83$B9.188722176@news.frii.net>

In article <90rr7t$lj9$1@bcrkh13.ca.nortel.com>,
simonmcc <simonmcc@nospam.nortelnetworks.com> wrote:
>So I've tried deja, and camel etc, and I can get answers to parts of my
>problem, but not all.
>
>I need to instantiate an object, but I don't know what it is (i.e. it is in
>a variable).
>
[...]
>
>also is this bad practice? (I need to do it because I use a generic piece of
>code to instantiate many drivers)
>
>any help is appreciated
>
>simon.
>
>

This seems to be workiing for me

    $a = "Net::FTP";
    eval "use $a;";
    $x = $a->new('ftp.uu.net');
    print "$x\n";


I don't see anything wrong with using something like this.  It
looks a like a Perl implementation of the abstract factory pattern.
I suppose that the "eval police" might point out that you might
not want to take a class name from user input in some cases.

Good Luck
chris
-- 
    This space intentionally left blank


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

Date: Fri, 8 Dec 2000 20:26:02 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: eval() performance
Message-Id: <slrn9332ha.2es.tadmc@magna.metronet.com>

Neil Conway <spam@klamath.dyndns.org> wrote:

>Would this improve performance?


Write a benchmark and see.

use Benchmark;


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


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

Date: Sat, 09 Dec 2000 06:13:52 GMT
From: Neil Conway <spam@klamath.dyndns.org>
Subject: Re: eval() performance
Message-Id: <3A31CD9F.8040301@klamath.dyndns.org>

Tad McClellan wrote:

> Neil Conway <spam@klamath.dyndns.org> wrote:
>> Would this improve performance?
> 
> Write a benchmark and see.

Well alright :-)

I didn't want to bother benchmarking if someone knew the answer -- 
because it's difficult to simulate the environment (CGI, lots of 
different Perl scripts, etc) properly. But here goes:

#!/usr/bin/perl -w
#test.pl
use strict;
use Benchmark;
undef $/;
my $code;
timethese(8000, {
     'Slow Eval' => sub {open(INPUT, 'code.pl');$code = 
<INPUT>;close(INPUT);eval $code;},
     'Fast Eval' => sub {open(INPUT, 'code.pl');$code = 
<INPUT>;close(INPUT);eval {$code;};}
});
###########################
#!/usr/bin/perl -w
#code.pl
use strict;
my $str = 'hello world';
$str =~ tr/o/i/;
for (1..3) {$str .= $str;}
###########################

Results:

Benchmark: timing 8000 iterations of Fast Eval, Slow Eval...
  Fast Eval:  0 wallclock secs ( 0.30 usr +  0.13 sys =  0.43 CPU)
  Slow Eval:  6 wallclock secs ( 4.98 usr +  0.42 sys =  5.40 CPU)

So apparently an eval block is significantly faster than calling eval() 
on a scalar.

The important question is: is this benchmark accurate? Does it correctly 
simulate the necessary parts of the environment? Does it correlate with 
the general experience people have?

(I can't benchmark the actual application because I can't install it 
locally. Long story...)

Thanks,

Neil



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

Date: Sat, 09 Dec 2000 07:44:41 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: eval() performance
Message-Id: <3a31e2e8.5d54$7d@news.op.net>
Keywords: Fourier, Japan, oxygen, pectoralis

In article <3A317EF2.3000509@klamath.dyndns.org>,
Neil Conway  <spam@klamath.dyndns.org> wrote:
>eval $code;
>if ($@) {
>     #handle errors
>}
>
>My question is: how would you improve this? My first thought was to use 
>an eval block - i.e.
>
>eval {$code;};
>if ($@) {
>     #handle errors
>}
>
>Would this improve performance?

Yes, but since it doesn't do the same thing, or anything even close to
it, changing it probably won't help you with your real problem.  :)


This:
        eval {$code}

is analogous to

        eval '$code'

not to
        eval "$code"

Big difference.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Sat, 09 Dec 2000 07:47:39 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: eval() performance
Message-Id: <3a31e39a.5d6c$2a7@news.op.net>
Keywords: barnacle, debacle, jump, torsion

In article <3A31CD9F.8040301@klamath.dyndns.org>,
Neil Conway  <spam@klamath.dyndns.org> wrote:
>Benchmark: timing 8000 iterations of Fast Eval, Slow Eval...
>  Fast Eval:  0 wallclock secs ( 0.30 usr +  0.13 sys =  0.43 CPU)
>  Slow Eval:  6 wallclock secs ( 4.98 usr +  0.42 sys =  5.40 CPU)
>
>So apparently an eval block is significantly faster than calling eval() 
>on a scalar.

That's because the block version you wrote doesn't actually run the
code.  it just looks up the value of $code and returns that.

Do correctness testing *before* performance testing.  :)
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 9 Dec 2000 10:15:55 GMT
From: daniel@chetlin.com (Daniel Chetlin)
Subject: Re: eval() performance
Message-Id: <90t0os01uf1@news2.newsguy.com>

On Sat, 09 Dec 2000 07:44:41 GMT,
 Mark-Jason Dominus <mjd@plover.com> wrote:
[snip]
>This:
>        eval {$code}
>
>is analogous to
>
>        eval '$code'
>
>not to
>        eval "$code"
>
>Big difference.

`eval BLOCK' and `eval STRING' are still very different things, even
when the string is a constant (as it is when single quoted). While the
two are analagous for the purposes of answering the stated question,
it's important to keep in mind that they are not the same.

Mark knows this, of course, and his point is that in this case the end
result of `eval BLOCK' and `eval STRING' where the string is
non-interpolative are the same, whereas `eval STRING' with an
interpolating string is vastly different. But for others watching, do
remember that the two analagous constructs share no common op and will
be quite different performance-wise.

-dlc


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

Date: Sat, 09 Dec 2000 05:50:25 GMT
From: "Ben Kennedy" <bkennedy99@home.com>
Subject: Re: FAQ 4.57:   How do I sort a hash (optionally by value instead of key)?
Message-Id: <BKjY5.182795$td5.26081632@news1.rdc2.pa.home.com>


"PerlFAQ Server" <faq@denver.pm.org> wrote in message
news:gKfY5.71$B9.170582016@news.frii.net...
> This message is one of several periodic postings to comp.lang.perl.misc
> intended to make it easier for perl programmers to find answers to
> common questions. The core of this message represents an excerpt
> from the documentation provided with every Standard Distribution of
> Perl.

Perhaps I'm being hypersensitive, but is anyone else finding these annoying?
For one thing, they are coming out in the wrong order (4.49, 4.5, 4.50).
For another thing, once a week is fairly standard for thing "Here's the FAQ"
postings, not 14 times a week.  The whole point of a FAQ is to reduce
newgroup clutter, not create it.

--Ben Kennedy




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

Date: Sat, 09 Dec 2000 06:16:03 GMT
From: sjs@yorku.ca (Steven Smolinski)
Subject: Re: FAQ 4.57:   How do I sort a hash (optionally by value instead of key)?
Message-Id: <slrn933na9.1dm.sjs@ragnar.stevens.gulch>

Ben Kennedy <bkennedy99@home.com> wrote:
> 
> "PerlFAQ Server" <faq@denver.pm.org> wrote in message
> news:gKfY5.71$B9.170582016@news.frii.net...
> > This message is one of several periodic postings to comp.lang.perl.misc
> > intended to make it easier for perl programmers to find answers to
> > common questions. The core of this message represents an excerpt
> > from the documentation provided with every Standard Distribution of
> > Perl.
> 
> Perhaps I'm being hypersensitive, but is anyone else finding these annoying?

This is a perfect thing for a scorefile.  See http://slrn.sourceforge.net/

The posts come from the same email address (which address is not used to
post anyhting but these messages).  The subjects all start with "FAQ ".

I find them far easier to score down than the continual stream of questions 
about 500 server errors or server configuration issues.

Steve
-- 
But they all have the same weakness: they're flipping web crud.
	--Tom Christiansen in <3a02e17a@cs.colorado.edu>


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

Date: Sat, 09 Dec 2000 06:43:30 GMT
From: "Ben Kennedy" <bkennedy99@home.com>
Subject: Re: FAQ 4.57:   How do I sort a hash (optionally by value instead of key)?
Message-Id: <mwkY5.182866$td5.26097048@news1.rdc2.pa.home.com>


"Steven Smolinski" <sjs@yorku.ca> wrote in message
news:slrn933na9.1dm.sjs@ragnar.stevens.gulch...
> Ben Kennedy <bkennedy99@home.com> wrote:
> >
> > "PerlFAQ Server" <faq@denver.pm.org> wrote in message
> > news:gKfY5.71$B9.170582016@news.frii.net...
> > > This message is one of several periodic postings to
comp.lang.perl.misc
> > > intended to make it easier for perl programmers to find answers to
> > > common questions. The core of this message represents an excerpt
> > > from the documentation provided with every Standard Distribution of
> > > Perl.
> >
> > Perhaps I'm being hypersensitive, but is anyone else finding these
annoying?
>
> This is a perfect thing for a scorefile.  See http://slrn.sourceforge.net/
>
> The posts come from the same email address (which address is not used to
> post anyhting but these messages).  The subjects all start with "FAQ ".
>
> I find them far easier to score down than the continual stream of
questions
> about 500 server errors or server configuration issues.

Yes, I realize that things like this are easily *plonk*-able, but I try to
avoid that sort of thing, especially in this case where the posts are
well-meaning.  Besides, even though you can't see the clutter doesn't mean
its not still there.  If someone were posting these FAQ tidbits every 5
minutes, everyone would be up in arms - I'm just trying to gauge what is
generally acceptable.

--Ben Kennedy




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

Date: Fri, 8 Dec 2000 23:51:59 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: File writing problem
Message-Id: <slrn933ejf.2vs.tadmc@magna.metronet.com>

Edd <edd@texscene.com> wrote:

>I am a novice in perl programming. 


Welcome to Perl!


>I am trying to learn 


How are you doing that?

From a tutorial? Other book? Website? Reading this newgroup?
(rhetorical questions. Just a list of "some ways" to learn Perl)

Reading the standard docs that come with every perl distribution?

That one is pretty much a required way  :-)

Most especially when you are having problems with Perl.

You can use the 'perldoc' program that comes with perl
to search/read the standard docs. To learn how to use
perldoc:

   perldoc perldoc


>how to write to a
>file. 


Since you seem to have already found out about the open()
function :-), you can read the description of it written by
the very people who write the perl interpreter itself:

   perldoc -f open


>To try it out, I wrote the code below. But it fails to do what I want
>it to do. 


Your code has about a half dozen serious mistakes. Don't be
discouraged by me pointing all of them out.


>The file I want to write to is: ' web1.html' . But it doesn't. 


If you ask perl to tell you why, it will tell you. See below.


>In
>the code below, the first thing I do is to parse a form. This works OK. 


But that code is only for a learning experience, right?

If you are going to use this as a "real CGI program" then
you should be using the CGI.pm module.


>Then
>I set the permissions for web1.html.


Does that one work?

You don't say, but it might.


>Then I check the attributes of the file web1.html. They confirm.


They do?

They don't when I run your code...


>But, when I check if a file which I know doesn't exist
>"nofile.html", I get positive response as well. This really confuses me
>desperately!


If you are having a problem with Perl's file tests, then you
should read the docs about Perl's file tests:

   perldoc -f -e


>When I run the programme, I see no change to the web1.html. I tried
>different paths etc.
>
>Could anybody help please. The code is as below:
>
>
>#!/usr/bin/perl


You should always enable warnings. It would have pointed
out a couple of your mistakes below automatically.

You should also always enable strictures and declare all
of our variables with my().

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



># Below I set the permissions
>if (-e "web1.html") {
      ^^^
      ^^^ a space between those, looks good

>   chmod(0744, "web1.html");
>   print "<P>the permissions changed";
>}
>
>
># Below I write to web1.html
>open (LOG, ">web1.html");


You should always, yes *always*, check the return value from open():

  open (LOG, '>web1.html') || die "could not open 'web1.html'  $!";

Be sure to include the $! special variable in the die message.
If the open() fails, $! will tell you why it failed.


>print LOG "Content-type: text/html\n\n";
>print LOG "<HTML><HEAD><TITLE>Hello Visitor</TITLE></HEAD><BODY>";
>print LOG "</BODY></HTML>";


If you are going to be printing long blocks of text, you should
read up on the "here-doc" quoting method in:

   perldoc perldata


print LOG <<ENDHTML;
Content-type: text/html

<HTML><HEAD><TITLE>Hello Visitor</TITLE></HEAD><BODY></BODY></HTML>
ENDHTML


>close(LOG);
>
># Below I check to see if the atributes of web1.html is OK
>if (-e, web1.html) {
      ^^^
      ^^^ that file test looks different from the first one :-)

Here you are file testing whatever file's name is in the $_
variable (because that is what -e defaults to when you do
not give it an argument.

You have not put a filename (or anything at all) into the
$_ variable.

You should always quote your strings.

You would have gotten warnings here, if you had asked for them...

   if (-e 'web1.html') {


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


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

Date: Sat, 9 Dec 2000 10:34:35 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: HELP PLEASE!
Message-Id: <slrn9342l5.3l5.efflandt@efflandt.xnet.com>

On 09 Dec 2000 04:44:30 GMT, Fryar386 <fryar386@aol.com> wrote:
>Is there anyway to use perl to take out all the _'s @'s $'s and all the symbols
>like that out of a string?

Take peek at 'perldoc perlre' and see if it would be easier to come up
with a regular expression listing "all the symbols like that" (whatever
'that' might be, since I don't see a pattern), or an expression that just
retains what you want to keep.

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

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


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