[17217] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4639 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 17 03:11:36 2000

Date: Tue, 17 Oct 2000 00:10:16 -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: <971766616-v9-i4639@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 17 Oct 2000     Volume: 9 Number: 4639

Today's topics:
        Regex substitution question... <ctucker@no.omenmedia.spam.com>
    Re: Regex substitution question... <godzilla@stomp.stomp.tokyo>
    Re: Regex substitution question... <ctucker@no.omenmedia.spam.com>
    Re: Regex substitution question... <ianb@ot.com.au>
    Re: Regex substitution question... <ctucker@no.omenmedia.spam.com>
    Re: Regex substitution question... <godzilla@stomp.stomp.tokyo>
    Re: Regex substitution question... <ctucker@no.omenmedia.spam.com>
    Re: Regex substitution question... <godzilla@stomp.stomp.tokyo>
    Re: Regex substitution question... <uri@sysarch.com>
    Re: Regex with repquota output <godzilla@stomp.stomp.tokyo>
    Re: Regex with repquota output <ianb@ot.com.au>
    Re: Run perl script as service <elephant@squirrelgroup.com>
    Re: Save As... Popup box <dsimonis@fiderus.com>
    Re: Saving Textarea to text file <elephant@squirrelgroup.com>
    Re: Sorting a list <kistler@gmx.net>
    Re: Strange behaviour with pos($text), m/.../g and for( <moell@ID-PRO.de>
    Re: Telling difference between a package and a class? trollis@my-deja.com
    Re: Tracking user in perl CGI... HELP! <dsimonis@fiderus.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 17 Oct 2000 15:31:49 +1100
From: "Colin Tucker" <ctucker@no.omenmedia.spam.com>
Subject: Regex substitution question...
Message-Id: <39ebd686$0$11621$7f31c96c@news01.syd.optusnet.com.au>

Hi there,

I'm trying to write a regex that will scan through a HTML file and replace
certain "commands" with their output, for example:

<html>
 ...
 ...
[Display("[Value("foobar")]")]
 ...
 ...
</html>

At the moment, I have it scanning for occurrences of square brackets with
anything between them, which it then evaluates as a function, and
substitutes the function's return value into the HTML, but the problem is
illustrated above - I want to be able to substitute "nested" commands.

Say that Value("foobar") returns "blah".  I want Perl to evaluate this inner
function, and then place it's output into the outer function, like this:

[Display("blah")]

 ...which would presumably display something called "blah".  Is there an easy
regex way of doing this?  Or can it be done with a loop or something?  Any
help would be greatly appreciated..!

Regards,

--
Colin Tucker





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

Date: Mon, 16 Oct 2000 21:54:36 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Regex substitution question...
Message-Id: <39EBDB8C.DA244EDC@stomp.stomp.tokyo>

Colin Tucker wrote:

> I'm trying to write a regex that will scan through a 
> HTML file and replace certain "commands" with their
> output, for example:
 
> <html>
> ...
> ...
> [Display("[Value("foobar")]")]
> ...
> ...
> </html>
 
> Say that Value("foobar") returns "blah".  I want Perl to 
> evaluate this inner function, and then place it's output
> into the outer function, like this:
 
> [Display("blah")]
 
> ...which would presumably display something called "blah".  Is there an easy
> regex way of doing this?  Or can it be done with a loop or something?  


> Any help would be greatly appreciated..!


Use of a little common sense will make this very
clear you are creating problems for naught. Why,
I really cannot fathom.

Your html:

> <html>
> display_foobar
> </html>

Your script:

$display_foobar = "some function result";

$html =~ s/display_foobar/$display_foobar/;



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


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

Date: Tue, 17 Oct 2000 16:01:42 +1100
From: "Colin Tucker" <ctucker@no.omenmedia.spam.com>
Subject: Re: Regex substitution question...
Message-Id: <39ebdd88$0$11631$7f31c96c@news01.syd.optusnet.com.au>

No, sorry, but that doesn't help me at all unfortunately.  Yes, that is the
easiest way to do it, but it's not the way I want it to work.  I don't want
to predefine variables and such - I've seen the real easy way to do this
with Perl, and it's similar to what you posted, like this:

<html>
 ..
 ..
Here is a value: $foobar
 ..
 ..
</html>

 ...using a regex you could easily find Perl variables within the HTML and
substitute their values, but this is not what I want to do.  I want function
names surrounded by square brackets, and I want these function calls to be
able to be nested.  I suppose I could just put one set of square brackets
around a whole series of nested calls, but the function calls are actually
method calls of an object instance - the instance name is not known to the
user, so they cannot refer directly to the object.

I'm trying to write a template parsing engine, for end-users - so all they
get is the Perl engine, and they write the HTML and command calls for the
engine.  They may not even be Perl programmers.  Every bit of iteraction
with the engine will be through these command calls within the HTML.  So,
*is* there a way to do it?

Thanks,

--
Colin Tucker

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:39EBDB8C.DA244EDC@stomp.stomp.tokyo...
> Colin Tucker wrote:
>
> > I'm trying to write a regex that will scan through a
> > HTML file and replace certain "commands" with their
> > output, for example:
>
> > <html>
> > ...
> > ...
> > [Display("[Value("foobar")]")]
> > ...
> > ...
> > </html>
>
> > Say that Value("foobar") returns "blah".  I want Perl to
> > evaluate this inner function, and then place it's output
> > into the outer function, like this:
>
> > [Display("blah")]
>
> > ...which would presumably display something called "blah".  Is there an
easy
> > regex way of doing this?  Or can it be done with a loop or something?
>
>
> > Any help would be greatly appreciated..!
>
>
> Use of a little common sense will make this very
> clear you are creating problems for naught. Why,
> I really cannot fathom.
>
> Your html:
>
> > <html>
> > display_foobar
> > </html>
>
> Your script:
>
> $display_foobar = "some function result";
>
> $html =~ s/display_foobar/$display_foobar/;
>
>
>
> Godzilla!
> --
> Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
> UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
> BumScrew, South of Egypt ¦ HTML Programming Class




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

Date: Tue, 17 Oct 2000 15:17:13 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: Regex substitution question...
Message-Id: <39EBD2C9.AFC42921@ot.com.au>

Colin Tucker wrote:

> Hi there,
>
> I'm trying to write a regex that will scan through a HTML file and replace
> certain "commands" with their output, for example:
>
> <html>
> ...
> ...
> [Display("[Value("foobar")]")]
> ...
> ...
> </html>
>
> ...which would presumably display something called "blah".  Is there an easy
> regex way of doing this?  Or can it be done with a loop or something?  Any
> help would be greatly appreciated..!

Regexes can't be written to match arbitrary levels of nesting. You can make
regexes that cater for a predetermined maximum level of nesting, but that's of
dubious value.

You can also look for the start ("["), then match prefixes ending in opening or
closing brackets, concatenating as you go, keeping a nesting depth count, then
exiting when the depth reaches zero or emitting an error when you hit EOF. I
have done it before, but I don't have time to try to recreate it right now.
Watch for escaped brackets too, if necessary...

There's bound to be an FAQ on it, or something in perldoc. Someone is also
likely to have written a CPAN module to do it too...

Regards,


Ian




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

Date: Tue, 17 Oct 2000 16:06:42 +1100
From: "Colin Tucker" <ctucker@no.omenmedia.spam.com>
Subject: Re: Regex substitution question...
Message-Id: <39ebdeb5$0$27119$7f31c96c@news01.syd.optusnet.com.au>

Wow, I didn't think it'd be so tricky!!  Thanks heaps for that...

Regards,

--
Colin Tucker

"Ian Boreham" <ianb@ot.com.au> wrote in message
news:39EBD2C9.AFC42921@ot.com.au...
> Regexes can't be written to match arbitrary levels of nesting. You can
make
> regexes that cater for a predetermined maximum level of nesting, but
that's of
> dubious value.
>
> You can also look for the start ("["), then match prefixes ending in
opening or
> closing brackets, concatenating as you go, keeping a nesting depth count,
then
> exiting when the depth reaches zero or emitting an error when you hit EOF.
I
> have done it before, but I don't have time to try to recreate it right
now.
> Watch for escaped brackets too, if necessary...
>
> There's bound to be an FAQ on it, or something in perldoc. Someone is also
> likely to have written a CPAN module to do it too...





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

Date: Mon, 16 Oct 2000 22:21:14 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Regex substitution question...
Message-Id: <39EBE1CA.6C182999@stomp.stomp.tokyo>

Colin Tucker wrote:


 
> No, sorry, but that doesn't help me at all unfortunately.

Using common sense always helps me.
Why don't you try using some common sense?


> Yes, that is the easiest way to do it,

This is a problem?


> but it's not the way I want it to work.

Then do it your way.


> I don't want to predefine variables and such
> - I've seen the real easy way to do this
> with Perl, and it's similar to what you posted, like this:

All variables in Perl are predefined. They may
hold a value, might be a null string or may even
become undefined at some point. In all cases,
all variables are predefined in some form or
fashion, by a script, regardless of value content.


> I'm trying to write a template parsing engine, for end-users - so all they
> get is the Perl engine, and they write the HTML and command calls for the
> engine.  They may not even be Perl programmers.  Every bit of iteraction
> with the engine will be through these command calls within the HTML.  So,
> *is* there a way to do it?

This is senseless. You are not asking your users to write
html alone. You are asking users to write html wrapped
around high risk command calls. Clearly, somewhere along
the line, you will need to use eval. This is something
which should be avoided if possible. This represents
a high security risk. Common sense dictates this.


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

Date: Tue, 17 Oct 2000 16:33:18 +1100
From: "Colin Tucker" <ctucker@no.omenmedia.spam.com>
Subject: Re: Regex substitution question...
Message-Id: <39ebe4f1$0$11631$7f31c96c@news01.syd.optusnet.com.au>

> > No, sorry, but that doesn't help me at all unfortunately.
>
> Using common sense always helps me.
> Why don't you try using some common sense?

I am, I'm just asking for some help.

> > Yes, that is the easiest way to do it,
>
> This is a problem?

No, but that way does not accomplish what I need, and
what I originally asked for in the first post.

> > but it's not the way I want it to work.
>
> Then do it your way.

I'm trying, that's why I came here and asked for some help.

> > I don't want to predefine variables and such
> > - I've seen the real easy way to do this
> > with Perl, and it's similar to what you posted, like this:
>
> All variables in Perl are predefined. They may
> hold a value, might be a null string or may even
> become undefined at some point. In all cases,
> all variables are predefined in some form or
> fashion, by a script, regardless of value content.

That's a little too deep for me at this time of day, I'll leave
it alone if it's okay with you.  ;o)

> > I'm trying to write a template parsing engine, for end-users - so all
they
> > get is the Perl engine, and they write the HTML and command calls for
the
> > engine.  They may not even be Perl programmers.  Every bit of iteraction
> > with the engine will be through these command calls within the HTML.
So,
> > *is* there a way to do it?
>
> This is senseless. You are not asking your users to write
> html alone. You are asking users to write html wrapped
> around high risk command calls. Clearly, somewhere along
> the line, you will need to use eval. This is something
> which should be avoided if possible. This represents
> a high security risk. Common sense dictates this.

If it's so senseless, then why have template processing engines such as ASP,
Java servlets, PHP, ColdFusion, Vignette StoryServer and about a zillion
others
even been written in the first place??  Why are the command calls "high
risk"??
They can only consist of method calls to an object which I have created.
The regular expression I'm currently using already performs an eval of the
command matched by using (), $1 and the e option at the end, so eval is
not necessary.  As for security risks, so long as the code is written
correctly
to handle any erroneous commands or data, the risk should be minimal.

As for common sense - if you had any, you would have replied originally with
a post like the good Ian Boreham has, a post that is helpful and answers
my original questions.

Regards,

--
Colin Tucker




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

Date: Mon, 16 Oct 2000 23:22:40 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Regex substitution question...
Message-Id: <39EBF030.E0EEAAA5@stomp.stomp.tokyo>

Colin Tucker wrote:
 
> > > No, sorry, but that doesn't help me at all unfortunately.

> > Using common sense always helps me.
> > Why don't you try using some common sense?
 
> I am, I'm just asking for some help.

No, you are looking to start an argument.

 
> > > Yes, that is the easiest way to do it,

> > This is a problem?
 
> No, but that way does not accomplish what I need, and
> what I originally asked for in the first post.

What I suggested does precisely and perfectly
what you ask, in the most simplistic of ways.
My suggestion is exceptionally logical compared
to about which you wish to argue.

My suggestion is clean, simple, requires less coding
and, quite importantly, does not require these users,
"non-programmers" of yours, to write complex code,
which ironically, they do not know how to do per
your statements. Why would you have people who know
nothing about Perl, write command calls?

 
> > > but it's not the way I want it to work.

> > Then do it your way.
 
> I'm trying, that's why I came here and asked for some help.

No, you are here to start an argument if possible.
This is not possible with me. It is possible to 
annoy me to a point of subjecting you to barbed 
commentary.

 
> > > I don't want to predefine variables and such
> > > - I've seen the real easy way to do this
> > > with Perl, and it's similar to what you posted, like this:

> > All variables in Perl are predefined. They may
> > hold a value, might be a null string or may even
> > become undefined at some point. In all cases,
> > all variables are predefined in some form or
> > fashion, by a script, regardless of value content.
 
> That's a little too deep for me at this time of day, I'll leave
> it alone if it's okay with you.  ;o)

If this notion is too deep for you, it is clear
you should not be trying to write a program as
you describe; you do not know enough about Perl.
It is impossible to pump in these random variables
of which you speak, without your script having
predefined parameters, predefined variables and
predefined script actions to deal with this input.
You have no choice but to use predefined variables.

 
> > > I'm trying to write a template parsing engine, 
> > > for end-users - so all they get is the Perl engine,
> > > and they write the HTML and command calls for the
> > > engine.  They may not even be Perl programmers.

Uh huh. "They may not even be Perl programmers."
You expect these people to write Perl command calls?


> > >  Every bit of iteraction  with the engine will be
> > > through these command calls within the HTML.
> > > So, *is* there a way to do it?

Yes there is a way to do this and, you already know
how this is done.


> > This is senseless. You are not asking your users to write
> > html alone. You are asking users to write html wrapped
> > around high risk command calls. Clearly, somewhere along
> > the line, you will need to use eval. This is something
> > which should be avoided if possible. This represents
> > a high security risk. Common sense dictates this.
 
> If it's so senseless, then why have template processing engines such as ASP,
> Java servlets, PHP, ColdFusion, Vignette StoryServer and about a zillion
> others even been written in the first place??  Why are the command calls 
> "high risk"??

Do users write these command calls as you would have them,
for these examples cited? Seems to me, users write predefined
safe pseudo-variables for these circumstances, not actual
command calls which are evaluated and executed.


> They can only consist of method calls to an object which I have created.
> The regular expression I'm currently using already performs an eval of the
> command matched by using (), $1 and the e option at the end, so eval is
> not necessary.  As for security risks, so long as the code is written
> correctly to handle any erroneous commands or data, the risk should 
> be minimal.

You said you don't know how to do this. Now you say you
already have working code and know how to do this. Goodness,
reads like an inadvertent Freudian slip of a confession
alluding to practicing deceit; a Freudian slip of your
ego tongue. Terminal Testosterone Poisoning?

This is equally senseless. First you state people who know
nothing about Perl programming will write this 'stuff' and,
now you say as long as they write command calls correctly,
no problem. Common sense dictates non-programmers will be
writing bad code consistently and constantly.

Hello? Knock.. Knock.. anyone in there?

 
> As for common sense - if you had any, you would have replied 
> originally with a post like the good Ian Boreham has, a post
> that is helpful and answers my original questions.

Ahhhh, po' boy. You are breaking my wittle heart,
truly you are, Frank.



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


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

Date: Tue, 17 Oct 2000 06:26:54 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Regex substitution question...
Message-Id: <x71yxgt234.fsf@home.sysarch.com>

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

  G> Colin Tucker wrote:
 
  >> > > No, sorry, but that doesn't help me at all unfortunately.

  >> > Using common sense always helps me.
  >> > Why don't you try using some common sense?
 
  >> I am, I'm just asking for some help.

  G> No, you are looking to start an argument.


our dear moronzilla is now just blathering and not even attempting to
answer questions anymore. someone please contact here keepers and have
her meds updated.

tucker,

ingore this asshole. she is just trolling you. you have gotten proper
answers elsewhere.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Mon, 16 Oct 2000 21:42:40 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Regex with repquota output
Message-Id: <39EBD8C0.9B5B1BE4@stomp.stomp.tokyo>

Arthur Dalessandro wrote:
 
> I am trying to finish an overquota warning system for our 
> unix file store by going through an array which contains a 
> bunch of the following data:

> <uid><file quota><inode quota> <actual used> <softlimit> <hard limit>
> <acutal inodes> <soft inodes> <hard inodes>
> odione.adalessandro--   13334   50000       0             39     0     0

> where -- means that file and inodes are below quota

> -+ means inodes are above quota
> +- means the files (K) are above quota
> ++ both are above quota..
 
> I need to split this line into the headings shown, it would 
> be nice to use the + - as triggers but not neccessary.


There are some serious problems with your article.
It appears your data are all items from "data:"
through "where" inclusively. These psuedo tags
in a format "<uid><file quota>..etc" are these
part of your data or something else? What you
exemplify is incomprehensible. You indicate these
pseudo tags are data, then later refer to them
as headings. Which are they? Data or a single line
header at the beginning of a data base document?

Your " (K) " typically means degrees Kelvin.
Is this item another variable or something
of obscure meaning?

No comment is to be found what you want to do
with the period in " odione.adalessandro " per
your unclear parameters. Do you want this period
tossed or saved? Is this period a delimiter?

Do you have nine variables, eighteen variables
or nineteen variables if "degrees Kelvin" is to
be included? You have made no clear statement,
set no clear parameters how you expect to split
this data but rather have made some vague reference
to "headings" which are, in themselves, unclear.

I would question why you are writing your data
base in such a manner there are no clear delimiters.
Why don't you write your data base correctly rather
than try to bandage the damage done? It would be most
logical of you to write your data base in both an
organized and well planned manner rather than this
mess you show only to struggle to fix what should
not be messed up initially.

You have stated parameters which are exceptionally
unclear, your explanation of what you want to do
is even less clear and, your incomprehensible example
contradicts much of what you have stated.

Do yourself a favor and state your parameters and
your expectations in a clear, concise and comprehensible
manner so an average person can understand what you
are saying and asking, with confidence.



Second guessing what you are trying to say, you
only need three simple lines of Perl code to fix
this data mess you have created.

$data =~ s/\s+/¦/g;
$data =~ s/\./¦/;
$data =~ s/([-+]+)/¦$1/;

Your data is now correctly delimited and prepared
for whatever it is you want to do.



Godzilla!
--

I have removed some excess spaces from
your questionable data example to
prevent word wrapping for clarity.



TEST SCRIPT:
------------


#!/usr/local/bin/perl

print "Content-type: text/plain\n\n";

$data = "odione.adalessandro--  13334  50000  0  39  0  0";

$data =~ s/\s+/¦/g;
$data =~ s/\./¦/;
$data =~ s/([-+]+)/¦$1/;

($uid, $file_quota, $inode_quota, $actual_used,
$softlimit, $hard_limit, $acutal_inodes,
$soft_inodes, $hard_inodes) = split (/¦/, $data);

print "
UID: $uid
FILE QUOTA: $file_quota
INODE QUOTA: $inode_quota
ACTUAL USED: $actual_used
SOFT LIMIT: $softlimit
HARD LIMIT: $hard_limit
ACTUAL INODES: $acutal_inodes
SOFT INODES: $soft_inodes
HARD INODE: $hard_inodes";

exit;



PRINTED RESULTS:
----------------

UID: odione
FILE QUOTA: adalessandro
INODE QUOTA: --
ACTUAL USED: 13334
SOFT LIMIT: 50000
HARD LIMIT: 0
ACTUAL INODES: 39
SOFT INODES: 0
HARD INODE: 0


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

Date: Tue, 17 Oct 2000 15:04:40 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: Regex with repquota output
Message-Id: <39EBCFD8.DB7505E8@ot.com.au>

Arthur Dalessandro wrote:

> I am trying to finish an overquota warning system for our unix file store by
> going through an array which contains a bunch of the following data:
> <uid><file quota><inode quota> <actual used> <softlimit> <hard limit>
> <acutal inodes> <soft inodes> <hard inodes>
> odione.adalessandro--   13334   50000       0             39     0     0
> where -- means that file and inodes are below quota
> -+ means inodes are above quota
> +- means the files (K) are above quota
> ++ both are above quota.

If you just want the +- bits to trigger your warnings, and you know that these
characters can't appear in user names, you could just do something like:

$data = "odione.adalessandro-+   13334   50000       0             39     0
0";
($file_quota, $inode_quota) = ($data =~ /([+-])([+-])/);

print "FILE: $file_quota; INODE: $inode_quota\n";


If the user names can include these characters also, you could do an assertion
that they are followed by whitespace:


$data = "odione.hyphenated--name-+   13334   50000       0             39
0     0";
($file_quota, $inode_quota) = ($data =~ /([+-])([+-])(?=\s)/);

print "FILE: $file_quota; INODE: $inode_quota\n";


>
> I need to split this line into the headings shown, it would be nice to use
> the + - as triggers but not neccessary.
>
> An alternative is to take the whole first part <uid><file quota><inode
> quota>  as one variable, and break all the others out, then compare the
> actual to the limits and see if the user is over quota.

By a matching fields using a regex:

$data = "odione.hyphenated--name-+   13334   50000       0             39
0     0";
($username, $file_quota, $inode_quota, $f, $sf, $hf, $ai, $si, $hi) = ($data =~
/([\w-]+)([+-])([+-])\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/);

print join(";", ($username, $file_quota, $inode_quota, $f, $sf, $hf, $ai, $si,
$hi)) ."\n";

(tweaking the username character class as desired - it probably could just be a
".*" anyway).


>
> Any ideas??  I am not sure how to split by white space since the spacing
> changes for each user, but the delimeter is always going to be spaces..

To just split the whole thing on whitespace, use:

$data = "odione.hyphenated--name-+   13334   50000       0             39
0     0";
($username_and_quotas, $f, $sf, $hf, $ai, $si, $hi) = split(" ", $data);

print join(";", ($username_and_quotas, $f, $sf, $hf, $ai, $si, $hi)) ."\n";


Here, splitting on the pattern " " has the special meaning of splitting on
whitespace, not just a single space (which is why I didn't write it as / /,
which would suggest treatment similar to normal regex-based splitting.

Regards,


Ian




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

Date: Tue, 17 Oct 2000 16:03:37 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Run perl script as service
Message-Id: <MPG.145696c72a41a783989825@localhost>

gaddamsr@my-deja.com wrote ..
>I am trying to run my perl script as a service on NT. I wrote a wrapper
>from which i am trying to invoke the perl with parameters. My wrapper
>works for notepad or calculator but not for perl.
>
>is it posible to run the perl script as a service ?..
>
>Any type of help or suggestion is appreciated.

take a look in the standard ActivePerl documentation - under ActivePerl-
Winfaq4 (Windows 9X/NT/2000) .. you should find your question asked and 
answered

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Mon, 16 Oct 2000 14:09:04 -0400
From: Drew Simonis <dsimonis@fiderus.com>
Subject: Re: Save As... Popup box
Message-Id: <39EB4440.B126EE57@fiderus.com>

Rob Donovan wrote:
> 
> Hi,
> 
> I have a perl script that picks a file from a dir and then I want it to
> download it from the browser.
> 
> I know who to send HTML to a browser (ie print content-type text/plain..bla
> bla...), but how do I make the browser download a file or pop up the 'save
> as...' box?
> 


And your Perl question is?  Take this to an HTML group, could ya?


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

Date: Tue, 17 Oct 2000 15:46:32 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Saving Textarea to text file
Message-Id: <MPG.145692c2d00f914e989822@localhost>

John Plaxton wrote ..
>I'm new to Perl having spent time on Delphi, so please could someone help.
>
>I'm trying to save a textarea to a text file.
>
>All works fine until I put in a carriage return. Then I find I am only
>saving the first line.
>
>Here's my code,  (I'm using cgi.pm)
>
>$htext = $q->param('headtext');
>$tempfile="$database.tmp";
>
> open (TEMP, ">$tempfile") or die "Error opening file: $!\n";
>print TEMP "$htext\n";
>close(TEMP);
>
>unlink($headerfile)                     || die "Could not delete file! $!";
>rename($tempfile,$headerfile) || die "Could not rename file! $!";
>
>This obviously won't work!!

obviously (with an assumed meaning of 'work' of course ;)

>Should $htext be an array of lines?

no

>Thanks for your help, in advance

I don't know why you're getting only one line of text (are you sure 
that's what's happening ??) .. because what you should get is a spare CR 
character before each newline

see .. a textarea uses the CRLF sequence as the line ending character .. 
so if you add a newline in the form field (in your browser) then a CRLF 
will come through to your Perl program

now .. you then put all that data into the $htext variable .. then you 
open a file in text mode .. you then output the raw data (which contains 
the CRLFs) to the file

on Win32 Perl converts all LFs in your output to CRLFs (text mode) and 
so you are actually outputting CRCRLF for each line ending that was in 
the input .. in UNIX you're just outputting CRLF (but its newline 
sequence is a single LF) .. hence the extra CR before each newline

