[18009] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 169 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 29 18:06:00 2001

Date: Mon, 29 Jan 2001 15:05:18 -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: <980809517-v10-i169@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 29 Jan 2001     Volume: 10 Number: 169

Today's topics:
    Re: 'apply' function in perl? (Greg Bacon)
    Re: [OT] What other languages do you know? (Tim Hammerquist)
    Re: [Q] Character / string analysis. <iltzu@sci.invalid>
        accessing name of variable (=?iso-8859-1?Q?J=F6rg?= Ziefle)
        AUTOLOAD an array... tohann@my-deja.com
    Re: AUTOLOAD an array... <kstep@pepsdesign.com>
    Re: Basic string question nobull@mail.com
    Re: Basic string question <godzilla@stomp.stomp.tokyo>
    Re: Basic string question <amonotod@netscape.net>
    Re: Can't use 'pop' as hash key nobull@mail.com
        Cron task jean@ematic.com
    Re: Cron task tohann@my-deja.com
    Re: Dealing with x1b character hparks@my-deja.com
        error message with Win32::API module <jensluetzen@yahoo.de>
    Re: Finding a char in string <amonotod@netscape.net>
    Re: Finding a char in string <godzilla@stomp.stomp.tokyo>
    Re: Finding a char in string <amonotod@netscape.net>
    Re: Finding unused variables ? (Martien Verbruggen)
    Re: Finding unused variables ? <nospam.newton@gmx.li>
        HELP: localtime, days of a month <Nigel_member@newsguy.com>
    Re: HELP: localtime, days of a month (Abigail)
        how do I temporarily close part of my site? <dcs@ntlworld.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 29 Jan 2001 19:32:49 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: 'apply' function in perl?
Message-Id: <t7bhb1c1pm5m84@corp.supernews.com>

In article <t73su35bnu9ef1@corp.supernews.com>,
    Greg Bacon <gbacon@hiwaay.net> wrote:

: In article <3a71ed40$1@news.microsoft.com>,
:     Jürgen Exner <juex@deja.com> wrote:
: 
: : Out of curiosity: would it be possible to somehow use closures for this
: : purpose (or am I way off)?
: 
: Well, sure, but you'd have to do it by hand, and you'd have to play
: funny games to get curried versions of builtins like map and grep.

Compare mjd's example with a language like Ocaml that does currying
for you:

    # let rec reduce f b lst =
        match lst with
          [] -> b
        | h :: t -> f(h, reduce f b t);;
    val reduce : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b = <fun>

If this looks like gobbledygook, then read mjd's typing article[*]
for a gentle introduction to ML.

[*] <URL:http://perl.plover.com/yak/typing/typing.html>

