[9134] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2752 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 28 16:07:25 1998

Date: Thu, 28 May 98 13:01:40 -0700
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 May 1998     Volume: 8 Number: 2752

Today's topics:
    Re: new to OO Perl <lr@hpl.hp.com>
    Re: Password decoding... <rootbeer@teleport.com>
    Re: PC Screen Image File <rootbeer@teleport.com>
        perl modules ("Rick Bauman")
    Re: perl modules <rootbeer@teleport.com>
    Re: Possible to "skip" a record? <lr@hpl.hp.com>
    Re: read and write (Ilya Zakharevich)
    Re: read and write (Ilya Zakharevich)
    Re: read and write (Ilya Zakharevich)
    Re: Reading whole file into a scalar (John Porter)
    Re: Reading whole file into a scalar (Lack Mr G M)
    Re: Sensing whether a script is already running... <rootbeer@teleport.com>
    Re: sort array of hashes (Tom Grydeland)
        Special Variable (again) bthak@bascom.com
    Re: Statistics for comp.lang.perl.misc (Chris Nandor)
        Unix "file" function in perl? <hamiltaj@cray.com>
    Re: Visibility of "my" vars (Jon Drukman)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 28 May 1998 11:00:08 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: new to OO Perl
Message-Id: <6kk8no$778@hplntx.hpl.hp.com>

John Porter wrote in message ...
>On Thu, 28 May 1998 08:52:05 -0700,
>in article <6kk17v$53g@hplntx.hpl.hp.com>,
>lr@hpl.hp.com (Larry Rosler) wrote:
 ...
>OO has worked wonderfully, seeing how it has been used in such
>modules as LWP and Tk.  It has allowed me to write a 10-line web
>server in perl.  Maybe my program wasn't large, but the libraries
>of classes I'm drawing on are huge, some of them.  I would say that
>meets your criteria for programming in the large.  In which case
>you've got plenty of evidence right under your nose.


Is it OO that makes the difference here, or simply the protection of
namespaces afforded in Perl by packages?  Large valuable subroutine
libraries have been available for decades.  Does calling the
abstractions that they encapsulate "classes" add value comparable to the
extra overhead?

>> I don't see how OO helps you write your write-fast/run-slow program
>> faster, but I can certainly see how it helps it run slower.
>
>According to my benchmarks, sub calls are much slower than
>hash lookups.  So, if speed is important, then one should avoid
>writing code that uses subroutines.  Makes sense, right?


It all depends.  Inlining is a way of avoiding using subroutines,
essentially by "cut and paste".  It's nice when a good optimizer does it
for you, but sometimes you just have to do it yourself.

Using Perl, there are lots of such things -- loop unrolling, for
example.  Sometimes Perl provides a Better Way.  For example, I just cut
significantly into the time of a tight inner loop by subtracting "$.
before" from "$. after" instead of counting the lines using ++$lines.
And I saved time by accumulating a value in a simple variable inside the
loop, then storing its final value into the hash where it belonged,
after the loop.  Sometimes little things mean a lot.

>And as I said, this topic has been beaten to death already.
>But I'll say it again: if speed is that important, maybe Perl
>is not the best language for you.  It would be silly to write
>a transaction processor in perl, if it has to handle a realistically
>high number of xns per sec.


Having written too much code using C's primitive string-handling library
functions, I'll vouch for the expressiveness of Perl text manipulation,
which does lead to far greater program productivity and seems to be
reasonably efficient too.  I am not trying to re-argue issues of JIT
compiler (Perl) versus batch compiler (C).  I *am* trying to focus on
the cost/benefit tradeoffs of OO per se (which could apply to C++ versus
C, also).  All new technology should be evaluated that way, but
religions should not be.  Which category does OO fall into?

--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com





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

Date: Thu, 28 May 1998 17:56:03 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Password decoding...
Message-Id: <Pine.GSO.3.96.980528105355.29051N-100000@user2.teleport.com>

On Wed, 27 May 1998 kjernigan@geocities.com wrote:

> What I want is a perl script that will take input from a html page and
> convert it into the coded version and allow the user into the board if
> it worked. 

You should probably use a module; there are some on CPAN which you may
find helpful. Since I'm not sure how far you've gotten on this project,
I'm not sure which modules to recommend. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 28 May 1998 18:17:34 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: PC Screen Image File
Message-Id: <Pine.GSO.3.96.980528111617.29051S-100000@user2.teleport.com>

On Thu, 28 May 1998 info@insyte.com wrote:

>     $out_data =~ tr /a-zA-Z0-9':+/ /c;
> 
> This does get rid of the non-alphamerics (attributes) but leaves me with
> spaces. If I do
> 
>     $out_data =~ tr /a-zA-Z0-9'://c;

That doesn't accomplish anything. (Well, for your purposes.) Perhaps you
wanted the /d option as well? Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 28 May 1998 08:40:00 +0000
From: rick@internetx.net ("Rick Bauman")
Subject: perl modules
Message-Id: <19980528123116.AAA3734@rick.internetx.net>

Is there a comprehensive list of modules needed to use the networking 
features of perl? I am constantly having to install new modules as I 
practice some of the things I learn in this newsgroup.

Thanks
Rick

Rick Bauman
System Administrator/Internet Express
rick@internetx.net  www.internetx.net
finger rick@internetx.net for pgp public key
http://www.lowcountry.net/
Lowcountry Free Software Archives



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

Date: Thu, 28 May 1998 19:18:04 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: perl modules
Message-Id: <Pine.GSO.3.96.980528121400.29051X-100000@user2.teleport.com>

On Thu, 28 May 1998, Rick Bauman wrote:

> Is there a comprehensive list of modules needed to use the networking 
> features of perl? 

Yes. 

    @comprehensive_list = qw/ /;	# :-)

You don't _need_ to use any modules. But besides the standard modules, you
should probably check out the ones in the networking categories on CPAN,
including the mail and Usenet categories. Hope this helps!

    http://cpan.perl.org/modules/by-category/

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 28 May 1998 11:04:03 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: Possible to "skip" a record?
Message-Id: <6kk8v3$7b7@hplntx.hpl.hp.com>

Dave Kenny wrote in message <6kk4rt$r2n$2@blackice.winternet.com>...
>I'm not sure exactly what you need, but perhaps `redo' can help.
>It's kind of like next or last.  A `redo' restarts the loop block
>without evaluating the conditional again.  There is an example on
>page 103 of the Camel Book.  It shows how to append the next line
>to the current one (for example if the current line ends in a
continuation
>mark like "\").  You say $_ = <>; redo;  This restarts the loop


Probably you mean to say $_ .= <>; redo; (after appropriate chomping on
$_).

>just after the while (<>), so you re-examine the now-longer line
>that resulted from appending the new line.


--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com




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

Date: 28 May 1998 19:00:37 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: read and write
Message-Id: <6kkc8l$12n$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Zenin 
<zenin@bawdycaste.org>],
who wrote in article <896341250.591544@thrush.omix.com>:
> Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> : After the first operator one has an empty FILE.  Why it is that the
> : first <FILE> returns `undef'?

> :  I would prefer the first <FILE> to
> : return an empty string, and the second one `undef'.  Is it a
> : limitation of C, which cannot disambiguate empty read() from EOF?
> 
> 	But you're at EOF, so why the empty string?  You'd run an invalid
> 	loop if you did something like while (<FILE>) that isn't meant to
> 	test true at EOF, but would if you gave it a null string becase it
> 	only tests defined.

It would test true at EOF.  It is just that it will not signal EOF on
the first iteration.

> 
> 	There is no such thing as an "empty read()", except of course at
> 	EOF.  Read() is guaranteed not to pull that kind of cheap trick
> 	on you, at least not when talking about normal files. :-)

*This* is an argument.  But this limitation of C looks
counter-intuitive to me when I think Perl.

Ilya


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

Date: 28 May 1998 19:06:09 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: read and write
Message-Id: <6kkcj1$1m2$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Martien Verbruggen
<mgjv@comdyn.com.au>],
who wrote in article <6kj28f$s08$1@comdyn.comdyn.com.au>:

> I think I have to disagree. An empty file has 0 byte size. 
> 
> $a = <FILE>
> 
> would return the next line of the file, or undef at the end of file.
> Since the file contains 0 bytes, the end of file condition is
> encountered on first read. In other words: there is no line to read.
> 
> In Perl, I think that this is a logical thing to do. Doing it
> otherwise makes it hard to distinguish between a file that contains
> nothing, or a file that contains only one line separator.

How so?  One cannot disambiguate between '' and "\n" in $_ ?

But if one takes manual *literally*, this is what should happen.
Which is very unfortunate, since one cannot be sure that after

      $/ = undef;
      $contents = <FOO>;

what is in $contents is the contents of the file.

Ilya


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