solution: get rid of all CRs before outputting the text

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Tue, 17 Oct 2000 07:38:29 +0200
From: Per Kistler <kistler@gmx.net>
To: "Randal L. Schwartz" <merlyn@stonehenge.com>
Subject: Re: Sorting a list
Message-Id: <39EBE5D5.3A58AA3B@gmx.net>

"Randal L. Schwartz" wrote:
t sort mySort @data;
> 
> That's gonna be annoyingly slow for all but the tiniest of lists.  You
> should look into a Schwartzian Transform (named after me, but not *by*
> me) or the GSR sort (named by the authors after themselves :-).

So I did and got:

timethese(10, {
        GRT    => q(our (@data,@res2);
                        @res2 = 
                        map { substr( $_, 1 + index($_, ':') ) }
                        sort map +(split /:/)[1] . ":$_" , @data; ),

        Schwartzian => q(our (@data,@res3);
                        @res3 =
                        map { $_->[0] }
                        sort { $a->[1] cmp $b->[1] } 
                        map { [ $_, (split /:/)[1] ] } @data ),
});

for a an array with 100_000 lines: (on pIII 733)

       Benchmark: timing 10 iterations of GRT, Schwartzian...

       GRT: 43 wallclock secs (43.00 usr +  0.18 sys =
       43.18 CPU) @  0.23/s (n=10)

       Schwartzian: 79 wallclock secs (78.72 usr +  0.06 sys =
       78.78 CPU) @  0.13/s (n=10)