Notice that there are no explicit type declarations; the language
infers them.  Let's decode the various parts of the "val reduce : "
line:

  o val reduce :
      "reduce is ..."
  o = <fun>
      "a function"
  o ('a * 'b -> 'b)
      "a function taking an argument of type 'a and an argument of
       type 'b, returning a value of type 'b"
  o 'a list
      "a list composed of members of type 'a"

Think of -> as separating the domain from the range, like in formal
mathematical notation.  (Similarly, 'a * 'b -> 'b is like f : A x B -> B
where x is the Cartesian product.)  The -> operator associates to the
right: reduce take a function and returns a function that takes a 'b
and returns a function that take an 'a list and returns a 'b.  Of
course, you don't have to grind through every step; it's perfectly
acceptable to think of reduce as a function that takes a function, a
base value, and a list and then returns a single value.

Type inference helps you debug your code.  Here is my initial
implementation of reduce:

    # let rec reduce f b lst =
        match lst with
          [] -> []
        | head :: tail -> f(head, reduce f b tail);;
    val reduce : ('a * 'b list -> 'b list) -> 'c -> 'a list -> 'b list = <fun>

That says reduce returns a list.  The problem of course, is that I
return the empty list for the empty list ([] -> []) instead of the base
value ([] -> b from the earlier code).

Anyway, to see currying at work:

    # let reduce_sum = reduce (function (a,b) -> a+b);;
    val reduce_sum : int -> int list -> int = <fun>
    # reduce_sum 0 [1; 2; 3];;
    - : int = 6
    # reduce_sum 1 [1; 2; 3];;
    - : int = 7
    # let sum = reduce_sum 0;;
    val sum : int list -> int = <fun>
    # sum [4; 5; 6; 7];;
    - : int = 22

Greg


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

Date: Mon, 29 Jan 2001 20:28:57 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: [OT] What other languages do you know?
Message-Id: <slrn97bkvb.t8.tim@degree.ath.cx>

Mario <m_ario@my-deja.com> wrote:
> Just curious to know what other languages are popular in the Perl
> community.

Perl
Python
C/C++
(and I've recently been looking into Pike)

Less preferable but often used:
sh

Used only when necessary:  =)
DOS Batch files (.BAT)

-- 
-Tim Hammerquist <timmy@cpan.org>

I don't have any solution, but I certainly admire the problem.
	-- Ashleigh Brilliant


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

Date: 29 Jan 2001 19:43:14 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: [Q] Character / string analysis.
Message-Id: <980796305.4968@itz.pp.sci.fi>

In article <Pine.A41.4.21.0101191655120.18502-100000@dante39.u.washington.edu>, Anshuman Pandey wrote:
>
>To illustrate what I mean, take, for example, the string "abcd", of which 
>there are 8 possible linear combinations:
>
>	A+B+C+D	(3 dividers)
>	A+B+CD  (2 dividers)
>	A+BC+D
>	AB+C+D
>	A+BCD   (1 divider)
>	AB+BC
>	ABC+D
>	ABCD    (0 dividers)

  my @chars = split //, "ABCD";
  for my $n (0 .. (1 << $#chars) - 1) {
      print map($chars[$_] . ($n & 1<<$_ ? "+" : ""), 0 .. $#chars), "\n";
  }

This will not work for arrays that have more than 31 elements on most
systems, but by then you'll be having other problems dealing with all
the 2147483648 possible combinations.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"I imagine that getting the crack of your ass vacuum-burned would put the
 world's worst case of hemorrhoids to shame!"  -- Charles Martin in rasfs

Please ignore Godzilla and its pseudonyms - do not feed the troll.


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

Date: 29 Jan 2001 22:52:08 GMT
From: gt4556a@acmez.gatech.edu (=?iso-8859-1?Q?J=F6rg?= Ziefle)
Subject: accessing name of variable
Message-Id: <slrn97bt0o.fe.gt4556a@acmez.gatech.edu>

Just curious:

Is it possible (with globs, ...) to directly access the name of a
variable?  For instance, when I have a scalar named $foo, the operation
would give me the string 'foo', that is, the name of $foo stringified.

An application could be to facilitate the Data::Dumper->Dumper calls with
arbitrary variables (in a loop).
-- 
Jörg Ziefle


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

Date: Mon, 29 Jan 2001 19:36:54 GMT
From: tohann@my-deja.com
Subject: AUTOLOAD an array...
Message-Id: <954gok$b1h$1@nnrp1.deja.com>

Hello.  I'm relatively new to the Perl Object Oriented programming
world, and I seem to have a pretty basic question.
Here's the problem I'm seeing.  I have an object with 10 or so
variables.  Most of the variables are regular scalars, with 2 arrays.  I
load the object's first array with a fully populated tmp array
containing 1-9 elements.  But whenever I try to access the array from
the object, I only get the first element of the array.  Here's the
object's .pm in it's entirety:

package package1;

use Carp;

my %fields = {
    field1=>undef,
    field2=>undef,
    field3=>undef,
    ...
    array1=>undef,
    array2=>undef,
    };

sub new {
  my $that = shift;
  my $class = ref($that) || $that;
  my $self = {
              _permitted => \%fields,
              %fields,
             };
  bless $self, $class;
  return $self;
}

sub AUTOLOAD {
  my $self = shift;
  my $type = ref($self) || croak "$self is not an object!!";
  my $name = $AUTOLOAD;
  $name =~ s/.*://;
  #
  if (@_) {
    return $self->{$name} = shift;
  } else {
    return $self->{$name};
  }
}

I've done some searching on objects containing arrays, but I've come up
with nothing so far.  Any help would be appreicated.

Thanks in advance,
Trent O.


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 29 Jan 2001 16:44:02 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: AUTOLOAD an array...
Message-Id: <954o2r$ihs$1@slb6.atl.mindspring.net>

<tohann@my-deja.com> wrote in message news:954gok$b1h$1@nnrp1.deja.com...
> Hello.  I'm relatively new to the Perl Object Oriented programming
> world, and I seem to have a pretty basic question.
> Here's the problem I'm seeing.  I have an object with 10 or so
> variables.  Most of the variables are regular scalars, with 2 arrays.  I
> load the object's first array with a fully populated tmp array
> containing 1-9 elements.  But whenever I try to access the array from
> the object, I only get the first element of the array.  Here's the
> object's .pm in it's entirety:

I'll call e'm as I see 'em....

> package package1;
>
> use Carp;

How about 'use strict' as well.

> my %fields = {
>     field1=>undef,
>     field2=>undef,
>     field3=>undef,
>     ...
>     array1=>undef,
>     array2=>undef,
>     };

Use (a => 1) for your hashes, {a => 1} for hash references.

> sub new {
>   my $that = shift;
>   my $class = ref($that) || $that;
>   my $self = {
>               _permitted => \%fields,
>               %fields,
>              };
>   bless $self, $class;
>   return $self;
> }

Here's where the problem starts.  When you copy %fields to the soon-to-be
blessed $self, you are copying a bunch of undefined scalar elements.  Your
autoloaded code below has no way of knowing that array1 and array2 should
contain array references.  Make that so....

sub new {
    my $that = shift;
    my $class = ref($that) || $that;
    my $self = {
        _permitted => \%fields,
        %fields,
    };

    # Tell AUTOLOAD what to expect
    $self->{array1} = [];
    $self->{array2} = [];

    bless $self, $class;
    return $self;
}

> sub AUTOLOAD {
>   my $self = shift;
>   my $type = ref($self) || croak "$self is not an object!!";
>   my $name = $AUTOLOAD;
>   $name =~ s/.*://;
>   #
>   if (@_) {
>     return $self->{$name} = shift;

Ah, heres the problem....  When you pass in an array, shift() takes the
first element and stores it in the object's hash.  When you retrieve it,
that's all your going to get back.

>   } else {
>     return $self->{$name};
>   }
> }

Before going any further, you should consider what kind of access behavior
you want from the array members.  Should AUTOLOAD expect to see a list of
values or an array reference?  How should the values be passed back?  You
may decide that you can provide a richer and more useful interface if you
provide explicit methods to access the array members, i.e. add_element,
remove_element, push_element, etc.  Of course, you could still use AUTOLOAD
to construct the array members and return them in their entirety.

The code below is a rework of your program that accepts a list of values in
@_ and uses the default return behavior to retrieve a copy of the array
members.

<< BEGIN CODE >>
use strict;
use warnings;

package package1;

use Carp;
# use vars qw($AUTOLOAD); # For perl bersion < 5.6

our %fields = (
    scalar1=>undef,
    scalar2=>undef,
    array1=>undef,
    array2=>undef,
);

our $AUTOLOAD; # For perl bersion >= 5.6

sub new {
    my $proto = shift;
    my $class = ref($proto ) || $proto ;
    my $self = {
        _permitted => \%fields,
        %fields,
    };
    # Tell AUTOLOAD what to expect
    $self->{array1} = [];
    $self->{array2} = [];
    bless $self, $class;
    return $self;
}

sub AUTOLOAD {
    my $self = shift;
    my $type = ref($self) || croak "$self is not an object!!";
    my $name = $AUTOLOAD;
    $name =~ s/.*://;

    croak "Unknown method $AUTOLOAD() called"
        unless exists $self->{_permitted}->{$name};

    if (ref($self->{$name}) eq 'ARRAY') {
        # Handle arrays
        $self->{$name} = [@_] if @_;
        return @{$self->{$name}};
    }
    else {
        # Handle scalars
        return $self->{$name} = shift() if @_;
        return $self->{$name};
    }
}

# Prevent AUTOLOAD from croaking on DESROY
sub DESTROY {}

package main;

$|=1; # Autoflush output

my $p1 = new package1;

$p1->scalar1('foo');
print "\$p1->scalar1() = '", $p1->scalar1, "'\n";

my $p2 = new package1;

$p2->scalar1('bar');
print "\$p1->scalar1() = '", $p1->scalar1, "'\n";
print "\$p2->scalar1() = '", $p2->scalar1, "'\n";

$p1->array1('Charlie', 'Lucy', 'Linus', 'Pigpen');
print "\$p1->array1() = (";
print join ', ', map { "'$_'" } $p1->array1;
print ")\n";

$p2->array1('Stan', 'Eric', 'Kyle', 'Kenny');
print "\$p2->array1() = (";
print join ', ', map { "'$_'" } $p2->array1;
print ")\n";

$p1->foo;    # Croak here

<< END CODE >>

HTH,

Kurt Stephens





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

Date: 29 Jan 2001 18:53:06 +0000
From: nobull@mail.com
Subject: Re: Basic string question
Message-Id: <u9zogaur59.fsf@wcl-l.bham.ac.uk>

"Godzilla!" <godzilla@stomp.stomp.tokyo> writes:

> nobull@mail.com wrote:
> 
> > Some time ago before our resident troll's recent sebattical
> 
> If I am truly the troll, why are you trolling me, in this
> article and other blatant troll articles of yours?

Because I'm weak-willed.  The correct response to a troll is to ignore
them - but sometimes I slip into troll-baiting.
  
> > In fact I can only find two (fairly minor) ways to fault it.
> 
> > More inportantly it failed to point out 
> 
> 
> I am not an "it" as you and others state.

Astute readers will note although I _do_ use the pronoun "it" or more
to refer to Godzilla[1], the "it" in the quoted text refers to Godzilla's
response not Godzilla herself.

Actually I usually use she/he/it - sometimes abbreviated to s/h/it.
(Don't blame me, I didn't invent the abrviation).

I do this because if one signs oneself using a name like "Godzilla" or
"NoBull" the common interpretation is that one is acting as a
character of ones own invention, and that this character is not
necessarily of the same gender as the actor or even necessarily
gendered at all.

If you want to be treated as gendered then call yourself Kira.

While I call myself "NoBull" and not "Brian" I'm quite happy to be
referred to by the pronoun "it" or "s/h/it".

> I am a female human...

[snip random semi-coherent, theist, bigoted ranting against men and
people with disabilites]

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


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

Date: Mon, 29 Jan 2001 12:19:15 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Basic string question
Message-Id: <3A75D043.2912847B@stomp.stomp.tokyo>

nobull@mail.com wrote:
 
> "Godzilla!" <godzilla@stomp.stomp.tokyo> writes:
> > nobull@mail.com wrote:

(snipped with a barnyard shovel)

              ( )
    ==\  __ __[oo
       \/     /\@
   ##   l_____|
  ####   ll  ll
 ######  LL  LL


Godzilla!


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

Date: Mon, 29 Jan 2001 22:03:37 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Basic string question
Message-Id: <954pbi$jgo$1@nnrp1.deja.com>

In article <3A75D043.2912847B@stomp.stomp.tokyo>,
  "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
>
>               ( )
>     ==\  __ __[oo
>        \/     /\@
>    ##   l_____|
>   ####   ll  ll
> Godzilla!LL  LL

There, that's better...

amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com
http://www.deja.com/


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

Date: 29 Jan 2001 19:16:39 +0000
From: nobull@mail.com
Subject: Re: Can't use 'pop' as hash key
Message-Id: <u9r91muq20.fsf@wcl-l.bham.ac.uk>

oakbox@my-deja.com writes:

> I tried to use the word 'pop' as a key in a hash,

You are not analysing your problem correctly.   

You tried to use 'pop' it as a bareword string constant in a list.
The fact that you put that list into an array and at some later stage
tried to use the elements of that array as a keys of a hash is
irrelevant.

> Are their reserved words that cannot be hash keys?

No, but in older versions of Perl $fields{pop} is interpreted as
$fields{pop()} rather than $fields{'pop'}.  This is probably what you
are vaguely recalling,

Put "use strict" at the top of your script to disable bareword string
contants altogether and you will not have this problem again.

> @key_vals=(name,address,phone,pop);

Should be:

@key_vals=('name','address','phone','pop');

Or 

@key_vals=qw( name address phone pop );

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


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

Date: 29 Jan 2001 18:55:49 -0000
From: jean@ematic.com
Subject: Cron task
Message-Id: <SQ5R8T0J36920.8304282407@frog.nyarlatheotep.org>

Hi,

Using Telnet to connect on my remote server, I run a script by:

perl script.cgi [options]

Now, I want run "script.cgi" in a cron task, must I setup crontab with:
(for every days at 7 AM)

0 7 * * * /path/to/perl script.cgi [options]

Or must I write 
0 7 * * * /path/to/script.cgi [options]

Or rename script.cgi to script, and setup the task as

0 7 * * * /path/to/script [options]



Thanks !
Jean




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

Date: Mon, 29 Jan 2001 20:30:53 GMT
From: tohann@my-deja.com
Subject: Re: Cron task
Message-Id: <954jtu$e2r$1@nnrp1.deja.com>

In article <SQ5R8T0J36920.8304282407@frog.nyarlatheotep.org>,
  jean@ematic.com wrote:
> Hi,
>
> Using Telnet to connect on my remote server, I run a script by:
>
> perl script.cgi [options]
>
> Now, I want run "script.cgi" in a cron task, must I setup crontab
with:
> (for every days at 7 AM)
>
> 0 7 * * * /path/to/perl script.cgi [options]
>
> Or must I write
> 0 7 * * * /path/to/script.cgi [options]
>
> Or rename script.cgi to script, and setup the task as
>
> 0 7 * * * /path/to/script [options]
>
> Thanks !
> Jean
>
>

The 1st option will work, and the 2nd will too assuming the script.cgi
has the correct permissions set...



Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 29 Jan 2001 19:00:48 GMT
From: hparks@my-deja.com
Subject: Re: Dealing with x1b character
Message-Id: <954ekp$8qi$1@nnrp1.deja.com>

In article <RFmc6.32550$I9.2306317@news5.aus1.giganews.com>,
  "Jay Flaherty" <fty@mediapulse.com> wrote:
> Looks like Mark Jason Dominus already answered your question so the
problem
> does not remain anymore. i.e. look at the binmode() function.

You are correct.   binmode(INFILE) allows the program to continue past
the embedded ctrl-z character.


Howard Parks
1 Peter 4:10


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 29 Jan 2001 20:08:57 +0100
From: Jens Luetzen <jensluetzen@yahoo.de>
Subject: error message with Win32::API module
Message-Id: <3A75BFC9.7B701AA7@yahoo.de>

Hello all,

I would like to use the Win32:api module with perl and it looks as if
everything was installed properly (build 6.0.23) but whenever I call the
module it gives back an error message that reads:

can't locate loadable object for module Win32:API in @INC (@INC
contains: y:/perl/lib y:/perl/site/lib .) at D:\perlscripts}api1.pl line
1
Compilation failed in require at D:\perlscripts api1.pl line 1

I checked and the module requires "Exporter" and "DynaLoader". The error
message seems to be caused by the latter since whenever uncommenting, it
doesn't complain (but obviously the script doesn't work the way it
should). I tried copying the DynaLoader.pm into every directory possible
without this alleviating the problem.

Can anyone give me a hint?

Any help is greatly appreciated,

thanks very much in advance,

Jens

jensluetzen@yahoo.de



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

Date: Mon, 29 Jan 2001 20:09:07 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Finding a char in string
Message-Id: <954ikq$cqf$1@nnrp1.deja.com>

In article <3A7443C5.43E1EA11@stomp.stomp.tokyo>,
  "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> Mark Jason Dominus wrote:
> > >A substring method for this case example is significantly
> > >faster,
>
> > That does not appear to be true.
>
> > My earlier benchmark was in error.  I was benchmarking
>
> > The conclusion of my article is the same however.  An amended
> > version follows.  My apologies for any confusion.
>
> My benchmark results made prior to posting
> my initial article directly contradict your
> own results.

Believe it or not, but moronzilla appears to be correct... At least, the
code included below endorses her claim (unfortunately... :-< ).  I
tested with some pseudo-random input, generated at the beginning of the
script...

(See code below)
Benchmark: timing 1000 iterations of test1, test2...
     test1: 55 wallclock secs (49.16 usr +  5.31 sys = 54.47 CPU)
     test2: 61 wallclock secs (54.26 usr +  5.46 sys = 59.72 CPU)

However, there is a bug in moronzilla's code... Each time I ran it, if
the input line did not have a semi-colon, the last character was lopped
off.  To test it, just change "for (my $y = 1" to a value greater than
1, say... 150, so that any lines where the semicolon would have been
within the first 150 chars, have no semicolon.

Now, if you fix the bug, say with a grep() (Instead of m///, since the
arguement is against regex's.), moronzilla's code takes longer...

Benchmark: timing 1000 iterations of test1, test2...
     test1: 71 wallclock secs (64.09 usr +  5.67 sys = 69.76 CPU)
     test2: 61 wallclock secs (54.01 usr +  5.59 sys = 59.60 CPU)

but the difference really is quite negligible, considering the size of
the input lines, and the number of iterations.  Plus, it seems that if
the input lines are shorter (I tested with "$lngth = int(rand 1000);"
and "$lngth = int(rand 100);")  then the substr() method is
significantly faster:

Benchmark: timing 1000 iterations of test1, test2...
     test1: 68 wallclock secs (59.41 usr +  7.44 sys = 66.84 CPU)
     test2: 87 wallclock secs (77.26 usr +  8.76 sys = 86.02 CPU)

And slightly faster, even with the grep();
Benchmark: timing 1000 iterations of test1, test2...
     test1: 86 wallclock secs (75.40 usr +  8.95 sys = 84.35 CPU)
     test2: 89 wallclock secs (78.23 usr + 10.02 sys = 88.25 CPU)


> Fortunately, I am careful enough
> to attain correct results based on unbiased
> data under strict controls, from the get go.

Now what the hell that was, I just don't know.  Why the hell does
moronzilla include that kind of crap in it's posts? "Blah freaking blah
blah blah" is all I get out of it...


>
> Godzilla!
>

Guess I'll run DiskKeeper now...
amonotod



Code without the grep function:
#!perl -w
use strict;
use Benchmark;
my (@chararray, $char, $string, $newstring, @stringarray, $comment);
for (my $x = 65; $x < 91; $x++) { push @chararray, chr($x); }
for (my $x = 97; $x < 123; $x++) { push @chararray, chr($x); }
push @chararray, ';';
for (my $x = 1; $x < 5000; $x++) {
  $string = '';
  my $lngth = 0;
  while ($lngth < 15) { $lngth = int(rand 1000); }
  $comment = int(rand $lngth);
  for (my $y = 1; $y <= $lngth; $y++) {
    if ($y == $comment ) { $char = 52; }
    else { $char = int(rand 51); }
    $string .= $chararray[$char];
  }
  push @stringarray, $string;
}
open (ASMCODE, "> text.asm");
foreach $string (@stringarray) { print ASMCODE "$string\n"; }
close (ASMCODE);
timethese (1000, { 'test1' => \&SUB_STR, 'test2' => \&REGEX } );
exit;
sub SUB_STR {
  open (ASMCODE, "<text.asm");
  open (ASMSAVE, "> text.asm_substr");
  while (<ASMCODE>) {
    chomp;
    $string = $_;
    $string = substr ($string, 0, index ($string, ";"));
    print ASMSAVE "$string \n";
  }
  close (ASMCODE);
  close (ASMSAVE);
}
sub REGEX {
  open (ASMCODE, "< text.asm");
  open (ASMSAVE, "> text.asm_regex");
  while (<ASMCODE>) {
    chomp;
    $string = $_;
    $string =~ s/;.*//s;
    print ASMSAVE "$string \n";
  }
  close (ASMCODE);
  close (ASMSAVE);
}



Code with the grep function:
#!perl -w
use strict;
use Benchmark;
my (@chararray, $char, $string, $newstring, @stringarray, $comment);
for (my $x = 65; $x < 91; $x++) { push @chararray, chr($x); }
for (my $x = 97; $x < 123; $x++) { push @chararray, chr($x); }
push @chararray, ';';
for (my $x = 1; $x < 5000; $x++) {
  $string = '';
  my $lngth = 0;
  while ($lngth < 15) { $lngth = int(rand 1000); }
  $comment = int(rand $lngth);
  for (my $y = 1; $y <= $lngth; $y++) {
    if ($y == $comment ) { $char = 52; }
    else { $char = int(rand 51); }
    $string .= $chararray[$char];
  }
  push @stringarray, $string;
}
open (ASMCODE, "> text.asm");
foreach $string (@stringarray) { print ASMCODE "$string\n"; }
close (ASMCODE);
timethese (1000, { 'test1' => \&SUB_STR, 'test2' => \&REGEX } );
exit;
sub SUB_STR {
  open (ASMCODE, "<text.asm");
  open (ASMSAVE, "> text.asm_substr");
  while (<ASMCODE>) {
    chomp;
    $string = $_;
    if (grep $string, ';') { $string = substr ($string, 0, index
($string, ";")); }
    print ASMSAVE "$string \n";
  }
  close (ASMCODE);
  close (ASMSAVE);
}
sub REGEX {
  open (ASMCODE, "< text.asm");
  open (ASMSAVE, "> text.asm_regex");
  while (<ASMCODE>) {
    chomp;
    $string = $_;
    $string =~ s/;.*//s;
    print ASMSAVE "$string \n";
  }
  close (ASMCODE);
  close (ASMSAVE);
}

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 29 Jan 2001 12:36:33 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Finding a char in string
Message-Id: <3A75D451.DAEA43BC@stomp.stomp.tokyo>

amonotod wrote:
 
>  Godzilla! wrote:
> > Mark Jason Dominus wrote:

> > > >A substring method for this case example is significantly
> > > >faster,

> > > That does not appear to be true.

> > > My earlier benchmark was in error.  I was benchmarking

> > > The conclusion of my article is the same however.  An amended
> > > version follows.  My apologies for any confusion.

> > My benchmark results made prior to posting
> > my initial article directly contradict your
> > own results.
 
> Believe it or not, but moronzilla appears to be correct... At least, the
> code included below endorses her claim (unfortunately... :-< ).


(snipped intellectually insulting tests)


Neither you nor Dominus are intellectually qualified
to conduct valid scientific inquiries and experiments.
Your methodologies and results are just as erroneous.

Godzilla!


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

Date: Mon, 29 Jan 2001 21:26:04 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Finding a char in string
Message-Id: <954n4v$hbb$1@nnrp1.deja.com>

In article <3A75D451.DAEA43BC@stomp.stomp.tokyo>,
  "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> amonotod wrote:
>
> >  Godzilla! wrote:
> > > Mark Jason Dominus wrote:
>
> > > > >A substring method for this case example is significantly
> > > > >faster,
>
> > > > That does not appear to be true.
>
> > > > My earlier benchmark was in error.  I was benchmarking
>
> > > > The conclusion of my article is the same however.  An amended
> > > > version follows.  My apologies for any confusion.
>
> > > My benchmark results made prior to posting
> > > my initial article directly contradict your
> > > own results.
>
> > Believe it or not, but moronzilla appears to be correct... At least,
> > the code included below endorses her claim (unfortunately... :-< ).
>
> (snipped intellectually insulting tests)
Okay, whatever... Tests that validated the claims made by moronzilla,
and in no way *intellectually* insulted anyone.

>
> Neither you nor Dominus are intellectually qualified
> to conduct valid scientific inquiries and experiments.
There is no absolute minimum intelligence requirment for conducting
scientific experiments.  Every day, single celled organisms conduct germ
warfare experiments on your immunological system, with absolutely no
"intelligence" at all.

> Your methodologies and results are just as erroneous.
Erroneous as what?  Your previous statement?  Whatever...

I am now convinced that moronzilla's sabatical was spent in a Perl
language/programming class.  However, I think the time would have been
much better spent if moronzilla were in a psychological assessment and
treatment center.

>
> Godzilla!
>

I believe that I actually spent time vindicating (accidently, but it
still happened) moronzilla, just to have insults heaped upon me.  Once a
troll, always a troll.

Back to the bit bucket...
amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 29 Jan 2001 21:56:26 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Finding unused variables ?
Message-Id: <slrn97bpmd.mbo.mgjv@verbruggen.comdyn.com.au>

On Mon, 29 Jan 2001 11:36:13 +0800,
	John Lin <johnlin@chttl.com.tw> wrote:
> "Abigail" wrote
>> John Lin wrote
> 
>> our() is weird, confusing, and should be avoided.
> 
> One day I found my code can be trimmed cleaner:
> 
> use strict;
> use Exporter;
> use vars '@ISA @EXPORT';
> @ISA = ('Exporter');
> @EXPORT = ('PI');
> 
> becomes
> 
> use strict;
> use base 'Exporter';
> our @EXPORT = ('PI');

@Classname::EXPORT = ('PI');

> I don't know whether I should thank to "our" or hate "use strict".

Thank strict. While my feelings about our aren't as stong as
Abigail's, I don't really find it a very useful addition to the
language either. And I do agree that it unnecessarily complicates the
issues of scoping. I still prefer 'use vars' above 'our', because I
feel it expresses much more clearly that the variables are package
globals. Besides that, it makes code compile better on version
5.005_03 of Perl. If only it hadn't been 'our', but something else.

Martien
-- 
Martien Verbruggen                      |
Interactive Media Division              | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Mon, 29 Jan 2001 23:41:51 +0100
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: Finding unused variables ?
Message-Id: <89rb7tgu6dmuah1g0600l42p4u4nee9hsq@4ax.com>

On Mon, 29 Jan 2001 11:36:13 +0800, "John Lin" <johnlin@chttl.com.tw> wrote:

> use vars '@ISA @EXPORT';

ITYM use vars qw'@ISA @EXPORT';

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 29 Jan 2001 12:34:14 -0800
From: Nigel <Nigel_member@newsguy.com>
Subject: HELP: localtime, days of a month
Message-Id: <954k4602s48@drn.newsguy.com>

I hope someone can help me here.

I need to find out how many days there are in a given month. I tried doing this:

$epoch_seconds_1 = (0,0,0,0,$month1,$year);
$epoch_seconds_2 = (0,0,0,0,$month2,$year);

$days = ($epoch_seconds_2  - $epoch_seconds_1) / (24 * 60 * 60);

But this returns something like this:

28 -12345

How can I get a simple number of days?

Thanks,
Nigel



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

Date: 29 Jan 2001 21:55:46 GMT
From: abigail@foad.org (Abigail)
Subject: Re: HELP: localtime, days of a month
Message-Id: <slrn97bpn2.bf7.abigail@tsathoggua.rlyeh.net>

Nigel (Nigel_member@newsguy.com) wrote on MMDCCVIII September MCMXCIII in
<URL:news:954k4602s48@drn.newsguy.com>:
;; I hope someone can help me here.
;; 
;; I need to find out how many days there are in a given month. I tried doing this:
;; 
;; $epoch_seconds_1 = (0,0,0,0,$month1,$year);
;; $epoch_seconds_2 = (0,0,0,0,$month2,$year);


That would make $epoch_seconds_1 and $epoch_seconds_2 equal to $year.

;; $days = ($epoch_seconds_2  - $epoch_seconds_1) / (24 * 60 * 60);
;; 
;; But this returns something like this:
;; 
;; 28 -12345

Really? You do simple arithmetic, in a single expression, and you end up
with *two* numbers? Your Perl must be truely broken!

;; How can I get a simple number of days?


Easy.

    my $days = {
        April     => sub {30},
        August    => sub {31},
        December  => sub {31},
        February  => sub {28 + ($_ [0] % 400 ? 0 :  1) +
                               ($_ [0] % 100 ? 0 : -1) +
                               ($_ [0] %   4 ? 0 :  1)},
        January   => sub {31},
        July      => sub {31},
        June      => sub {30},
        March     => sub {31},
        May       => sub {31},
        November  => sub {30},
        October   => sub {31},
        September => sub {30},
    };

And then call it like:

    my $year  =  2001;
    my $month = 'January';

    printf "$month $year counts %d days.\n" => $days -> {$month} -> ($year);


Abigail

-- 
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s};;;
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};                # Perl 5.6.0 broke this...
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))


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

