[9595] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3189 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 17 16:07:24 1998

Date: Fri, 17 Jul 98 13:00:27 -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           Fri, 17 Jul 1998     Volume: 8 Number: 3189

Today's topics:
        array parsing problem <gil_brown@hp.com>
        Changing user from nobody to username dhawker@my-dejanews.com
        Correction: Problem with escaped octal chars > 177 <jpowers@cs.oberlin.edu>
    Re: Get char from string (Larry Rosler)
    Re: Get char from string (Craig Berry)
    Re: Get char from string <yong@shell.com>
    Re: Help me on the if-then-else branch (Craig Berry)
    Re: Help me on the if-then-else branch (Eric Harley)
    Re: Help me on the if-then-else branch <barnett@houston.Geco-Prakla.slb.com>
    Re: How do I clear an array? (Craig Berry)
    Re: How do I clear an array? <jdporter@min.net>
    Re: How to interprete What Sucks/Rules? <dean@mail.biol.sc.edu>
    Re: I'm baffled.. (and an amateur:) <jdporter@min.net>
    Re: Invoking a Programme from HTML. <dparrott@ford.com>
    Re: m//g strange behaviour ? <desar@club-internet.fr>
        Mutiple pattern searches <RC0705@email.sps.mot.com>
    Re: newbie date format (Matt Knecht)
    Re: newbie date format (Larry Rosler)
        On mixing (seek/tell) and (sysopen/syswrite) <NOSPAMkEynOn@panix.comNOSPAM>
    Re: On mixing (seek/tell) and (sysopen/syswrite) <tchrist@mox.perl.com>
    Re: Perl Beautifier Home Page <*@qz.to>
        Perl Port Benchmarking (Tom Rokicki)
    Re: Please Help Me! (Matt's Script BB Problem) <merlyn@stonehenge.com>
    Re: Print LoL-tree routine (attached) <swoboda@uvic.ca>
    Re: Print LoL-tree routine (attached) <swoboda@uvic.ca>
    Re: Print LoL-tree routine (attached) <jdporter@min.net>
        Problem with escaped octal chars > 127 <jpowers@cs.oberlin.edu>
        ptkdb Vers 1.033  Perl Debugger With ptk GUI (Andrew E Page)
    Re: real quick and easy - replace.... (Craig Berry)
    Re: Recipient Validation <alschoen@nps.navy.mil>
    Re: regexp help? <yong@shell.com>
    Re: Return value of eval() <jdporter@min.net>
        Which Win32 port should I use? <markstang@ncgroup.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Fri, 17 Jul 1998 15:34:03 -0400
From: "Gil Brown" <gil_brown@hp.com>
Subject: array parsing problem
Message-Id: <6oo8vl$il5$1@ocean.cup.hp.com>

Hi;

I am trying to parse a line from a file by assigning it to an array. I need
the 4th element of the line and sometimes it does not exist. When it doesn't
exist perl complains about an uninitialized value but print the value
whitout complaining if it's there. What am I missing?

use strict;
use FileHandle;
use diagnostics;


my @data;
my $fh = new FileHandle; # Create local filehandle
open ($fh, "/home/gbrown/test/hqhp1") || die $!;
while (defined(my $line = <$fh>))
{
        @data=split(/ +/,$line);
         print "$data[3]\n";
}

Thank you.




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

Date: Fri, 17 Jul 1998 19:08:44 GMT
From: dhawker@my-dejanews.com
Subject: Changing user from nobody to username
Message-Id: <6oo7fr$l9m$1@nnrp1.dejanews.com>

The web server is run as "nobody" and emails sent from a web script have
nobody@host in the From. Is it possible, in perl, to change the identity to
our username? Short of sending ourself an email to be processed by our mail
server script which runs as our username.

dhawker@bigfoot.com

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Fri, 17 Jul 1998 14:22:58 -0400
From: Joshua Powers <jpowers@cs.oberlin.edu>
Subject: Correction: Problem with escaped octal chars > 177
Message-Id: <Pine.ULT.3.96.980717140921.7588L-100000@occs.cs.oberlin.edu>

Apologies - there were a few errors in my previous posting, which I have
corrected:

I have run into an interesting problem when using escaped octal values
outside of the ascii range as markers in an expression parser. I got the
idea to do this from Sriram Srinivasan's _Advanced Perl Programming_ (page
184, where he uses \201 and \200 to replace quotation marks).  I am using
character \202. 
 
When, during the recursion, I encounter one of these markers, the value of
my counter variable is forcibly set to '1', even though it is initialized
to zero.  It seems that Perl is somehow writing over its own byte codes
upon encountering this marker.

Programming Perl doesn't seem to make much mention of this issue.  It says
that an escaped numberin a pattern match that can't be interpreted any
other way is interpreted as an octal value (as long as it is 3 digits or
fewer), but it seems this is restricted to the 128 values in the ASCII
charater set. 
 
Has anyone encountered this problem in the past?
 
 -Josh Powers
 
 
 -_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-
 		     Josh Powers - jpowers@cs.oberlin.edu
 		      http://www.cs.oberlin.edu/~jpowers



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

Date: Fri, 17 Jul 1998 10:58:32 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Get char from string
Message-Id: <MPG.101930a2ceefaa66989721@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <35AF8BBB.EF03907A@best.com> on Fri, 17 Jul 1998 10:36:59 -
0700, bchapman <bchapman@best.com> says...
> Say I have a string that is 10 chars long and I want the 4th char of it.
> 
> The only way I know how to do that is substr the string down to a 1
> character string, and then chop that to give me the char.
> 
> Is there an easier way to do that?

