[16941] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4353 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 18 00:05:32 2000

Date: Sun, 17 Sep 2000 21:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <969249907-v9-i4353@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 17 Sep 2000     Volume: 9 Number: 4353

Today's topics:
    Re: Annoying quotation marks! (Gwyn Judd)
        Combine/Improve several  scripts <jacobmj@geocities.com>
    Re: find the number of characters in a string <bliles@bigup.shacknet.nu>
    Re: find the number of characters in a string <bwalton@rochester.rr.com>
    Re: Getting started w/ Perl (Perl in windows) newbie  (JoeCoolCols)
    Re: Getting started w/ Perl (Gwyn Judd)
    Re: Graphical Perl?? <bliles@bigup.shacknet.nu>
        Is there a DBI that will connect to MS SQL Server? zirconx@my-deja.com
    Re: Just curious.. <halo_five@my-deja.com>
    Re: Recipe For Sorting LoL (Martien Verbruggen)
    Re: Recipe For Sorting LoL andre_sanchez@my-deja.com
    Re: RunJava script from MS Explorer problem (Gwyn Judd)
    Re: shtml on-the-fly (Tony L. Svanstrom)
    Re: Teaching Perl (Norman Gaywood)
    Re: Teaching Perl <phil@BuxTech.Com>
    Re: Using range operator (Gwyn Judd)
    Re: Using range operator <godzilla@stomp.stomp.tokyo>
    Re: Using range operator <jeffp@crusoe.net>
    Re: Using range operator <randy_734@my-deja.com>
    Re: Why does * in a string glob? (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 18 Sep 2000 01:11:13 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Annoying quotation marks!
Message-Id: <slrn8saqte.ego.tjla@thislove.dyndns.org>

I was shocked! How could Tigz <tigz@ntlworld.com>
say such a terrible thing:
>Thanks evryone I have sorted the fonts out now :)
>
>But i require to change the "Send!" and "logoff" buttons, in to text link,
>how could i do this?

These questions are all off-topic for this group. Just because you wrote
your CGI program in Perl doesn't make what you have a Perl problem.
Imagine if you had written your program in C, COBOL or BASIC, the
questions you have and the answers would be basically the same. This
makes yours a CGI problem, not a Perl problem. I think if you ask this
in a group with "CGI" in the name then you will have more success
(comp.infosystems.www.authoring.cgi comes to mind).

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Q:	Why do mice have such small balls?
A:	Very few of them know how to dance!


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

Date: Sun, 17 Sep 2000 17:44:58 -0700
From: "Jacob Joseph" <jacobmj@geocities.com>
Subject: Combine/Improve several  scripts
Message-Id: <ssastptme9urf8@corp.supernews.com>

Hello everyone.  Let me just start by saying I'm a complete newbie with
perl.  I have read quite a bit of documentation to get this far, and it is
my hope you people will be able to help me out a little.

The purpose of these scripts is to monitor my /var/log/messages syslog and
act when an ISDN router logs a change of line state.  "monitor" watches the
syslog.  "gotmail" checks another user's hotmail account.  "connected"
brings up a VPN and runs fetchmail for me.  I would like to streamline what
I've got into one script.  It currently is all separate because everything
needs to run concurrently.  Also, I do not like the method of monitoring the
syslog.  I read in the docs about another method, but I'm not clear.  It
seems that what I've got is not reliable.  Every one and a while, it will
not 'see' the connection going up and thus will not run anything.

Here are the scripts...

Monitor:

#!/usr/bin/perl
open (MESSAGE, "tail -f /var/log/messages |");
while(<MESSAGE>)
{
  if (/gateway ASCEND/)
        {
        if (/slot 2 port 1, LAN session up/)
                {
                system("/etc/sysconfig/network-scripts/connected&");
                system("/etc/sysconfig/network-scripts/gotmail&");
                }
        if (/slot 2 port 1, LAN session down/)
                {
                system("/etc/sysconfig/network-scripts/goingdown&");
                system("killall gotmail&");
                }
        if (/slot 0 port 0, LAN session down/)
                {
                system("/etc/sysconfig/network-scripts/goingdown&");
                system("killall gotmail&");
                }
        }
}
close MESSAGE;




Connected:
#!/bin/sh
# Run fetchmail as november
su november -c "fetchmail -a -d 420"

# Cipe
ciped-cb
route add -net 10.0.0.0/24 gw 10.0.0.254



Gotmail(the worst script):