Date: Mon, 29 Jan 2001 22:53:01 -0000
From: "Terry" <dcs@ntlworld.com>
Subject: how do I temporarily close part of my site?
Message-Id: <pvmd6.6940$cD2.232555@news2-win.server.ntlworld.com>

Hi,

 There will be times when I will need to modify cgi scripts, member stats
etc. on my site.
I know that I can change the .htaccess file to deny access to these areas
(and this is what my host suggests I do). My problem with this is: wouldn't
that run the risk of corrupting my files if a user's input was modifying a
file or files at the time?

 If I'm wrong you can cut me off there.
Assuming I'm correct, I was going to upload a small text file with only the
word open or closed in it, then have my scripts first check this file before
performing their normal tasks (or not, if it was "closed"). But I would
still need to check that no sensitive files were open at the time, so would
have to go through a series of opening and "flocking" these files before
shutting off access.
Now, eventually, to my main problem.
As new users join my site they generate new member files, so I have no way
of knowing the names of the files to flock.

 Is there someway I can get a listing of these files and use that list for
the opening and "flocking"?

 I don't know the command (if there is one) so I'll call it "dir" to show
what I want

     chomp (my @filelist = <"dir: /members/*.*">);   #to get list of files.
         for ($i=0; $i<=$#filelist) {
             $thisfile = $filelist[$i];
             $filename = "filenumber".$i;        #give each file a unique
name.
             $filepath = "/members/".$thisfile;
             open ($filename,  $filepath);
                 flock $filename;
         }
         open (CHK, "checkfile.txt");
              truncate (CHK, 0);
             print CHK, "closed\n";
         close (CHK);
         for ($i=0; $i<=$#filelist) {
             $filename = "filenumber".$i;        #get each unique name.
             close ($filenum);
         }

 Does this seem reasonable?
If so what is the "dir" command and what exactly does it return?

 Sorry for the long post and thanks for any help you can give,

 TM




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

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 V10 Issue 169
**************************************


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