Per.

-- 
Per Kistler, Zuerich, Switzerland
------------------------------------------------------------------------


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

Date: Tue, 17 Oct 2000 08:15:03 +0200
From: Volker Moell <moell@ID-PRO.de>
Subject: Re: Strange behaviour with pos($text), m/.../g and for(...)
Message-Id: <39EBEE67.EA5ABF9E@ID-PRO.de>

Hi, Per!

> I added more comments to the script and got:

Thanks, this makes some points clearer to me.


> This seems to show, that the old perl let the variables $1,$2 set to
> the last value, while 5.7.0 (developer version), deletes them, which
> makes more sense. So your coce proceeds, because you only stop if
> $2 is not defined.

Ok, I see. But what I still didn't understand: Why is there a different
behaviour of the three loops (for, foreach and while) in Perl5.6? 

Up to now I thought the 
   for (my $i = 0; $i < 4; $i++) { ... }
will be expanded to the corresponding
   my $i = 0; while ($i < 4) { ... ; $i++ }
?

    -volker

--- 
Volker Moell <moell@ID-PRO.de> (Products & Developement)
* ID-PRO Deutschland GmbH * Am Hofgarten 20 * D-53113 Bonn
* Tel. +49 (0) 2 28-4 21 54-0 * Fax -3 59
* http://open-for-the-better.com


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