#!/usr/bin/perl
open (FILE, "/etc/sysconfig/network-scripts/chat-ppp0");
while (<FILE>)
# This is the only way I could figure out to get the script to loop.  I
couldn't find anything in the logs specific to my purpose.
{
if (/ABORT/)
        {
        system ('su joslyn -c "cd /home/joslyn/;./gotmail.pl"');
        sleep 420;
        redo
}
}



And goingdown:
#!/bin/sh
# This script is meant to be run by diald as it is going down.  It goes
# along with the connected script.

su november -c "fetchmail -q"
killall ciped-cb


Again, I have posted in search of help.  I do realize there are much better
methods of accomplishing my needs.  I would appreciate your help in
implementing those methods.

Thanks,
Jacob Joseph




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

Date: Mon, 18 Sep 2000 01:30:40 GMT
From: "Bryan Liles" <bliles@bigup.shacknet.nu>
Subject: Re: find the number of characters in a string
Message-Id: <4fex5.150380$eS6.2013361@news1.rdc1.md.home.com>

In article <8mkps0$t0l$1@nnrp1.deja.com>, jliu34740@my-deja.com wrote:

$len = length($_);

> I have a string defined as follows:
> $_ = "9 of 15 cats are there";
> how do I count the number of letters in the above string?


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

Date: Mon, 18 Sep 2000 02:02:19 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: find the number of characters in a string
Message-Id: <39C577C6.D8E8DC85@rochester.rr.com>

Bryan Liles wrote:
> 
> In article <8mkps0$t0l$1@nnrp1.deja.com>, jliu34740@my-deja.com wrote:
> 
> $len = length($_);
> 
> > I have a string defined as follows:
> > $_ = "9 of 15 cats are there";
> > how do I count the number of letters in the above string?

Well, actually, if it is the number of *letters* the poster wants:

    $number_of_letters=$_=~y/a-zA-Z/a-zA-Z/;

-- 
Bob Walton


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

Date: 18 Sep 2000 01:53:00 GMT
From: joecoolcols@aol.com (JoeCoolCols)
Subject: Re: Getting started w/ Perl (Perl in windows) newbie 
Message-Id: <20000917215300.22426.00000034@ng-fb1.aol.com>

>Do you have a Unix box you can get started on? If not then you can run Perl
>on your windows system, and just ftp your scripts to your site when you're
>done. 

If I do this can I send Cgi Variables to the perl program on windows the same
way as in Unix to test the script?






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

Date: Mon, 18 Sep 2000 01:13:33 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Getting started w/ Perl
Message-Id: <slrn8sar1r.ego.tjla@thislove.dyndns.org>

I was shocked! How could JoeCoolCols <joecoolcols@aol.com>
say such a terrible thing:
>I am fairly new to Perl I got started by using Perl on My PC with an emulator
>that ran in Windows "MkSnt" or something like that.  Unfortunately it got lost
>somewhere when i was transfering things from my old pc to my new one.
>Does anyone know whether or where  you can get one of these emulators now?
>I need one so I can work on and test my CGI project before sening it to the web
>site. Please Help Me !

www.activestate.com

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Captain Hook died of jock itch.


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

Date: Mon, 18 Sep 2000 01:33:44 GMT
From: "Bryan Liles" <bliles@bigup.shacknet.nu>
Subject: Re: Graphical Perl??
Message-Id: <Yhex5.150382$eS6.2013361@news1.rdc1.md.home.com>

In article <39C4C9F4.A137BDBA@iol.ie>, "Kyle Parfrey" <kyle@iol.ie> wrote:

> Hi all Perl people: I am a programming beginner just coming over to perl
> from a bit of java, liking perls control of the system a lot.  Two
> questions though:
> 
> 1) Is there a graphical toolkit for perl? I have heard something about
> Tk, but don't know what it is. Is it as easy to use as java's integrated
> gui widgets?
> 

perl TK
perl GTK


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

Date: Mon, 18 Sep 2000 02:37:12 GMT
From: zirconx@my-deja.com
Subject: Is there a DBI that will connect to MS SQL Server?
Message-Id: <8q3v4m$1ln$1@nnrp1.deja.com>

Hello. I am looking at hardware and software for a very large
project, and it looks like I'll have the need to connect to
a MS SQLServer from Linux/perl. Is this possible? I've tried
to find the answer but couldn't. I found posts that say it
should work, might work, does work with 6.5... but can I connect
to a modern SQLServer (is that like 7.0 or 2000?) via DBD/DBI
Perl on linux? Which one?

Can I just reach it with DBD:ODBC? Thanks for any help.