my $char = substr $string, 3, 1;

Why should you have to do a 'chop'; on what???

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 17 Jul 1998 18:24:21 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Get char from string
Message-Id: <6oo4sl$f3c$4@marina.cinenet.net>

bchapman (bchapman@best.com) wrote:
: Say I have a string that is 10 chars long and I want the 4th char of it.

  $str  = 'abcdefghij';
  $c4th = substr($str, 3, 1);   # 4th char is at index 3

$c4th is now 'd'.

: The only way I know how to do that is substr the string down to a 1
: character string, and then chop that to give me the char.
: 
: Is there an easier way to do that?

Dear god, there exist *only* easier ways to do that...

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Fri, 17 Jul 1998 14:50:21 -0500
From: Yong Huang <yong@shell.com>
To: bchapman <bchapman@best.com>
Subject: Re: Get char from string
Message-Id: <35AFAAFD.FC179DDD@shell.com>

Bill,

The function substr is actually very fast. If you want to use regular
expressions, e.g.., they're probably slower. If your actual work involves
more complicated string manipulation than the example you posted, let us
know.

Yong Huang

bchapman wrote:

> Say I have a string that is 10 chars long and I want the 4th char of it.
>
> The only way I know how to do that is substr the string down to a 1
> character string, and then chop that to give me the char.
>
> Is there an easier way to do that?
>
> My return address works.  Please cc it.
>
> Bill Chapman





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

Date: 17 Jul 1998 18:06:35 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Help me on the if-then-else branch
Message-Id: <6oo3rb$f3c$2@marina.cinenet.net>

Mark Stang (markstang@ncgroup.com) wrote:
: I'm a newbie too, but I think your code should be changed to read
: 
: $name = chomp(<STDIN>);

Nope, can't chomp a constant list.

BTW, my earlier answer was incomplete; as others have pointed out, the
original poster does indeed need to chomp off the newline in addition to
the case problem I pointed out.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Fri, 17 Jul 1998 11:51:29 -0700
From: eharley@pacbell.net (Eric Harley)
Subject: Re: Help me on the if-then-else branch
Message-Id: <eharley-1707981151300001@ppp-207-214-149-253.snrf01.pacbell.net>

> > I get a prompt asking me for my name, and it accepts my input, However
> > when I put the word Lloyd in, it ignores the if then branch and goes
> > straight to the last line and prints hello lloyd.
> 
> Two things come to mind, bolth untested.  One would be that $name ==
> lloyd\n.  Try 
> 
> $name = <STDIN>;
> chomp $name;
> 
> to remove any CR/LF at the end of $name.
> 
> The other is that it is missing due to case sensitivity.

So you would write:

#!/usr/local/bin/perl -w

print "What is your name?\n";

chomp($name = <STDIN>);

if ($name =~ /lloyd/i) {
   print "Hi Lloyd glad to see you back!\n";
} else {
   print "hello, $name\n";
}

-- 
Eric Harley
Freelance Programmer
  You need it done, I'm your man.

eharley@pacbell.net
http://burn.victim.com/~eharley


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

Date: Fri, 17 Jul 1998 13:27:09 -0500
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: Help me on the if-then-else branch
Message-Id: <35AF977D.E2A8C6DF@houston.Geco-Prakla.slb.com>

lloyd wrote:
> 
> I am a total newcomer to the perl language. I bought the book Learning
> Perl and I have learned a lot already, but there is a small 9 line program
> that I cannot figure out.
> 
> Here is the program:
> 
> #!/usr/local/bin/perl -w
> 
> print "What is your name?\n";
> $name = <STDIN>;
> if ($name eq "lloyd") {
>    print "Hi Lloyd glad to see you back!\n";
> } else {
> print "hello, $name\n";
> }
> 
> I get a prompt asking me for my name, and it accepts my input, However
> when I put the word Lloyd in, it ignores the if then branch and goes
> straight to the last line and prints hello lloyd.
> 
> Why is this happening. I copied this program stright out of that book and
> it doesn't work. Someone please be kind enough to help.....
> 
> lloyd francis
> lloyd007@best.com
Several reasons come to mind.

One, why are you typing Lloyd (cap L), but checking against lloyd (lower
l)?
Second, you do realize that all input from STDIN has a newline character
on the end, right?  ($name = "lloyd<RETURN>" where <RETURN> = \n, or
\r\n or Mac combination for end of line)  Look up chop/chomp in the docs
(perldoc -f chomp).
Third, you do understand that $name eq "lloyd" is making sure that $name
matches EXACTLY with the letters lloyd, and nothing else, right? 
Similar to:  if ($name =~ /^lloyd$/)

Several suggestions:
if ($name =~ /lloyd/i) {	# ignores case
if ($name =~ lc(lloyd)) {       # also ignores case
include chomp($name) after $name = ... and before if ...


HTH.

Dave

-- 
"Security through obscurity is no security at all."
		-comp.lang.perl.misc newsgroup posting

----------------------------------------------------------------------
Dave Barnett                 U.S.: barnett@houston.Geco-Prakla.slb.com
DAPD Software Support Eng    U.K.: barnett@gatwick.Geco-Prakla.slb.com
----------------------------------------------------------------------


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

Date: 17 Jul 1998 18:20:05 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How do I clear an array?
Message-Id: <6oo4kl$f3c$3@marina.cinenet.net>

Robert Eric Pearse (pearse@mail.shebang.net) wrote:
: > A vivid image, that. :)  Let me ask you this:  Why are you assigning a
: > scalar (the empty string) to an array?  Shouldn't you be assigning lists
: > to arrays, in generaly?  What does the empty *list* look like?
: 
: You tell me.

Larry "one S" Rosler just did, in another reply.  It's ().  Kinda makes
sense, no? :-)