Date: Tue, 17 Oct 2000 05:08:31 GMT
From: trollis@my-deja.com
Subject: Re: Telling difference between a package and a class?
Message-Id: <8sgmsc$rmb$1@nnrp1.deja.com>

In article <Pine.GSO.4.21.0010162249020.25707-100000@crusoe.crusoe.net>,
  japhy@pobox.com wrote:
> [posted & mailed]
>
> On Oct 16, trollis@my-deja.com said:
>
> >I'm trying to identify whether a file is a Perl package or a class.
> >I have been thinking about checking for "@ISA" or "sub new", but
either
> >could exist for both types, right? So, is there a proper way to do
it?
> >Is there a near catch-all way to do it, e.g. 90% of all packages have
> >no "new" sub?
>
> I'm trying to figure out WHY you need/want to do this, but anyway.

I'm writing a tool for API documentation which works in the same way
as javadoc (before anyone bites: I *know* about pod).

> By "package", you mean just a module with variables and functions
defined
> in its own namespace, right?  And by "class", you mean such a package
that
> is expected to have its functions called as methods?

Yes, correct on all accounts. Sorry for the confusion.

> Hmm, I don't know if there's a sure-fire way to do it.
>
>   sub is_class {
>     my $pkg = shift;
>     my $IS_CLASS = 0;
>     local $@;
>
>     eval {
>       $IS_CLASS = 0;
>       my $obj = $pkg->new;
>       $IS_CLASS = UNIVERSAL::isa($obj,$packagename);
>     };
>
>     return $@ ? 0 : $IS_CLASS;
>   }
>
> That's probably crappy, though.

Ok, this is on the border of my Perl knowledge, but I understand what
the above code does. So if I receive the files to test on the command
line, I'll just add their paths to the perl module search path and test
all modules as above? If I catch most of them, then it's fine with me.

Thanks Jeff!

Regards,

/Gunnar
--


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


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

Date: Mon, 16 Oct 2000 15:06:47 -0400
From: Drew Simonis <dsimonis@fiderus.com>
Subject: Re: Tracking user in perl CGI... HELP!
Message-Id: <39EB51C7.CAA4FB43@fiderus.com>

lorddcee@my-deja.com wrote:
> 
> Tracking user in perl CGI... HELP!
> 
> Hi!
> 
> I've just started using Perl (and CGI Too.. ), so please, be gentle :)

This is a very popular topic in comp.infosystems.www.authoring.cgi

> So, I need to keep track of my users during their sessions, 

HTTP (and consequently CGI) has no idea of a session.  There are 
none to track.  You have to create the idea of one programatically.

> Is there any easier, or, better, or... just tell me what you use! to
> keep track of the session of a user... (god i miss the session
> Object...)
> 

ASP user?  Or PHP4?


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

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


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