Ryan


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


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

Date: Mon, 18 Sep 2000 02:41:27 GMT
From: halofive <halo_five@my-deja.com>
Subject: Re: Just curious..
Message-Id: <8q3vck$1vs$1@nnrp1.deja.com>

Heh, this is to everyone who responded..
-=-=-

I was, for the most part, just curious about how, or `if' for that
matter, you could print "three" from the hash without using key() etc,
but I'm probably just being anal.

Thanks for all of the responses, however.  Oh, and my [dumbass] logic
behind print "three" with  $hash{""}  was that, I read undef was
returned if there was no value to the key (if that makes sense).  So,
in turn, I was curious if using undef to return the key's value would
work.


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


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

Date: Mon, 18 Sep 2000 01:42:15 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Recipe For Sorting LoL
Message-Id: <slrn8sasn6.2cp.mgjv@verbruggen.comdyn.com.au>

On Sun, 17 Sep 2000 18:05:58 GMT,
    andre_sanchez@my-deja.com <andre_sanchez@my-deja.com> wrote:
> In article <slrn8s85pm.ntr.mgjv@martien.heliotrope.home>,
>   mgjv@tradingpost.com.au wrote:
> 
> > Sort by first key first, then by second:
> >
> > sub sortsub { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] }
> >
> 
> I would like to sort by successive keys, in a fashion similiar to the
> one you describe, but for the more general case where the number of
> elements in the lists are not known in advance and that may vary for
> each
> succesive list.

Next time it would be good if you showed us what you have tried
already. We like to know that you have at least _tried_ soemthing, and
are not just begging for us to do your work. Something like the
following might get you on the road:

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

my @LoL;

while (<DATA>)
{
	chomp;
	push @LoL, [split]
}

print "@$_\n" for (sort flex_cmp @LoL);

sub flex_cmp
{
	my $n = $#$a < $#$b ? $#$a : $#$b;
	my $result = 0;
	for (0 .. $n)
	{
		last if $result = $a->[$_] cmp $b->[$_]
	}
	$result || $#$a <=> $#$b;
}

__DATA__
a b c d e
a b c
d e f
g h i
d e f g
e f g h
a b c d
e f g h
e f k i
e f g h
e f g h
e f g
a b d e
e f g h i
a b c
a b c e

You might be able to get away with joining the strings together with
some high-sorting character in the middle (using join, or maybe pack),
but I'd probably shy away from that until there was a decent
performance need for it.

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


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

Date: Mon, 18 Sep 2000 03:31:46 GMT
From: andre_sanchez@my-deja.com
Subject: Re: Recipe For Sorting LoL
Message-Id: <8q42b3$5bo$1@nnrp1.deja.com>

My thanks and my apologies: My thanks for the help you have provided;
My apologies for not having expressed my self clearly before.

Before posting I had searched "Programming Perl", "Perl Cookbook",
"Mastering Algorithms With Perl", "Advanced Perl Programming",
deja.com, perl.com, and had not found an example for the general
case. I was sure that someone must have solved this problem before,
and that I had just overlooked where it was documented.

What I was looking for was a reference. What I got was working
code. Thank you.

Sincerely,

Andre Sanchez


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


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

Date: Mon, 18 Sep 2000 01:19:19 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: RunJava script from MS Explorer problem
Message-Id: <slrn8sarcl.ego.tjla@thislove.dyndns.org>

I was shocked! How could yantar <yantarian@hotmail.com>
say such a terrible thing:
>Certainly someone else has seen this problem ...

>Does anyone know
>how to fix it so the filenname gets passed without appending
>of the '~1' to each file name in DOS/Explorer

Is this even a Perl question?

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
BOFH excuse #64:

CPU needs recalibration


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

Date: Mon, 18 Sep 2000 05:23:48 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: shtml on-the-fly
Message-Id: <1eh529k.1auidznyv9hfaN%tony@svanstrom.com>

        [Followup-To: comp.infosystems.www.authoring.cgi]

Fernando <rs016182@pro.via-rs.com.br> wrote:

> I need to generate a shtml document from a cgi.

You should ask this question in comp.infosystems.www.authoring.cgi, and
not in c.l.p.misc. But being in a good mood I'll give you the answer
anyhow, it can't be done (ok, the few that know everything might say
that it's possible, but I have so far not come across a server that
allows it; and I'd consider it more or less broken if it did, kind of,
because I don't want the server to mess around with perfection... ;-).

Here's the reason why (simplified, but close enough): When you use CGI
the webpage is sent directly to the webbrowser, so it is never passed
thru all the SSI-stuff that the server might be able to do. The server
simply thinks that if you're good enough to use CGI then you're good
enough to handle your own SSI.

There are many benefits to why you'd like to handle the SSI-stuff
yourself when you are using CGI anyhow, one of them is that you can
write a SSI-function that is much more complex than "standard" SSI. The
part about that that at least I love is that it's so easy to share a lot
of things that you otherwise might have to put into every single
[whatever it is that you want to include].
I've set one such thing up as an example on a website, you "access" it
like this: <URL:http://www.svanstrom.com/?user=thiscode>

What that does is that it sets you as a "superuser" internally, so you
are bypassing all the logging and all the banners. Don't even think
about it as a way to try to do bad things without getting logged, I'm
not that stupid... :-)


     /Tony
-- 
     /\___/\ Who would you like to read your messages today? /\___/\
     \_@ @_/  Protect your privacy:  <http://www.pgpi.com/>  \_@ @_/
 --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
   on the verge of frenzy - i think my mask of sanity is about to slip
 ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
    \O/   \O/  ©99-00 <http://www.svanstrom.com/?ref=news>  \O/   \O/


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

Date: 18 Sep 2000 12:22:41 +1100
From: norm@turing.une.edu.au (Norman Gaywood)
Subject: Re: Teaching Perl
Message-Id: <8q3qp1$pec$1@turing.une.edu.au>

Bart Lateur <bart.lateur@skynet.be> writes:
>Adam Trace Spragg wrote:
>>was when I said that you could do "c=c+1" that she sort of flipped out.  In
>>a math sense, "c=c+1" rarely ever makes sense.

>Your girlfriend (and you?) is confusing assignment with equality.
>Would you expect in a bormal programming language to do:
>	12 = 3*x + 2*y
>	15 = 2*x + 3*y
>and the program come up with appropriate values for x and y?
>Well, maybe you would. But that's not how it works.

It is in MetaPost. The above equations are a perfectly acceptable way
to assign values to x and y. There is an assignment operator as well,
so you can:

x := x + 1;

If you wrote:

x = x + 1;

you get the error message "Inconsistent equation (off by 1)"

Of course I am not saying that Adam should teach his girlfriend MetaPost.
It certainly is not a "bormal" programming language. :-)

Cheers.
-- 
Norman Gaywood -- School of Mathematical and Computer Sciences
University of New England, Armidale, NSW 2351, Australia
norm@turing.une.edu.au     http://turing.une.edu.au/~norm
Phone: +61 2 6773 2412     Fax: +61 2 6773 3312


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

Date: 17 Sep 2000 22:52:07 -0400
From: Phil Eschallier <phil@BuxTech.Com>
Subject: Re: Teaching Perl
Message-Id: <86k8cah0o8.fsf@BuxTech.Com>

>>>>> "Adam" == Adam Trace Spragg <spragg@cs.ucdavis.edu> writes:

    > Tim <SPAM+indigo@dimensional.com> wrote: : For people who have
    > do this sort of thing before, any general advice?

    > I haven't done this sort of thing, but I still have some general
    > advice.  Knowing Perl will not automatically make you a good
    > teacher.  Teaching is a skill in and of itself, regardless of
    > the subject matter.

    > I decided to describe Perl (and general) programming to my
    > girlfriend recently (who is a recent math major graduate).  I
    > described variables and values, and that went well.  If a=5 and
    > b=6, then c=a+b would result in c being 11.  It was when I said
    > that you could do "c=c+1" that she sort of flipped out.  In a
    > math sense, "c=c+1" rarely ever makes sense.  :) Also, if c is
    > reassigned c+1, then when would the cycle stop?  Etc, etc.

    > My point of all this is to show that even though I thought it
    > would be simple to describe even the most elementary concepts,
    > it was much more difficult than I anticipated.

    > I guess this doesn't really apply if you are teaching computer
    > savvy folk, but might if you are teaching newbies.

    > HTH Adam

Adam;

Not like I'd ever want to sound like my (or someone elses) father, but
"back when I was in school", there was a clear distinction between a
test for equality and assignment.

Specifically ...

Equality tests were of the nature:

        if this "equals" that

and assignment was of the nature:

        this "gets" that

 ... your conversations with your girl friend did not seem to make such
a distinction.

And how this distinction was depecticted in any given programming
language was not relevant, only that there was a distinction.

As such, a note for your girl friend ... there is no cycle!  "c = c +
1" is not an odd mathematical postulate true for only sufficiently
small values of c (or 1), it is an assignment.  And there is a clearly
defined end (that is; no loop) as it is an operation, not a continuum.

Let's not confuse realms based on similar notations.

Cheers.

-- 
Phil Eschallier
Bux Technical Services
70 Irish Meetinghouse Rd
Perkasie, PA  18944
215.249.TECH (215.249.8324)
215.249.8325 (fax)
http://www.BuxTech.Com


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

Date: Mon, 18 Sep 2000 01:07:17 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Using range operator
Message-Id: <slrn8saqm3.ego.tjla@thislove.dyndns.org>

I was shocked! How could Randy <randy_734@my-deja.com>
say such a terrible thing:
>Is there a simple way to use the range operator to check if a value
>falls within?
>
>Something like:
>
>$num=5;
>print "In range\n" if ($num == (1..20));

Here's a TMTOWTDI solution:

use Quantum::Superpositions;
my $num = 5;
print "In range\n" if ($num == any(1..20));

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Are you mentally here at Pizza Hut??


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

Date: Sun, 17 Sep 2000 18:19:03 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Using range operator
Message-Id: <39C56D87.AECA7169@stomp.stomp.tokyo>

Wyzelli wrote:
 
> Godzilla! wrote:
 
> > Caution should
> > be used regarding how large of a range is set.
> > Memory can be eaten up for a very large range,
> > if a range much like they have in Texas.
 
> Time will be used rather than memory in a loop like you coded. Typical
> Texas ego!  There is a single cattle station (you would call it a ranch)
> here that all of Texas would fit into five times over!



See my other article for size and semantics.

This reminds me of a tech ordeal I experienced just recently,
this past week in fact. I noticed my programs were running
slower and slower, to a point of taking five to ten minutes
to produce results where before results came back in one
second or, usually, less.

Checking everything over, many times, running tests with a
"Hello World!" simple print script, I knew something was
wrong. During day, extremely slow. During late night, slow
but not as slow as daytime. Even my log records were screwed
up; displayed records in wrong chronological order. This
indicated multiple instances of spawning a script and, results
coming back, at differing rates.

My final analysis was a modem was going bad at my server. This
analysis was based on worse conditions, over days and the same
for day versus night. Towards the end, near final resolution,
some simple scripts, Hello World!, were taking ten minutes and
upward to print results.

Clincher is this, html style documents showed no delay in
response time, zero, nada, zippo. This was stupefying. Why
would a cgi slow down but not an html document if a modem 
is going bad? Obviously, something wrong with core 
processing, but what?

An investigation of processing led to a surprising discovery.
A procmail program had gone rogue and would not stop running.
With each mail sent, a new procmail instance spawned, till
eventually, after three or four days, any perl core processing
came to a near standstill with so many procmail spawnings. This
very much was a mimic of a modem going bad.

So yes, my loop would use time for a technical term and, consume
memory for a long time, much as these rogue procmail spawnings
used equal amounts of memory, but indefinitely in time, leading
to unavailable memory for other parallel processing.

Randal and you, are correct technically in saying more time would
be used than memory. In contrast, my meaning is memory would be
used up needlessly, under same circumstances.

Most interesting case of slippery semantics, indeed.


Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

Date: Sun, 17 Sep 2000 23:32:21 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Using range operator
Message-Id: <Pine.GSO.4.21.0009172306240.28758-100000@crusoe.crusoe.net>

I'm taking DSA (Data Structures & Algorithms) this year in college, so I
consider myself learned enough to make the follow statements:

  int i;
  for (i = 0; i < N; i++) {
    1;
  }

That block of C code is O(N).  That means, it performs its actions in a
time proportional to N.  PROPORTIONAL TO N.  If N is small, the loop takes
a small amount of time to run.  As N gets bigger, the time increases.  How
much memory is involved does not change.  Time and memory, "Godzilla," are
NOT interchangeable, nor are they techno-babble.  The following loop takes
up a lot more TIME:

  for ($i = 0; $i < 1_000_000_000; $i++) {}

than this one:

  for ($i = 0; $i < 10; $i++) {}

But both take far less MEMORY than:

  for $i (0..999_999_999) {}

This is because the range operator builds a list (in this case, a list of
10^9 elements), and lists are stored in memory.  Larger lists require
larger amounts of memory.

As for the extendability of your loop, I would do something all crazy and
obfuscated in the Perl 5 fashion of things:

  # @low is the lower index of the ranges (0-9),(10-14),(15,29),(30-INF)
  @low = (0,10,15,30);
  @actions = (
    sub { print "0->9\n" },
    sub { print "10->14\n" },
    sub { print "15->29\n" },
    sub { print "30->INF\n" },
  );

  $actions[ range($target, \@low) ]->();
  
  sub range {
    my ($value,$lows) = @_;
    my $i;
    for ($i = 0; $i < @$lows - 1; $i++) {
      last if $lows->[$i] <= $value and $value < $lows->[$i+1];
    }
    return $i;
  }

Oh no, that uses REFERENCES.  Not a difficult concept.  It's quite
efficient, if you ask me.  You don't have an array with elements 0 through
9 being the same thing, 10 through 14 the same, 15 through 29 the same,
and, well, don't get me started on $array[INFINITY].

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



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

Date: Mon, 18 Sep 2000 03:57:33 GMT
From: Randy <randy_734@my-deja.com>
Subject: Re: Using range operator
Message-Id: <39c591bd.43516796@207.126.101.100>

Jeff,

Pardon my butting in...
I'm surprised to learn that range operator creates a list rather than
a counter.  Given that, would you say that it is most always going to
be more efficient to set up a loop with a counter rather than use a
range, assuming the index is numeric?

Randy Harris
(trying very hard to learn a little bit about Perl)



Jeff Pinyan <jeffp@crusoe.net> wrote:

>I'm taking DSA (Data Structures & Algorithms) this year in college, so I
>consider myself learned enough to make the follow statements:
>
>  int i;
>  for (i = 0; i < N; i++) {
>    1;
>  }
>
>That block of C code is O(N).  That means, it performs its actions in a
>time proportional to N.  PROPORTIONAL TO N.  If N is small, the loop takes
>a small amount of time to run.  As N gets bigger, the time increases.  How
>much memory is involved does not change.  Time and memory, "Godzilla," are
>NOT interchangeable, nor are they techno-babble.  The following loop takes
>up a lot more TIME:
>
>  for ($i = 0; $i < 1_000_000_000; $i++) {}
>
>than this one:
>
>  for ($i = 0; $i < 10; $i++) {}
>
>But both take far less MEMORY than:
>
>  for $i (0..999_999_999) {}
>
>This is because the range operator builds a list (in this case, a list of
>10^9 elements), and lists are stored in memory.  Larger lists require
>larger amounts of memory.
>
>As for the extendability of your loop, I would do something all crazy and
>obfuscated in the Perl 5 fashion of things:
>
>  # @low is the lower index of the ranges (0-9),(10-14),(15,29),(30-INF)
>  @low = (0,10,15,30);
>  @actions = (
>    sub { print "0->9\n" },
>    sub { print "10->14\n" },
>    sub { print "15->29\n" },
>    sub { print "30->INF\n" },
>  );
>
>  $actions[ range($target, \@low) ]->();
>  
>  sub range {
>    my ($value,$lows) = @_;
>    my $i;
>    for ($i = 0; $i < @$lows - 1; $i++) {
>      last if $lows->[$i] <= $value and $value < $lows->[$i+1];
>    }
>    return $i;
>  }
>
>Oh no, that uses REFERENCES.  Not a difficult concept.  It's quite
>efficient, if you ask me.  You don't have an array with elements 0 through
>9 being the same thing, 10 through 14 the same, 15 through 29 the same,
>and, well, don't get me started on $array[INFINITY].
>
>-- 
>Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
>PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
>The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
>CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/
>



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

Date: Mon, 18 Sep 2000 02:08:40 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Why does * in a string glob?
Message-Id: <slrn8sau8m.2cp.mgjv@verbruggen.comdyn.com.au>

On Fri, 15 Sep 2000 14:48:47 -0600,
	David J Iannucci <dji@myriad.com> wrote:
> I've got a weird problem... I've got a case where I'm
> putting an SQL statement ("select * from tablename where [...]")
> into a double-quoted Perl string, and Perl is treating the *
                                        ^^^^
										I doubt it.
										Something else may be.

> character as a glob, and replacing it in the string with a list
> of all the files in my home directory! (I should say: I guess
> Perl is the culprit -- I certainly can't imagine the database
> doing this).

How do you get that string to your database? Any invocations of shell
with system(), backticks and/or qx//? Perl certainly will not glob a *
in a doublequoted string unless you ask for it explicitly.

If you are using external programs to send these sql strings to your
database, you need to start looking at the DBI module.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd.   | make up 3/4 of the population.
NSW, Australia                  | 


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4353
**************************************


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