(What is it with Perl hackers and duplicate-consonant stripping, anyway? 
Randal, Rosler...Have they all run a tr/a-z//s on their names?  Do I have
to become Craig Bery if I aspire to gurudom?) 

: I never looked at arrays as lists of lists. 

That's not what I said.  An array holds a list, to put it one way. 
Assigning () to an array says "Make this array hold the empty list." 

: Although, they can and often are. I've just used them in the following
: context.
: 
: while ($foo = readdir(DIR) {
: 	@bar = (@bar, $foo)
: }
: 
: Looks like I'm assigning scalars to an array here. . .

Nope, the assignment is of a list to an array.  The list is in turn
composed by taking an existing array and appending a scalar to it, in the
next unused array position.  Note that

  push @bar, $foo;

is the more usual way to write this.

Note also that you can do the entire loop above as a single operation:

  push @bar, readdir DIR;

since readdir in a list context returns all the remaining entries.  If
your intent is that @bar is initially empty, you can just say

  @bar = readdir DIR;

instead.

Never forget to think about list versus scalar context, and always keep in
mind that lists can contain *only* scalars.

Hope this helps...

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Fri, 17 Jul 1998 19:21:32 GMT
From: John Porter <jdporter@min.net>
Subject: Re: How do I clear an array?
Message-Id: <35AFA5D1.3CC2@min.net>

Craig Berry wrote:
> 
> (What is it with Perl hackers and duplicate-consonant stripping, anyway?
> Randal, Rosler...Have they all run a tr/a-z//s on their names?  Do I have
> to become Craig Bery if I aspire to gurudom?)

Heh! Ronald J. Kimbal, Haijo Schiper, Martien Verbrugen...
Hmm, but not Lary Wal.

-- 
John Porter

sub Another::Just {
shift;local$\=",\n";local$,=' ';
print reverse @_,(caller(0))[3]=~/(.*)::(.*)/;
}
sub Hacker::Perl{(caller(0))[3]=~/(.*)::(.*)/}
Just Another Perl Hacker;


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

Date: 17 Jul 1998 13:54:56 -0400
From: Dean Pentcheff <dean@mail.biol.sc.edu>
Subject: Re: How to interprete What Sucks/Rules?
Message-Id: <m3hg0gicr3.fsf@mail.biol.sc.edu>

kortbein@iastate.edu (Josh Kortbein) writes:
> Yong Huang (yong@shell.com) wrote:
> : At http://www.tpj.com/tpj/rules/ and
> : http://electriclichen.com/linux/srom.html, it talks about What
> : Sucks/Rules. But the article is not clear as to the criterion. Seems the
> : result comes from a Web search for "XXX rules" and "XXX sucks" strings
> : and count them. Can anybody explain? The fact that Java sucks even more
> : than Visual BASIC seems to counteract most people's impression.
> 
> Perhaps some normalization is in order. There are probably simply
> more people talking about Java sucking. :)

It uses a ratio based on the counts.

-Dean
-- 
N. Dean Pentcheff                                          <pentcheff@acm.org>
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-7068)


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

Date: Fri, 17 Jul 1998 18:34:35 GMT
From: John Porter <jdporter@min.net>
Subject: Re: I'm baffled.. (and an amateur:)
Message-Id: <35AF9AD0.6474@min.net>

JFR wrote:
> 
>         print start_form;
>         print "<HTML>\n";
>         print "<HEAD>\n";
>[etc.]

May I gently suggest that you use a single print statement
for things like this?  E.g.

print qq{
  <HTML>
  <HEAD>
  ....
  </HTML>
};

or a Here document:

print <<EOF;
  <HTML>
  <HEAD>
  ....
  </HTML>
EOF

-- 
John Porter

sub Another::Just {
shift;local$\=",\n";local$,=' ';
print reverse @_,(caller(0))[3]=~/(.*)::(.*)/;
}
sub Hacker::Perl{(caller(0))[3]=~/(.*)::(.*)/}
Just Another Perl Hacker;


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

Date: Fri, 17 Jul 1998 13:55:00 -0400
From: "Dennis M. Parrott" <dparrott@ford.com>
To: Scratchie <upsetter@ziplink.net>
Subject: Re: Invoking a Programme from HTML.
Message-Id: <35AF8FF4.5469@ford.com>

Scratchie wrote:
> 
> Michael W. Lancaster <conservative-party@iname.com> wrote:
> 
> : I have tried using three statements but to no avail;
> 
> : <!--exec cgi="/lordgovernor/cgi/script.cgi"-->
> : <!--exec cgi="/full/path/to/cgi/script.cgi"-->
> : <!--include virtual="/lordgovernor/cgi/script.cgi"-->
> 
> I think you need a space before the -->.
> 

BZZZT!  No, sorry, but that is a Wrong Answer! We do 
thank you for playing SSI Trivia!  Johnny, please tell
our contestant what lovely consolation prizes he has 
won!

Code it this way:

  <!--#exec cgi="/<relative path to CGI script>"-->

BTW - the include needs to do the same deal.
AND - whether you need a space before the '-->' 
thingie depends on your server -- some seem to like
it, others don't or don't care...

-- 