Date: 28 May 1998 19:11:28 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: read and write
Message-Id: <6kkct0$252$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was NOT sent to Ilya Zakharevich
<ilya@math.ohio-state.edu>],
who wrote in article <6kkc8l$12n$1@mathserv.mps.ohio-state.edu>:
> > 	But you're at EOF, so why the empty string?  You'd run an invalid
> > 	loop if you did something like while (<FILE>) that isn't meant to
> > 	test true at EOF, but would if you gave it a null string becase it
> > 	only tests defined.
> 
> It would test true at EOF.  It is just that it will not signal EOF on
                ^^^^
		    FALSE, of course!

> the first iteration.

Ilya


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

Date: Thu, 28 May 1998 18:03:27 GMT
From: jdporter@min.net (John Porter)
Subject: Re: Reading whole file into a scalar
Message-Id: <MPG.fd772b812fdfcd39896fa@news.min.net>

On Thu, 28 May 1998 12:21:26 -0400,
in article <6kk2u7$3of$1@nntp1.ba.best.com>,
mdolan@best.com (Mike Dolan) wrote:
> I want to read the entire contents of a text file into a single scalar so
> that I can apply regular expressions to that scalar.  Do you know how to do
> this?

RTFM&TFFAQ.

$ grep 'read in whole file' *.pod
perlfaq6.pod: undef $/;   # read in whole file, not just one line

$ grep 'input entire file' *.pod
perlfunc.pod:undefining $/ to input entire files as one record, 

$ perldoc perlvar
/$/
     $/      The input record separator, newline by default.
             Works like awk's RS variable, including treating
             empty lines as delimiters if set to the null string.
             ...You may set it to a multi-character string
             to match a multi-character delimiter, or to undef to
             read to end of file....

                 undef $/;
                 $_ = <FH>;          # whole file now here
                 s/\n[ \t]+/ /g;
 

hth,
John Porter


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

Date: Thu, 28 May 1998 18:57:31 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Reading whole file into a scalar
Message-Id: <1998May28.185731@ukwit01>

In article <6kk2u7$3of$1@nntp1.ba.best.com>, "Mike Dolan" <mdolan@best.com> writes:
|> I want to read the entire contents of a text file into a single scalar so
|> that I can apply regular expressions to that scalar.  Do you know how to do
|> this?

   You read about record separators in perlvar.  What you want to do is
read the file with no record separators, so, an example script:

#!/usr/local/bin/perl

open FH, $0 or die "Failed to open myself! $!\n";

{  local $/;     # So we only undef our view of it, not our callers...
   undef $/;
   
   $filetext = <FH>;
}

# Slurps out the whole lot, but you can process $filetext as you wish

print $filetext; 

-- 
----------- Gordon Lack ----------------- gml4410@ggr.co.uk  ------------
The contents of this message *may* reflect my personal opinion.  They are
*not* intended to reflect those of my employer, or anyone else.



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

Date: Thu, 28 May 1998 18:02:42 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Sensing whether a script is already running...
Message-Id: <Pine.GSO.3.96.980528110226.29051Q-100000@user2.teleport.com>

On Wed, 27 May 1998, Gus Garcia wrote:

> Is there a way for one Perl script to detect whether another (or even the
> same one for that matter) script is already running?

I think you could use the methods in Randal's fourth Web Techniques
column, which explains how to use flock() to avoid problems when multiple
processes need to modify one file. Hope this helps! 

   http://www.stonehenge.com/merlyn/WebTechniques/

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 28 May 1998 18:14:46 GMT
From: Tom.Grydeland@phys.uit.no (Tom Grydeland)
Subject: Re: sort array of hashes
Message-Id: <slrn6mracm.t3q.Tom.Grydeland@mitra.phys.uit.no>

On Wed, 27 May 1998 16:26:03 GMT,
tarou@kormedia.com <tarou@kormedia.com> wrote:

> I ran into the same problem and am finding that this isn't working for
> me. Perhaps I'm just not implementing it correctly<SIGH>

"isn't working" isn't enough to tell.

What did you try and what happened when you tried it?

> Kirk Tarou <tarou@kormedia.com>

-- 
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
      - Do radioactive cats have 18 half-lives? -


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

Date: Thu, 28 May 1998 19:36:47 GMT
From: bthak@bascom.com
Subject: Special Variable (again)
Message-Id: <6kkecg$2qh$1@nnrp1.dejanews.com>

Okay let me try to clarify what i need. (Hope this is clearer)