-----------------------------------------------------------------------
Dennis M. Parrott        |            Unix:  dparrott@ford.com
PCSE Webmaster           |           PROFS:  DPARROTT
Ford Motor Company       |             VAX:  EEE1::PARROTT
Dearborn, Michigan USA   | public Internet:  dparrott@ford.com
-----------------------------------------------------------------------
Voice: 313-322-4933  Fax: 313-248-1234  Pager: 313-201-9978


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

Date: Fri, 17 Jul 1998 20:08:56 +0200
From: Francois DESARMENIEN <desar@club-internet.fr>
To: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: m//g strange behaviour ?
Message-Id: <35AF9338.24093C0C@club-internet.fr>

Hi Rick,

> The other thing I noticed is that you do get 'aa' under the older
> v5.003.
>

Thank you for all the time you spent on that !
Your last statement made me look at Perl 5.003 too and I found the
same result than you ("aa").
So I sent (as Ilya suggested me later) a bug report to have
it (maybe) corrected in 5.005.

Again, many thanks

Francois




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

Date: Fri, 17 Jul 1998 11:40:29 +0000
From: John Nguyen <RC0705@email.sps.mot.com>
Subject: Mutiple pattern searches
Message-Id: <35AF380A.533C@email.sps.mot.com>

Is there a way of searching a text file using multiple search patterns. 
For example, say I want only lines from a text file that does NOT
include these three patterns: abc xyz mno

My problem is that the string patterns are elements in an array.  How do
you specify an array in a search pattern and have a ! (not) symbol in
front of each element since I only want lines that do not include these
string patterns.

John


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

Date: Fri, 17 Jul 1998 18:18:11 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: newbie date format
Message-Id: <DzMr1.144505$on1.7842514@news2.voicenet.com>

Larry Rosler <lr@hpl.hp.com> wrote:
>Odd that you should prefer quick and dirty to quick and clean.
>
>#!/usr/local/bin/perl -w
>use Benchmark;
>
>$x = '1';
>
>timethese(1 << (shift || 0), {
>    Clean => sub { $_ = sprintf '%.2d', $x },
>    Dirty => sub { $_ = (length($x) < 2 && '0') . $x },
>});
>__END__
>
>Benchmark: timing 65536 iterations of Clean, Dirty...
>     Clean:  2 secs ( 1.68 usr  0.01 sys =  1.69 cpu)
>     Dirty:  6 secs ( 1.71 usr  0.02 sys =  1.73 cpu)

I agreed to quickly with your alternative to my solution.  We need to
add my original back into the fray:

timethese(1 << (shift || 0), {
    Clean => sub { $_ = sprintf '%.2d', $x },
    Dirty => sub { $_ = (length($x) < 2 && '0') . $x },
    Orig  => sub { $_ = $x+1 < 10 ? $x : '0'.$x },
});

Which gives me:

Benchmark: timing 65536 iterations of Clean, Dirty, Orig...
     Clean: 10 secs ( 6.56 usr  0.00 sys =  6.56 cpu)
     Dirty:  6 secs ( 4.54 usr  0.00 sys =  4.54 cpu)
      Orig:  6 secs ( 3.97 usr  0.00 sys =  3.97 cpu)

The difference between run times on identical code on two different
machines is disturbing.  I ran the same test with a higer count to get a
better look:

Benchmark: timing 262144 iterations of Clean, Dirty, Orig...
     Clean: 29 secs (27.34 usr  0.00 sys = 27.34 cpu)
     Dirty: 19 secs (19.07 usr  0.00 sys = 19.07 cpu)
      Orig: 16 secs (15.95 usr  0.00 sys = 15.95 cpu)

On my machine (Sparc 2 *shudder*) the sprintf solution takes almost
twice as long as using ?:.  Out of curiousity, what platform did you run
that on?

>> Ideally I'd bury something like the above in a #define, but I haven't
>> got the heart to litter my Perl code with pre-processor statements...
>> yet :)
>
>Gag me!

Well, I really do miss the convienence of inlining small functions, and
truly constant constants that it gives.

-- 
Matt Knecht - <hex@voicenet.com>
"496620796F752063616E207265616420746869732C20796F7520686176652066
617220746F6F206D7563682074696D65206F6E20796F75722068616E6473210F"


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

Date: Fri, 17 Jul 1998 12:45:33 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: newbie date format
Message-Id: <MPG.101949bca13113c6989722@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <DzMr1.144505$on1.7842514@news2.voicenet.com> on Fri, 17 Jul 
1998 18:18:11 GMT, Matt Knecht <hex@voicenet.com> says...
 ...
timethese(1 << (shift || 0), {
    Clean => sub { $_ = sprintf '%.2d', $x },
    Dirty => sub { $_ = (length($x) < 2 && '0') . $x },
    Orig  => sub { $_ = $x+1 < 10 ? $x : '0'.$x },
});

The logic of Orig is wrong, but it doesn't much change the Benchmarks.

 ...
> The difference between run times on identical code on two different
> machines is disturbing.  I ran the same test with a higer count to get a
> better look:
> 
> Benchmark: timing 262144 iterations of Clean, Dirty, Orig...
>      Clean: 29 secs (27.34 usr  0.00 sys = 27.34 cpu)
>      Dirty: 19 secs (19.07 usr  0.00 sys = 19.07 cpu)
>       Orig: 16 secs (15.95 usr  0.00 sys = 15.95 cpu)
> 
> On my machine (Sparc 2 *shudder*) the sprintf solution takes almost
> twice as long as using ?:.  Out of curiousity, what platform did you run
> that on?

Clean  Dirty  Orig   perl -v   uname -a
 9.73   7.32  6.98   5.002     HP-UX       9.05 HP 9000/735
10.08   7.58  7.43   5.003     Windows_NT  4.00 HP Vectra XU 6/200
 6.63   6.53  6.13   5.004_03  HP-UX      10.20 HP 9000/819

This benchmark was slightly recast, because the one posted previously 
didn't compile under the older versions of perl:

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

$x = 1;

sub Clean { sprintf '%.2d', $x }
sub Dirty { (length($x) < 2 && '0') . $x }
sub Orig  { $x > 9 ? $x : '0' . $x }

timethese(1 << 18), {
    'Clean' => q{ Clean() },
    'Dirty' => q{ Dirty() },
    'Orig'  => q{ Orig()  },
});

My conclusion:  [s]printf has been improved in perl 5.004 to the degree 
that using it when convenient is appropriate without significant 
performance penalty.

Now let's look at a more realistic use:  mm/dd:

$x = 1; $y = 10;

sub Clean { sprintf '%.2d/%.2d', $x, $y }
sub Orig  { ($x > 9 ? $x : '0' . $x) . '/' . ($y > 9 ? $y : '0' . $y) }

timethese(1 << 18, {
    'Clean' => q{ Clean() },
    'Orig'  => q{ Orig()  },
});

Clean:  8.32
 Orig:  9.01

And extrapolate to '%d/%.2d/%.2d %.2d:%.2d:%.2d'.  Are we beginning to 
see the light?

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 17 Jul 1998 18:15:20 GMT
From: k y n n <NOSPAMkEynOn@panix.comNOSPAM>
Subject: On mixing (seek/tell) and (sysopen/syswrite)
Message-Id: <6oo4bo$qqi@news1.panix.com>