foreach $index ($rangeStart..$rangeFin) {
   $i = $index;
   if ($ip1[$i] =~ /^\d+$/ && $ip2[$i] =~ /^\d+$/ && $ip3[$i] =~ /^\d+$/ &&
       $ip4[$i] =~ /^\d+$/) {
              $count2++;
              if (($ip1[$i] >= 0 && $ip1[$i] <= 255) && ($ip2[$i] >= 0 &&
                   $ip2[$i] <= 255) && ($ip3[$i] >= 0 && $ip3[$i] <=255) &&
                   $ip4[$i] >=0 && $ip4[$i] <= 255)) {

                                ## write the file to temp directory
                   }
              else {
                   $errorIp = "<b>Invalid Ip -- Number should be between 0 -
                               255 </b>";
                   &$file;
                   exit;
              }
   }
   else {

      $errorIp = "<b>Invalid Ip -- Number should be between 0 - 255 No ltrs";
      &$file;
      exit;
   }
}

Okay Now my question is which number failed .. if i had something like
following

   255 . 255 . 255 . 0                (ALL IPS are made up but they
   100 . 234 . 80 . 65                 have to be between 0 .. 255 )
   190 . 1e0 . 19 . 49
   255 . 255 . 0 . 0

okay now $ip3[2] is failed.. i know it by looking at it.. but how i can i get
vale of  $ip3[2]  which eqauls to 1e0 .. the 1e0 could have been anywhere in
there. Or any invalid ip at any of the fields..

if ($ip1[$i] =~ /^\d+$/ && $ip2[$i] =~ /^\d+$/ && $ip3[$i] =~ /^\d+$/ &&
    $ip4[$i] =~ /^\d+$/)

above line checks if they are all digits..i want to know for which $ipX[$i] it
detected an invalid value (a non digit). $i will give me the index but how do
i know what the "X" would be..

(HOPE someone out there understands my gibberish)

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Thu, 28 May 1998 19:39:19 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <pudge-2805981533440001@dynamic265.ply.adelphia.net>

In article <6kk6fu$405@dfw-ixnews10.ix.netcom.com>, jeff@yoak.com (Jeff
Yoak) wrote:

# Whatever might be said about the nature and persistance of the
# arguments in these threads, inasmuch as the issue at stake is the
# license under which perl and Perl documentation are offered I think
# the conversation is appropriate here.  I would be surprised if the
# proposed moderators would disallow these threads.  Perhaps one of them
# might comment on it.

Advocacy issues do not belong on clp.moderated.  Any arguments about free
vs. free belongs on clp.misc if anywhere, not clp.moderated.

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])


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

Date: Thu, 28 May 1998 14:23:44 -0500
From: Andrew Hamilton <hamiltaj@cray.com>
Subject: Unix "file" function in perl?
Message-Id: <356DB9C0.B1FBFE5@cray.com>

I'm writing a perl program that will go through a user's home directory
and report to them information about their disk usage.  One thing this
program is to accomplish is to inform the user how many files they have
of certain types (i.e. gif's, jpeg's, core files, movie files, or
anything that may not be necessary).  I know I could use  something
like:

$file_type = qx{ file $name };  # where $name is the name of the file,
or
$file_type = `file $name`;  # would do the same thing.

The only problem is that if I run the program without the piece of code
to determine the file type it take about 15 seconds to read about 900
files (6.7 Mb), but if I run it with the file type code segment it takes
about 4 and a half minutes to run on the same amount of files.  The
extra time, I assume, comes in from the program having to hand over
control to the shell for every file.  If there was some way to do this
in perl, I think it would greatly speed up my code.  I've thought about
looking at file extensions, but this would be very horrific (as
sometimes files of certain formats are not saved with the correct file
extensions).

Any suggestions?

Thanks a lot,
Andrew Hamilton



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

Date: Thu, 28 May 1998 11:14:41 -0700
From: jsd@gamespot.com (Jon Drukman)
Subject: Re: Visibility of "my" vars
Message-Id: <jsd-2805981114410001@bass-kitten.immaculate.org>

In article <6kjju6$rps$1@lhc.nlm.nih.gov>, bkline@cortex.nlm.nih.gov (Bob
Kline) wrote:

> my $foo = 8;
> &bar;
> sub bar
> {
>     $foo += 3;
>     print "$foo\n";
> }

this works as you'd expect.  but don't do it, because this one doesn't:

 #!/usr/local/bin/perl -w
 foo();
 foo();

 sub foo {
     my $a = 0;
     sub bar {
        $a++;
     }
     print bar(),"\n";
     print bar(),"\n";
     $a = 10;
     print bar(),"\n";
     print bar(),"\n";
 }

-jsd-


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 2752
**************************************

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