I've learned that, in some Perl implementations (e.g. v. 5.004 on
Linux), mixing calls to syswrite and tell yields crazy results (I
posted a script illustrating this recently).  From what I understand,
sysopen, syswrite, sysread, etc. use a different "interface" from that
used by open, print, and tell (and seek?), which means that mixing
calls to functions from these two sets leads to serious trouble.
(With the exception of a few cryptic hints here and there in the Camel
book, e.g. at the end of the engry for sysread, p. 230, I have not
found any documentation on this topic, so it wouldn't surprise me if I
hadn't gottne it quite right.)

What I want to know is, what can I safely use in place of tell() and
seek() in conjunction with sysopen(), syswrite()?

Alternatively, how can I use open() and print() to write at a given
offset from the beginning of a file without erasing it (as would
happen if I used open(OUT, ">file"))?

Thank you very much,

K.

-- 
To those who prefer to reply by e-mail, please remove the upper-case
letters from the return address in the header.  Thank you.  K.


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

Date: 17 Jul 1998 18:46:59 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: On mixing (seek/tell) and (sysopen/syswrite)
Message-Id: <6oo673$300$1@csnews.cs.colorado.edu>

In comp.lang.perl.misc, 
    k y n n <NOSPAMkEynOn@panix.comNOSPAM> writes:
:What I want to know is, what can I safely use in place of tell() and
:seek() in conjunction with sysopen(), syswrite()?

No.  And when you stop mutilating your address, I'll tell
you what you should do instead.

--tom
-- 
	    Refer does not rhyme with deafer.
	    Foeffer does, and zephyr, heifer.


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

Date: 17 Jul 1998 19:32:50 GMT
From: Eli the Bearded <*@qz.to>
Subject: Re: Perl Beautifier Home Page
Message-Id: <eli$9807171530@qz.little-neck.ny.us>

In comp.lang.perl.misc, Russ Allbery  <rra@stanford.edu> wrote:
> Anything that's nested more than four levels needs rewriting.
> I've encountered *very, very* few exceptions to that principle that can be
> justified.  If you use a four-space indent, you should be able to handle
> four level nesting without continuation with very little difficulty.

Don't use commented REs very often do you? This will just fit in eighty
columns with tabs at eight and shiftwdith at four, but I would prefer it if
I could have the comment text indented to match the code. (There is,
actually, a violation of the indent style here to coerce it to fit into the
narrow line.)

I like one or two column indentation. It works.

sub bus {

    my $car = shift;

		    #
		    # We here try to match a three letter weekday followed
		    # by a three letter month and day or a day " of " a
		    # three letter month.
		    #
		    # $1 will have the whole date, minus the trailing garbage
		    # $2 will have the three letter month and day (if found)
		    # $3 will have the day " of " a month (if found)
		    #
    if ( $$car =~ /^				# begin match, anchored
		    (				# start capture to $1 (a)
		        (?:			# begin grouping (b)
				Sun		# match a three letter weekday
			    |   Mon		#   "
			    |   Tue		#   "
			    |   Wed		#   "
			    |   Thu		#   "
			    |   Fri		#   "
			    |   Sat		#   "
			)			# end group (b)
			\s+			# match some white space
			(?:			# begin group (c)
			    (			# begin capture to $2 (d)
				(?:		# begin group (e) 
				        Jan	# match a three letter month
				    |   Feb	#   "
				    |   Mar	#   "
				    |   Apr	#   "
				    |   Jun	#   "
				    |   Jul	#   "
				    |   Aug	#   "
				    |   Sep	#   "
				    |   Oct	#   "
				    |   Nov	#   "
				    |   Dec	#   "
				)		# end group (e)
				\s+		# match whitespace
				(?:		# begin group (f)
				        [012]?	# a first digit (optional)
					\d	# a second digit
				    |   3[01]	# or a 3x day
				)		# end group (f)
			    )			# end capture to $2 (d)
			|   (			# begin capture to $3 (g)
				(?:		# begin group (h)
				        [012]?	# a first digit (optional)
					\d	# a second digit
				    |   3[01]	# or a 3x day
				)		# end group (h)
				\s+ of \s+	# match " of "
				(?:		# begin group (i) 
				        Jan	# match a three letter month
				    |   Feb	#   "
				    |   Mar	#   "
				    |   Apr	#   "
				    |   Jun	#   "
				    |   Jul	#   "
				    |   Aug	#   "
				    |   Sep	#   "
				    |   Oct	#   "
				    |   Nov	#   "
				    |   Dec	#   "
				)		# end group (i)
			    )			# end capture to $3 (g)
			)			# end group (c)
		    )				# end capture to $1 (a)
		  /ix				# /i: case insensitive
		  				# /x: expanded format
    			)	# end of if() clause
        {	# begin if( $$car =~ date ) code block

	    my $fulldate = $1;
	    my $monthday = $2 or $3;

	    # do stuff

	}	# end if( $$car =~ date ) code block
    else
    	{	# begin if( $$car =~ date )...else code block

	    # report error

	}	# end if( $$car =~ date )...else code block
}

Elijah
------
considers this a simple RE, just for example purposes


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

Date: 17 Jul 1998 11:42:46 -0700
From: rokicki@cello.hpl.hp.com (Tom Rokicki)
Subject: Perl Port Benchmarking
Message-Id: <6oo5v6$jkv@cello.hpl.hp.com>


Has anyone thought of a `PerlMarks' benchmark that compares the
runtime of different aspects of Perl on different machines?  I'm
thinking of something that would separately check things like grunt
code (increment/loop/etc.), memory allocation (cons a lot of large
arrays and hashes, copy them, etc.), regexp handling, string
interpolation/concatenation, etc.

Putting together the correct metrics is the first step in improving
performance . . .

-tom


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

Date: Fri, 17 Jul 1998 18:41:32 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Please Help Me! (Matt's Script BB Problem)
Message-Id: <8caf68z5ez.fsf@gadget.cscaper.com>

>>>>> "IRA" == I R A Aggie <fl_aggie@thepentagon.com> writes:

IRA> He's stated, in the documentation, and in several other forums that
IRA> he may or may not correct bugs in his script archive. Reading between
IRA> the lines: its free software, and if it works for you, great, if not,
IRA> then dump into the trash.

That's why I call all my WebTechniques Perl programs "models" instead
of "ready-to-run software".  If they break, no one ever complains to
me, or at least doesn't get upset when I say I'm not supporting it.

print "Just another Perl hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Fri, 17 Jul 1998 10:29:00 -0700
From: Paul <swoboda@uvic.ca>
Subject: Re: Print LoL-tree routine (attached)
Message-Id: <35AF89DC.FDABC685@uvic.ca>

This is a multi-part message in MIME format.
--------------A66FCACF72CC1AAE64AB08DD
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Oops!  I just realized that, in packaging up that routine
for the above post, I screwed it up (it used to be just one
function).  A corrected version is attached.


--------------A66FCACF72CC1AAE64AB08DD
Content-Type: text/plain; charset=us-ascii; name="print_lol.ph"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="print_lol.ph"

sub print_lol_tree
# Prints a tree (built from lists of lists), indenting each new level by two
# and printing branches.  Space between branches is filled in with periods, so
# that indentation levels can be seen clearly.
#
# Argument: The LoL-tree: must be passed in as a reference to a list!
{
  my($tree_ref) = @_;

  if (ref($tree_ref) ne 'ARRAY') {
    print "ERROR: non array-ref argument passed to print_lol_tree()\n";
    return;
  }
  if ($#{$tree_ref} > 0) {
    print_lol_tree_helper('+-', $tree_ref, 0);
  } else {
    print_lol_tree_helper('+-', $tree_ref, 1);
  }
}


sub print_lol_tree_helper
{
  my($indent, $tree, $last_element_flag_list) = @_;
  my($this_node, $first_element_drawn, $temp_indent, $node_count,
     $temp_flag_list, $this_flag);

  if (length($indent) == 0) {
    $indent = '+-';
  }
  $first_element_drawn = 0;
  $node_count = -1;
  foreach $this_node (@{$tree}) {
    $node_count++;
    if ($first_element_drawn) {
      $temp_flag_list = $last_element_flag_list;
      $indent = '';
      while(length($temp_flag_list) > 0) {
	$this_flag = chop($temp_flag_list);
	if ($this_flag eq '1') {
	  $indent = '. ' . $indent;
	} else {
	  $indent = '| ' . $indent;
	}
      }
    }
    if (ref($this_node) eq 'ARRAY') {
      if ($#{$this_node} >= 0) {
	# This node is a non-empty subtree:
	if ($node_count == $#{$tree}) {
	  print_lol_tree_helper($indent . '+-', $this_node,
				$last_element_flag_list . 1);
	} else {
	  print_lol_tree_helper($indent . '+-', $this_node,
				$last_element_flag_list . 0);
	}
      } else {
	# This node is a reference to an empty list:
	print $indent . '+-' . "\n";
      }
    } else {
      # A leaf!  Print the contents in quotes:
      print "$indent\"$this_node\"\n";
    }
    $first_element_drawn = 1;
  }
}


1;

--------------A66FCACF72CC1AAE64AB08DD--



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

Date: Fri, 17 Jul 1998 10:33:03 -0700
From: Paul <swoboda@uvic.ca>
Subject: Re: Print LoL-tree routine (attached)
Message-Id: <35AF8ACF.EE911FCA@uvic.ca>

This is a multi-part message in MIME format.
--------------EEDBCACFE718426561C264E7
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

ARGHH!  Ignore the last posting!  I attached the wrong
correction file!  The real one is attached.  :-)

--------------EEDBCACFE718426561C264E7
Content-Type: text/plain; charset=us-ascii; name="print_lol.ph"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="print_lol.ph"

sub print_lol_tree
# Prints a tree (built from lists of lists), indenting each new level by two
# and printing branches.  Space between branches is filled in with periods, so
# that indentation levels can be seen clearly.
#
# Argument: The LoL-tree: must be passed in as a reference to a list!
{
  my($tree_ref) = @_;

  if (ref($tree_ref) ne 'ARRAY') {
    print "ERROR: non array-ref argument passed to print_lol_tree()\n";
    return;
  } elsif ($#{$tree_ref} < 0) {
    print "+-\n";
    return;
  }
  print_lol_tree_helper('+-', $tree_ref, 1);
}


sub print_lol_tree_helper
{
  my($indent, $tree, $last_element_flag_list) = @_;
  my($this_node, $first_element_drawn, $temp_indent, $node_count,
     $temp_flag_list, $this_flag);

  if (length($indent) == 0) {
    $indent = '+-';
  }
  $first_element_drawn = 0;
  $node_count = -1;
  foreach $this_node (@{$tree}) {
    $node_count++;
    if ($first_element_drawn) {
      $temp_flag_list = $last_element_flag_list;
      $indent = '';
      while(length($temp_flag_list) > 0) {
	$this_flag = chop($temp_flag_list);
	if ($this_flag eq '1') {
	  $indent = '. ' . $indent;
	} else {
	  $indent = '| ' . $indent;
	}
      }
    }
    if (ref($this_node) eq 'ARRAY') {
      if ($#{$this_node} >= 0) {
	# This node is a non-empty subtree:
	if ($node_count == $#{$tree}) {
	  print_lol_tree_helper($indent . '+-', $this_node,
				$last_element_flag_list . 1);
	} else {
	  print_lol_tree_helper($indent . '+-', $this_node,
				$last_element_flag_list . 0);
	}
      } else {
	# This node is a reference to an empty list:
	print $indent . '+-' . "\n";
      }
    } else {
      # A leaf!  Print the contents in quotes:
      print "$indent\"$this_node\"\n";
    }
    $first_element_drawn = 1;
  }
}


1;

--------------EEDBCACFE718426561C264E7--



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

Date: Fri, 17 Jul 1998 19:29:44 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Print LoL-tree routine (attached)
Message-Id: <35AFA7BD.1DF1@min.net>

Paul wrote:
> 

You posted three times, but never said there was something
wrong with it, or asked for help.
Are you just proud of your brainchild?
If so, then kudos. KUTGW.

-- 
John Porter

Also, you're drunk.


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

Date: Fri, 17 Jul 1998 14:05:29 -0400
From: Joshua Powers <jpowers@cs.oberlin.edu>
Subject: Problem with escaped octal chars > 127
Message-Id: <Pine.ULT.3.96.980717135313.7588K-100000@occs.cs.oberlin.edu>

I have run into an interesting problem when using escaped octal values
outside of the ascii range as markers in an expression parser. I got the
idea to do this from Sriram Srinivasan's _Advanced Perl Programming_ (page
184, where he uses \201 and \200 to replace quotation marks).  I am using
character \202. 

When, during the recursion, I encounter one of these markers, the value of
my counter variable is forcibly set to '1', even though it is initialized
to zero.  It seems that Perl is somehow writing over its own byte codes
upon encountering this marker.  In Programming Perl, mention is only ever
made of escaping two-digit octal characters in this way, so I don't think
this can be considered a bug, as I am not following the language spec
exactly (although no error or warning is given). 

Has anyone encountered this problem in the past?

-Josh Powers


-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-
		     Josh Powers - jpowers@cs.oberlin.edu
		      http://www.cs.oberlin.edu/~jpowers



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

Date: Fri, 17 Jul 1998 19:11:14 GMT
From: aep@world.std.com (Andrew E Page)
Subject: ptkdb Vers 1.033  Perl Debugger With ptk GUI
Message-Id: <Ew96Mq.KM6@world.std.com>

ptkdb  A  Perl debugger with Graphical User Interface

You can find this utility with at:

<a href="http://world.std.com/~aep/ptkdb">http://world.std.com/~aep/ptkdb</a>

http://world.std.com/~aep/ptkdb

   Included are links to binaries for perl for Win95/NT with Tk
installed, and the latest distributions for perlTk.



New Version 1.033

Release Notes:

Bug fix.  Fixed conflict with debugging command line -e scripts.

Bug fix.  Expressions were not deleting properly from the list

Tune-up.   <Return> Dismisses alerts.

Tune-up.  You can select multiple expressions to delete.

Some work on 'rationalizing' the code, cleaning things up, increasing
the number of comments within the code.

New Environmental Variables: PTKDB_STOP_TAG_COLOR and
                             PTKDB_BREAKPOINT_TEXT_COLOR
-- 
Andrew E. Page   (Warrior Poet) |   Decision and Effort The Archer and Arrow
Software Engineering Consultant |     The difference between what we are
Unix, Mac, C/C++/Java, Perl, NT |           and what we want to be.


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

Date: 17 Jul 1998 18:00:08 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: real quick and easy - replace....
Message-Id: <6oo3f8$f3c$1@marina.cinenet.net>

Andrew M. Langmead (aml@world.std.com) wrote:
: cberry@cinenet.net (Craig Berry) writes:
: 
: >merzky@physik.hu-berlin.de wrote:
: >: $string =~ tr/[a-z]/[A-Z]/g;    # replace set of chars by diff. set (man tr)
: 
: >Replacing [ by [ and ] by ] seems a bit like a make-work program for the
: >interpreter. 
: 
: Its probably not all that much work,
[snip]

Yeah, I know, it was an attempt at humor.  Forgot my <joke></joke> markup
again...

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Fri, 17 Jul 1998 19:37:59 GMT
From: Art Schoenstadt <alschoen@nps.navy.mil>
Subject: Re: Recipient Validation
Message-Id: <35AFA816.41C67EA6@nps.navy.mil>

H.P. Buerki wrote:
> 

> 
> >
> > Re: Recipient Validation, H <webmaster@mediapromotion.ch>
> > said:
> >
> > H> Hi how i can make for sure, that the Recipient Addresses
> > H> are valid on the Remote Server before i will send an
> > H> E-Mail.
> >

   There are a couple of ways that SOMETIMES work:

    (1)  Use the   vrfy  program.  It exists on the web - try
         an archie site to find it.  It's written in C, and I
         got it to compile on my Sparc without too much trouble.

    (2)  Do a direct telnet to port 25 of the desired host and
         issue the command:

                 vrfy   username

         or
                 expn   username
 
        where  username  is the address you want to check.  
        (Sometimes only one of these will work.)

    (3) Try the   finger   command.

     Just note that all of these services imply some security 
and or privacy vulnerabilities at the distant site, so many have
turned them off.  But a lot have not!

     Failing that, all you can do is send a test message and see
if it "bounces."

-als


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

Date: Fri, 17 Jul 1998 14:42:06 -0500
From: Yong Huang <yong@shell.com>
To: Dave Radin <radin@ews.uiuc.edu>
Subject: Re: regexp help?
Message-Id: <35AFA90D.BE634BB7@shell.com>

This is very interesting. My script below manually deals with the commas in
quotes. They're changed to triple commas as an example.

#!perl -w
#I use Perl for Win95. So there's no path after #!. But I want the -w switch.

open(IN, "file.txt");

while (<IN>)
 { #s/\G(".+?),(.+?")/$1,,,$2/g;    #Hope somebody can make this work. I
can't.

   $lngth = @tmp = split /"/;

   for ($i=0; $i<$lngth; $i++)
    { if ($i%2!=0)    #find the string in quotes; they're after odd number of
" 's
       { $tmp[$i] =~ s/,/,,,/g;
       }
    }

   print join("",@tmp);
 }

close IN;


Dave Radin wrote:

> Hi all. I'm kind of new to Perl, and I was wondering if anyone could help
> with this. I'm trying to match any commas that appear within quotes in a
> string. For example,
>
> ,"Radin, Dave",   --> match the comma right after 'Radin'
> ,"gold, silver, bronze",   -> match the commas after gold and silver
> ,"blue, red, orange",nothing,something,"Radin, Dave" --> match after blue,
> red, and Radin
>
> I've tried this:
> open(IN, "file.txt");
> open(OUT,">out.txt");
> while (<IN>)
> {
>  s/(".+),(.+")/$1,,$2/g;
>  print OUT $_;
>
> }
>
> but it doesn't work...con anyone help, please?
>
> Thanks...





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

Date: Fri, 17 Jul 1998 19:14:01 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Return value of eval()
Message-Id: <35AFA40E.3BC1@min.net>

Vladimir Livshits wrote:
> 
> Hi Steve. So this is what I am trying to do:
> 
> I am trying to create a method that would allow calling arbitrary pieces of code
> (even rm *)
> from JavaScript and I want to grab the return value of that. 

I think there's a little conceptual problem here.
"Arbitrary code" -> "the return value".
How can you say what "the return value" might be, or even that
there will be one?
If the arbtrary code is "rm *", well, that's not perl.
If you execute it from perl, then its result is in $?.
That's obviously different than "1 + 2".

The long and short of it is, you need a protocol for communcating
results back to your script.  You could define a global ref var,
say $RESULT, and let the code assign it a ref of any type.
But whatever you do, it will be up to you to enforce the protocol.
Using my example protocol, the following would work:

	$code = 'rm *; $RESULT = \( $? )';
	$code = '$RESULT = [ gmtime ]';

After each one, you would test ref($RESULT_REF), and take action
accordingly.  (Of course, before each one, you'd reset $RESULT to
undef.)

hth,
John Porter


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

Date: Fri, 17 Jul 1998 14:31:49 -0400
From: "Mark Stang" <markstang@ncgroup.com>
Subject: Which Win32 port should I use?
Message-Id: <6oo5ba$le6$1@usenet1.interramp.com>

I keep seeing reference to the Core version for Win32.  I am currently using
ActiveState. Now Activestate's website seems to be saying that all of these
are going to merge with 5.005.

Now I'm all confused.

Which port should I use?  are they going to be more comaptible after 5.005?
Will ActiveState distribution be using _core_ Perl at that point?

Can anyone enlighten me?





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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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