RE: Reg ex help

2004-01-12 Thread Colin Johnstone
Thanks Wags, terrific.

Colin





"Wagner, David --- Senior Programmer Analyst --- WGO" 
<[EMAIL PROTECTED]>
13/01/2004 12:03 PM

 
To: Colin Johnstone/Australia/Contr/[EMAIL PROTECTED], <[EMAIL PROTECTED]>
cc: 
Subject:RE: Reg ex help



Colin Johnstone wrote:
> Gidday list,
> 
> Please I need a reg ex to return everything to the left of '\WORKAREA'
> 
> in this URL
> 
> $url = 'Y:\default\main\aphrwebAdmin\WORKAREA\Colin'
> 
> I tried
> 
> $url =~ s/(.*?)[\\WORKAREA]/$1/;
> 
> then we wish to remove the drive designation and the leading slash
> 
> Thanking you in anticipation
> 
> Colin
 Here is a shot.  When you use [] you are taking about a character class, 
which is not what you want.

I assume that instead of two passes, you could do one to rid yourself of 
the drive, colon and slash:

use strict;
my $url = 'Y:\default\main\aphrwebAdmin\WORKAREA\Colin';
$url =~ s/^.:.(.*?)\\WORKAREA/$1/;

printf "%-s\n", $url;

which prints out:

default\main\aphrwebAdmin\Colin


Wags ;)


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 






tai64 timestamp

2004-01-12 Thread Joel Newkirk
I'm trying to convert tai64 timestamps (qmail) to human-readable form. 
I installed DateTime::Format::Epoch::TAI64 and dependancies, and below
is the latest mutation of a test program.  The output lists the tai64
timestamp correctly, and the source IP ($src), but the converted time
($dt->hms) is 00:00:00.  What have I missed?  Do I have to explicitly
invoke a conversion of the data or something?

j

#!/usr/bin/perl
#
#
# [EMAIL PROTECTED]
#

use strict;
use warnings;
use DateTime;
use DateTime::Format::Epoch::TAI64;
my $formatter = DateTime::Format::Epoch::TAI64->new();

open QLOG1, "/home/qlog1/smtpd/current" or die $!;
while ()
{
if (/ ok /)
{
my ($time,undef,undef,undef,undef,$src) = split;
# substr to eliminate the leading '@'
$time = substr $time, 1;
print "$time - ";
my $dt = $formatter->parse_datetime( $time );
$time=$dt->hms;
print "\"$src\" at $time\n";
}
}
-- 
"Not all those who wander are lost."  - JRR Tolkien


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Reg ex help

2004-01-12 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Colin Johnstone wrote:
> Gidday list,
> 
> Please I need a reg ex to return everything to the left of '\WORKAREA'
> 
> in this URL
> 
> $url = 'Y:\default\main\aphrwebAdmin\WORKAREA\Colin'
> 
> I tried
> 
> $url =~ s/(.*?)[\\WORKAREA]/$1/;
> 
> then we wish to remove the drive designation and the leading slash
> 
> Thanking you in anticipation
> 
> Colin
 Here is a shot.  When you use [] you are taking about a character class, which is not 
what you want.

I assume that instead of two passes, you could do one to rid yourself of the drive, 
colon and slash:

use strict;
my $url = 'Y:\default\main\aphrwebAdmin\WORKAREA\Colin';
$url =~ s/^.:.(.*?)\\WORKAREA/$1/;

printf "%-s\n", $url;

which prints out:

default\main\aphrwebAdmin\Colin


Wags ;)


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




double-log-tail

2004-01-12 Thread Joel Newkirk
I'm interested in tailing two logs (qmail) simultaneously, and
interleaving the data in something approaching chronological sequence,
as well as dealing with logfile rotation gracefully.

Any suggestions?

j

-- 
"Not all those who wander are lost."  - JRR Tolkien


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Reg ex help

2004-01-12 Thread Colin Johnstone
Gidday list,

Please I need a reg ex to return everything to the left of '\WORKAREA'

in this URL 

$url = 'Y:\default\main\aphrwebAdmin\WORKAREA\Colin'

I tried

$url =~ s/(.*?)[\\WORKAREA]/$1/;

then we wish to remove the drive designation and the leading slash

Thanking you in anticipation

Colin

Re: RFC: Package == class == object type

2004-01-12 Thread Jenda Krynicky
From: "Rob Dixon" <[EMAIL PROTECTED]>
> You've created a package/class called 'Trainset' but decided not to
> instantiate it as an object. As James says, this is therefore no more
> than a namespace and could probably be more obviously coded as simple
> data items and subroutines in the 'main' namespace. At the very least,
> if you choose to have a bucket labelled 'Trainset' for all related
> subroutines and data, you should avoid writing methods for it. A call
> like
> 
>   Trainset->method()
> 
> is hiding the more obvious and truthful
> 
>   Trainset::method()
> 
> where there is no such thing as a 'Trainset' object. 

Well ... it may make sense to use the method call format even if 
there are no objects.

Inheritance works even with packages:

#
package A;

sub foo {print "foo called\n"}

package B;
@ISA = qw(A);
sub bar {print "bar called\n"};

package main;

B->bar();
B->foo();

B::bar();
B::foo();
__END__

This is actually used by File::Spec. (Though I think in that case the 
desing is ... let's say ... strange.)

> As a secondary point, I think you're also confounding your learning
> process by considering object destruction before you have anything
> working. My advice is to get the basics going first, and then consider
> optimisation and memory conservation as a secondary chore. Certainly
> you should forget about implementing a DESTROY or 'delete' method
> until it proves necessary: the vast majority of Perl modules have no
> such method.

I think he just was told to create destroy methods in his Java/C# 
class :-)

In either case ... just to reinforce your point ... in Perl you only 
have to have a DESTROY method if you need to do some cleanup.

Returning handles to the system, closing connections, freeing memory 
allocated outside the Perl memory space by the C part of your module, 
updating some object counts and similar structures ...

Most often Perl will just do the right thing.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




AppConfig - better way?

2004-01-12 Thread John McKown
I just converted from using environment variables to using AppConfig. 
Thanks to those who suggested it, it works very well. However, I want to 
do something a bit different. Example:

my $config->AppConfig->new();
$config->define('SUFFIXES=s@');
...
my $suffixes=$config->get('SUFFIXES');
my @suffix = split ' ', join ' ',@$suffixes;
foreach $suffix (@suffix) {
.. code
}

My question desire is to allow the following in the config file:

SUFFIXES=.a .b .c

Unfortunately, without the "split ' ',join ' ',[EMAIL PROTECTED];" line, I get a 
suffix of ".a .b .c" whereas I want ".a", ".b", ".c" as if I had specified
three separate SUFFIXES= lines.

Is there a better way to do this?

--
Maranatha!
John McKown


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: RFC: Package == class == object type

2004-01-12 Thread James Edward Gray II
On Jan 12, 2004, at 2:42 PM, Rob Dixon wrote:

Hi Gary.

I'm quite concerned about this thread. I think we could help you a
lot more if we had a better grasp of the problem: instead we've been
answering individual questions that you've raised, hoping that they
help you to achieve your goal but without any real idea of where
you're headed.
and

Finally, throughout this thread we've been working with our imaginings
of your design and code. It would help you as well as the group if you
were to post some actual code - this will be much more descriptive of
your ideas than you may imagine, and will help us to address the real
problems you're facing.
Rob's always so much smarter than I am.  Darn him!  :P

I just wanted to say that I think this is an excellent idea.  I think 
if you could get across to us how a small Trainset works on minimal 
level (using each of your objects once or twice), we might be able to 
critique code you provide or roll some of our own.  I bet you would 
learn a lot more for that than all these guesses we've been making, 
just like Rob said.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: script works from shell but not http

2004-01-12 Thread Dan Anderson
On Mon, 2004-01-12 at 12:12, [EMAIL PROTECTED] wrote:
> Thanks everyone,  
> 
> The reason the BEGIN statement was there is I don't exactly know where my 
> error logs are and it's faster to just read the file.  Plus if it wasn't  a 
> script problem the err.txt file wouldn't be created.

I don't know if anyone has mentioned this, but you are clobbering your
error logs and not acquiring locks on the files, nor do you have any
provisions to prevent a race condition should 2 people be using your
script at the exact same time.

You may want to reconsider using it for anything other then testing. 
Then again, maybe you're using it on a very small scale and the
probability of a race condition is so low as to not make it worth it.

-Dan


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: RFC: Package == class == object type

2004-01-12 Thread Rob Dixon
Hi Gary.

I'm quite concerned about this thread. I think we could help you a
lot more if we had a better grasp of the problem: instead we've been
answering individual questions that you've raised, hoping that they
help you to achieve your goal but without any real idea of where
you're headed.

Paul has come the nearest to echoing my thoughts so far, albeit for
different reasons, so I'm tagging this post onto his.

Paul Johnson wrote:
>
> On Mon, Jan 12, 2004 at 04:21:58PM +, Gary Stainburn wrote:
>
> > The only functionality gain would be the ability to have multiple trainsets.
> > This will never be requred.
>
> I've not been fully following this thread, but this comment caught my
> eye.  I think that is a very dangerous assertion to make.  Good code is
> often used in ways its original author didn't envisage.  Of course, the
> worse your code, the more likely your comment is to be true.  ;-)
>
> This is a general comment and you might feel that it doesn't apply in
> this specific case.  You might well be right, but I think that in
> general good designs try hard not to paint themselves into a corner.

You've created a package/class called 'Trainset' but decided not to
instantiate it as an object. As James says, this is therefore no more
than a namespace and could probably be more obviously coded as simple
data items and subroutines in the 'main' namespace. At the very least,
if you choose to have a bucket labelled 'Trainset' for all related
subroutines and data, you should avoid writing methods for it. A call
like

  Trainset->method()

is hiding the more obvious and truthful

  Trainset::method()

where there is no such thing as a 'Trainset' object. Such a bundle will
of course have no interest in constructor or destructor methods, as there
are no objects to create or destroy.

As Paul said, it's a good idea to write code to be as reuseable as
possible, as you don't know when somebody might get their hands on
it and use it in the next Cruise missile AI software. But in your case
you're writing a program just for your own teaching, and this doesn't
really apply. Would it help to compare your 'Trainset' non-class to
a learner's car built with no brakes, and the clutch and accelerator
pedals swapped (as proper functionality 'will never be required')?
(Forgive my ignorance of US English terms.) The time to bend the rules
comes only when experience tells us how far they can safely be bent.

As a secondary point, I think you're also confounding your learning
process by considering object destruction before you have anything
working. My advice is to get the basics going first, and then consider
optimisation and memory conservation as a secondary chore. Certainly
you should forget about implementing a DESTROY or 'delete' method until
it proves necessary: the vast majority of Perl modules have no such
method.

Finally, throughout this thread we've been working with our imaginings
of your design and code. It would help you as well as the group if you
were to post some actual code - this will be much more descriptive of
your ideas than you may imagine, and will help us to address the real
problems you're facing.

Hoping this is useful in some way, and wishing you well,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: coping txt files over a peer to peer.

2004-01-12 Thread david
William Ampeh wrote:
>
> 1.  I realized you used TCP instead of UDP for the protocol.  Are there
> any advantages of one over the other besides the fact the known drawback
> of standard UDP protocol (i..e, no guarantee to sequencing and unreliable
> delivery)?
> 

tcp is much more popular than udp as well... :-)

>
> 2. Your sysread had a 1024 bytes.  What are the implications of either
> increasing or decreasing this number?
> 

most os is able to handle 1k of memory much more faster than any other size. 
depending on your application, increasing or decreasing this number might 
not matter much. feel free to experiment with a different number.

david
-- 
sub'_{print"@_ ";* \ = * __ ,\ & \}
sub'__{print"@_ ";* \ = * ___ ,\ & \}
sub'___{print"@_ ";* \ = *  ,\ & \}
sub'{print"@_,\n"}&{_+Just}(another)->(Perl)->(Hacker)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Regular Exp for Numerics

2004-01-12 Thread Rob Dixon
Hi Mallik.

You asked this question yesterday. Here is a copy of my answer
to yesterday's post.

Rob


Mallik wrote:
>
> I have to compare numeric values as below
>
> if (($segsep == 13) || ($segsep == 10) || ($segsep == 0))
>
> Can I use the reg exp as below
>
> if ($segsep =~ /^(13|10|0)$/)
>
> My question is, is it adviceable to use reg exp for numeric values (entire
> value).
> If yes, why?
> If not, why?

No. Because it's slower, and because several different strings can have
the same numeric value.

  for ( qw/ 12 00012 1.2E1 / ) {
print "Numeric match for $_\n" if $_ == 12;
  }

succeeds in all three cases, but clearly

  for ( qw/ 12 00012 1.2E1 / ) {
print "Regexp match for $_\n" if /^12$/;
  }

would match for only the first value.

If you're looking for a more concise way of matching any of a list of numbers
then try

  if ( grep $segsep == $_, 13, 10, 0 )

HTH,

Rob





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: RFC: Package == class == object type

2004-01-12 Thread James Edward Gray II
On Jan 12, 2004, at 11:44 AM, Gary Stainburn wrote:

This is a very good point, and I am currently looking at changing my 
code to
better modularise and to have a Trainset object.

My two stumbling blocks are still:

1)  How could a sub-class access the Trainset globals without knowing 
the
instance of the Trainset object?
There is no law about keeping a reference to a parent object, as I 
believe you figured out below.

2) How do they do this quickly?
Ah, here's the tricky question!  Perl can be slow, in comparison to 
some things.  Perl's objects sure aren't famous for their speed either, 
so you're definitely in the problem zone.

However, let's keep our wits about us as we discuss this.  Slow in 
modern day computing is still pretty dang fast.  I've seen operations 
be "100 times slower" and still happen in the blink of an eye.  Believe 
me, it would take a lot of Perl object work to get my G5 to start 
behaving like a dog.

It may be that you're in the realm of needing to worry about this.  If 
you're going to have a LOT of objects and/or be making a LOT of method 
calls and need all your answers VERY FAST, you may run into problems.  
Those are all relative terms though.  Computers can just plain handle a 
lot these days.

The rule of thumb for optimizing is:  Don't do it until you must!  What 
if you build this whole thing and it's already "fast enough" (the super 
important speed goal to meet)?  Good.  If it's not, you have a lot of 
options at that point.  Profiling to find out what's slow and looking 
for ways to speed that up or getting really serious and using some 
linked in C code which is sure hard to beat speed wise.  You just don't 
want to make that a problem now, before you really know how much of a 
problem it is and how far your are going to have to go to fix it.

One possibility I've just thought of is to store the Trainset object 
as a ref
inside each sub-class object.  This would then allow for multiple 
Trainset
instances, but would greatly increase refcounts, memory usage, 
complexity and
expense of access etc.
See speed issue discussion above and apply it to each of these areas in 
turn.  Honestly, I'm a lot more concerned about the speed than anything 
you list down here and I'm not super concerned about any of it.  You 
shouldn't be either yet.  Keep your focus on building it right, for 
now.  If you keep the code clean and well designed, you'll be able to 
fix these problems somehow, should any of them ever actually arise.

Hope that helps.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: RFC: Package == class == object type

2004-01-12 Thread James Edward Gray II
On Jan 12, 2004, at 10:21 AM, Gary Stainburn wrote:

I'm trying to model a very simple neural net, where the changes in one 
block
affect all of it's neighbours. e.g. If one block becomes occupied the 
signal
to enter it should change to red.  The signal of the block in rear 
should
change to caution.

Any train occupying the block in rear would have to stop.

If a signaller in a signalbox throw a lever to set a call-ahead 
signal, the
train should be able to draw forward.

Thus:
Just throwing out more ideas below.  Remember that I've already 
admitted to knowing very little about this.

* blocks must be able to talk to each other
Would each block having a link to the blocks next to it (think linked 
list) cover the needed information?

* blocks must be able to read signals
Or get passed the needed signal information when they are being called 
on to do something.

* levers must be allowed to set signals (and points/switches)
This makes me wonder if Lever really needs to be it's own class or just 
methods of other classes.

* signalboxes must be able to own blocks, points, signals, and levers
(a signalman can only throw his own signals)
This sounds like an excellent choke point to manage all these things.

As you can see, there is a hell of a lot of cross-object talk which is 
why I
decided to put everything in to one namespace.
Well, objects that couldn't talk to each other would be pretty darn 
boring.  Cross talk is okay.  That's how the real Trainset works after 
all, right?

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: coping txt files over a peer to peer.

2004-01-12 Thread William.Ampeh




Hello David,

Thanks for your the sockets code.  I have a few questions though.

1.  I realized you used TCP instead of UDP for the protocol.  Are there any
advantages of one over the other besides the fact the known drawback of
standard UDP protocol (i..e, no guarantee to sequencing and unreliable
delivery)?

2. Your sysread had a 1024 bytes.  What are the implications of either
increasing or decreasing this number?

Thanks again for your help.

__

William Ampeh (x3939)
Federal Reserve Board


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Regular Exp for Numerics

2004-01-12 Thread Mallik
Dear Friends,

I have to compare numeric values as below

if (($segsep == 13) || ($segsep == 10) || ($segsep == 0))

Can I use the reg exp as below

if ($segsep =~ /^(13|10|0)$/)

My question is, is it adviceable to use reg exp for numeric values (entire
value).
If yes, why?
If not, why?

Thank you,
Mallik


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: RFC: Package == class == object type

2004-01-12 Thread Gary Stainburn
On Monday 12 Jan 2004 5:26 pm, Paul Johnson wrote:
> On Mon, Jan 12, 2004 at 04:21:58PM +, Gary Stainburn wrote:
> > The only functionality gain would be the ability to have multiple
> > trainsets. This will never be requred.
>
> I've not been fully following this thread, but this comment caught my
> eye.  I think that is a very dangerous assertion to make.  Good code is
> often used in ways its original author didn't envisage.  Of course, the
> worse your code, the more likely your comment is to be true.  ;-)
>
> This is a general comment and you might feel that it doesn't apply in
> this specific case.  You might well be right, but I think that in
> general good designs try hard not to paint themselves into a corner.

This is a very good point, and I am currently looking at changing my code to 
better modularise and to have a Trainset object.

My two stumbling blocks are still:

1)  How could a sub-class access the Trainset globals without knowing the 
instance of the Trainset object?

2) How do they do this quickly?

One possibility I've just thought of is to store the Trainset object as a ref 
inside each sub-class object.  This would then allow for multiple Trainset 
instances, but would greatly increase refcounts, memory usage, complexity and 
expense of access etc.
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: RFC: Package == class == object type

2004-01-12 Thread Randal L. Schwartz
> "Gary" == Gary Stainburn <[EMAIL PROTECTED]> writes:

Gary> I do have object types:

Gary> * Block
Gary> * point (switch to american readers)
Gary> * signal
Gary> * lever
Gary> * signalbox

In order to have an "object" of type "signal", you'll have to have
a package named "signal", and bless things into the "signal" package,
and have subroutines named "signal::method1", etc.

This is not recommended.  Lowercase packagenames are reserved for
pragmas.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: RFC: Package == class == object type

2004-01-12 Thread Paul Johnson
On Mon, Jan 12, 2004 at 04:21:58PM +, Gary Stainburn wrote:

> The only functionality gain would be the ability to have multiple trainsets.  
> This will never be requred.

I've not been fully following this thread, but this comment caught my
eye.  I think that is a very dangerous assertion to make.  Good code is
often used in ways its original author didn't envisage.  Of course, the
worse your code, the more likely your comment is to be true.  ;-)

This is a general comment and you might feel that it doesn't apply in
this specific case.  You might well be right, but I think that in
general good designs try hard not to paint themselves into a corner.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Matching invalid characters in a URL

2004-01-12 Thread Rob Dixon
Kevin Zembower wrote:
>
> Thank you all for some first thoughts and clarifying questions.
>
> I'm trying to discard any URL with any character that is not an upper- or lower-case
> letter, digit, or the characters $-_.+!*'(), . I realize that some other characters 
> can be
> used in special circumstances, but I don't have to allow for any of these in my 
> program.
>
> I thought that my perl statement:
>  if ($url =~ /^[^A-Za-z0-9$-_.+!*'(),]+$/) { #if there are any invalid URL 
> characters in the string
>  # Remember, special regex 
> characters lose their meaning inside []
> print "Invalid character in URL at line $.: $url\n";
> next;
>  }
>  is saying:
> if the variable $url contains any characters not in the set 
> [A-Za-z0-9$-_.+!*'(),]+$/), print "Invalid ..."
>
> So, I think I need help in two areas; Do I have my logic backwards because I'm 
> trying to match any
> character in a variable, and, How do I write the match statement to do what I want.

Hi Kevin.

Take note of Charles' points, but also note that Perl is trying to expand
the built-in variable $- into your regex. This is almost certainly zero
unless you're using formats, so you're including the digit zero for a second
time instead of dollar and dash.

If you escape the dollar and code

  [A-Za-z0-9\$-_.+!*'(),]

instead, then your class will include all characters from dollar up to
underscore. So you need to escape both  dollar and dash:

  if ($url =~ /[A-Za-z0-9\$\-_.+!*'(),]/) {
# Remember MOST special regex characters lose their meaning inside []
print "Invalid character in URL at line $.: $url\n";
next;
  }

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: script works from shell but not http

2004-01-12 Thread Motherofperls
Thanks everyone,  

The reason the BEGIN statement was there is I don't exactly know where my 
error logs are and it's faster to just read the file.  Plus if it wasn't  a 
script problem the err.txt file wouldn't be created.

I'm not clear about why the script could function from the shell and not the 
browser.

I called the person who is above the reseller that provided me with the site.
The problem was the permissions were set to a wrong username by the reseller. 
 He is just learning the ropes of hosting.  I empathize with him over typos.

His response time was 2 days.  Now my only dilemma is do I go to his reseller 
for cheaper hosting.   


Weekly list FAQ posting

2004-01-12 Thread casey
NAME
beginners-faq - FAQ for the beginners mailing list

1 -  Administriva
  1.1 - I'm not subscribed - how do I subscribe?
Send mail to <[EMAIL PROTECTED]>

You can also specify your subscription email address by sending email to
(assuming [EMAIL PROTECTED] is your email address):

<[EMAIL PROTECTED]>.

  1.2 -  How do I unsubscribe?
Now, why would you want to do that? Send mail to
<[EMAIL PROTECTED]>, and wait for a response. Once you
reply to the response, you'll be unsubscribed. If that doesn't work,
find the email address which you are subscribed from and send an email
like the following (let's assume your email is [EMAIL PROTECTED]):

<[EMAIL PROTECTED]>

  1.3 - There is too much traffic on this list. Is there a digest?
Yes. To subscribe to the digest version of this list send an email to:

<[EMAIL PROTECTED]>

To unsubscribe from the digest, send an email to:

<[EMAIL PROTECTED]>

This is a high traffic list (100+ messages per day), so please subscribe
in the way which is best for you.

  1.4 - Is there an archive on the web?
Yes, there is. It is located at:

http://archive.develooper.com/beginners%40perl.org/

  1.5 - How can I get this FAQ?
This document will be emailed to the list once a week, and will be
available online in the archives, and at http://learn.perl.org/

  1.6 - I don't see something in the FAQ, how can I make a suggestion?
Send an email to <[EMAIL PROTECTED]> with your suggestion.

  1.7 - Is there a supporting website for this list?
Yes, there is. It is located at:

http://beginners.perl.org/

  1.8 - Who owns this list?  Who do I complain to?
Casey West owns the beginners list. You can contact him at
[EMAIL PROTECTED]

  1.9 - Who currently maintains the FAQ?
Kevin Meltzer, who can be reached at the email address (for FAQ
suggestions only) in question 1.6

  1.10 - Who will maintain peace and flow on the list?
Casey West, Kevin Meltzer and Ask Bjoern Hansen currently carry large,
yet padded, clue-sticks to maintain peace and order on the list. If you
are privately emailed by one of these folks for flaming, being
off-topic, etc... please listen to what they say. If you see a message
sent to the list by one of these people saying that a thread is closed,
do not continue to post to the list on that thread! If you do, you will
not only meet face to face with a XQJ-37 nuclear powered pansexual
roto-plooker, but you may also be taken off of the list. These people
simply want to make sure the list stays topical, and above-all, useful
to Perl beginners.

  1.11 - When was this FAQ last updated?
Sept 07, 2001

2 -  Questions about the 'beginners' list.
  2.1 - What is the list for?
A list for beginning Perl programmers to ask questions in a friendly
atmosphere.

  2.2 - What is this list _not_ for?
* SPAM
* Homework
* Solicitation
* Things that aren't Perl related
* Monkeys
* Monkeys solicitating homework on non-Perl related SPAM.

  2.3 - Are there any rules?
Yes. As with most communities, there are rules. Not many, and ones that
shouldn't need to be mentioned, but they are.

* Be nice
* No flaming
* Have fun

  2.4 - What topics are allowed on this list?
Basically, if it has to do with Perl, then it is allowed. You can ask
CGI, networking, syntax, style, etc... types of questions. If your
question has nothing at all to do with Perl, it will likely be ignored.
If it has anything to do with Perl, it will likely be answered.

  2.5 - I want to help, what should I do?
Subscribe to the list! If you see a question which you can give an
idiomatic and Good answer to, answer away! If you do not know the
answer, wait for someone to answer, and learn a little.

  2.6 - Is there anything I should keep in mind while answering?
We don't want to see 'RTFM'. That isn't very helpful. Instead, guide the
beginner to the place in the FM they should R :)

Please do not quote the documentation unless you have something to add
to it. It is better to direct someone to the documentation so they
hopefully will read documentation above and beyond that which answers
their question. It also helps teach them how to use the documentation.

  2.7 - I don't want to post a question if it is in an FAQ. Where should I
look first?
Look in the FAQ! Get acquainted with the 'perldoc' utility, and use it.
It can save everyone time if you look in the Perl FAQs first, instead of
having a list of people refer you to the Perl FAQs :) You can learn
about 'perldoc' by typing:

"perldoc perldoc"

At your command prompt. You can also view documentation online at:

http://www.perldoc.com and http://www.perl.com

  2.8 Is this a high traffic list?
YES! You have been warned! If you don't want to get ~100 emails per day
from this list, consider s

Re: RFC: Package == class == object type

2004-01-12 Thread Gary Stainburn
On Monday 12 Jan 2004 3:01 pm, James Edward Gray II wrote:
> On Jan 12, 2004, at 5:27 AM, Gary Stainburn wrote:
> > Hi folks,
>
> Hello again.
>
> > I'm after peoples opinions on my (beginner's) slant objects in perl.
>
> I'll see what I can do.
>
> > In much of what I've read, there seems to be the implied rule that
> >
> > Package Name == Class == Object Type,
> >
> > specifically MyObject would be a object of class MyObject which would
> > be held
> > in a package MyObject,  and would probably be created by calling
> > MyObject->new.
>
> You seem to be getting it just fine to me.
>
> > In my Package Trainset, I have class Trainset with variables global to
> > that
> > class.  However, I don't have an object type of Trainset
>
> Well, then it's not really a "class" is it?  It's just a package or a
> namespace, if you will.
>
> > (In a previous  thread someone suggested creating one to hold the
> > class variables instead of  using globals, to enable me to create more
> > than one trainset. I decided that
> > would create more problems than it would solve here).
>
> Create more problems than it solves?  Pardon the pun, but I think your
> logic just derailed.  ;)
>
> I recall a big discussion on this list when we saw your code about what
> that external hash in the constructor was and if it was a good idea to
> be manipulating things like that.  If nothing else, I think we can
> assume from this that the intent of the code is not crystal clear.
> That means you stand to gain readability by objectifying Trainset.

I think the confusion here was that in my program I accessed 
%Trainset::__Blocks.  This is no longer possible ('my' now used instead of 
'our') and was there only as crude debugging (now moved inside the module).

Access to all objects will be done through the approriate method, thus 
cleaning up the interface.

>
> The suggestion was made, as you note above, because the code would gain
> functionality from the change as well.
>
> That's two plusses, what do you stand to lose?

The only functionality gain would be the ability to have multiple trainsets.  
This will never be requred. The two proposed uses for the module are:

a) automate the control of inteligent electric model train sets.
b) Signalbox simulator and training aid for Preserved Steam railways.

What I'll lose I'll cover below.

>
> > I do have object types:
> >
> > * Block
> > * point (switch to american readers)
> > * signal
> > * lever
> > * signalbox
> >
> > These are all created by calling Trainset->Block etc., and the code
> > for all
> > object types are in the Trainset package.
> >
> > My question is:
> >
> > Is there anything wrong with what I'm doing, or any pit-falls I need
> > to watch
> > out for?
>
> I would prefer and I think it would be better OO design if the classes
> where broken out into separate modules.  Maybe something like:
>
> Trainset.pm
> Trainset/Block.pm (package Trainset::Block)
> Trainset/Point.pm (package Trainset::Point)
> Trainset/Signal.pm (package Trainset::Signal)
> Trainset/Lever.pm (package Trainset::Lever)
> Trainset/SignalBox.pm (package Trainset::SignalBox)
>

I had originally thought of doing it this way, but considered it to be a bit 
over the top for the size of the code being created (quickly changing my mind 
though).

This was mainly because of the increase in complexity of having all the 
various objects in different name spaces. Again, see below.


> > Is there a better way to do this, without further complicating or
> > slowing of
> > the code (e.g. indirect access to the globals via Trainset methods as
> > would
> > be needed if I created a Trainset object)?
>
> I'm not sure if I totally understand the complaint above, but let me
> see if I can change your thinking anyway...  :D
>

In the the perldocs it compares having direct access to class globals with 
using methods to access them.  It states that while using methods provides 
better control over the contents, it is exponentially slower than direct 
access.  As both my intended uses are going to be real-time, I don't want any 
method slower than is necessary.

The other benefit mentioned in the perldocs is the simplicity and readability 
of the code:

If, within a block I wanted to access all other blocks I could simply do

foreach keys %_BLOCKS

instead of having to find the Trainset object which is a variable probably 
somewhere in main::, then calling a method to read the keys, then use another 
method to read the block objects.

This is why I've gone for having everything in one package and using class 
global variables.

> I was envisioning Trainset as the interface object to outside code.  I
> wouldn't think a user would be wanting to call those five extra
> constructors and attach the new object to the right part of the
> Trainset.  I would think they would call something like
> $trainset->add_signal(SOME PARAMS HERE) and the Trainset object would
> handle all the gory details, including creating the Signal object.
>

Thi

Re: RFC: Package == class == object type

2004-01-12 Thread James Edward Gray II
On Jan 12, 2004, at 5:27 AM, Gary Stainburn wrote:

Hi folks,
Hello again.

I'm after peoples opinions on my (beginner's) slant objects in perl.
I'll see what I can do.

In much of what I've read, there seems to be the implied rule that

Package Name == Class == Object Type,

specifically MyObject would be a object of class MyObject which would 
be held
in a package MyObject,  and would probably be created by calling
MyObject->new.
You seem to be getting it just fine to me.

In my Package Trainset, I have class Trainset with variables global to 
that
class.  However, I don't have an object type of Trainset
Well, then it's not really a "class" is it?  It's just a package or a 
namespace, if you will.

(In a previous  thread someone suggested creating one to hold the 
class variables instead of  using globals, to enable me to create more 
than one trainset. I decided that
would create more problems than it would solve here).
Create more problems than it solves?  Pardon the pun, but I think your 
logic just derailed.  ;)

I recall a big discussion on this list when we saw your code about what 
that external hash in the constructor was and if it was a good idea to 
be manipulating things like that.  If nothing else, I think we can 
assume from this that the intent of the code is not crystal clear.  
That means you stand to gain readability by objectifying Trainset.

The suggestion was made, as you note above, because the code would gain 
functionality from the change as well.

That's two plusses, what do you stand to lose?

I do have object types:

* Block
* point (switch to american readers)
* signal
* lever
* signalbox
These are all created by calling Trainset->Block etc., and the code 
for all
object types are in the Trainset package.

My question is:

Is there anything wrong with what I'm doing, or any pit-falls I need 
to watch
out for?
I would prefer and I think it would be better OO design if the classes 
where broken out into separate modules.  Maybe something like:

Trainset.pm
Trainset/Block.pm (package Trainset::Block)
Trainset/Point.pm (package Trainset::Point)
Trainset/Signal.pm (package Trainset::Signal)
Trainset/Lever.pm (package Trainset::Lever)
Trainset/SignalBox.pm (package Trainset::SignalBox)
Is there a better way to do this, without further complicating or 
slowing of
the code (e.g. indirect access to the globals via Trainset methods as 
would
be needed if I created a Trainset object)?
I'm not sure if I totally understand the complaint above, but let me 
see if I can change your thinking anyway...  :D

I was envisioning Trainset as the interface object to outside code.  I 
wouldn't think a user would be wanting to call those five extra 
constructors and attach the new object to the right part of the 
Trainset.  I would think they would call something like 
$trainset->add_signal(SOME PARAMS HERE) and the Trainset object would 
handle all the gory details, including creating the Signal object.

Does that give you any new ideas?

I should probably say that I know very little about what you're trying 
to create here and even less about trains, so if I'm being dumb, just 
ignore me.  I'm just trying to toss out some general ideas.

Good luck.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Matching invalid characters in a URL

2004-01-12 Thread Charles K. Clarkson
KEVIN ZEMBOWER <[EMAIL PROTECTED]> wrote:
: 
: I'm trying to discard any URL with any character that is not 
: an upper- or lower-case letter, digit, or the characters
: $-_.+!*'(), . I realize that some other characters can be
: used in special circumstances, but I don't have to allow for
: any of these in my program.
: 
: I thought that my perl statement:
:   if ($url =~ /^[^A-Za-z0-9$-_.+!*'(),]+$/) {
:   print "Invalid character in URL at line $.: $url\n";
:   next;
:   }
:  is saying:
: if the variable $url contains any characters not in the set 
: [A-Za-z0-9$-_.+!*'(),]+$/), print "Invalid ..."

No. It is saying if ALL characters are invalid ...

Ignore the character class and look at the rest. There
is no room for a valid character:

  /
^# start at the beginning of the string
  [^A-Za-z0-9$-_.+!*'(),]+
$# end at the end of the string
  /

Your anchors are dragging you down. You want to find the
first invalid character. After that it doesn't matter. This
should be fine.

  /[^A-Za-z0-9$-_.+!*'(),]/ 


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328








-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Matching invalid characters in a URL

2004-01-12 Thread KEVIN ZEMBOWER
Thank you all for some first thoughts and clarifying questions.

I'm trying to discard any URL with any character that is not an upper- or lower-case 
letter, digit, or the characters $-_.+!*'(), . I realize that some other characters 
can be 
used in special circumstances, but I don't have to allow for any of these in my 
program. 

I thought that my perl statement:
 if ($url =~ /^[^A-Za-z0-9$-_.+!*'(),]+$/) { #if there are any invalid URL 
characters in the string
 # Remember, special regex 
characters lose their meaning inside []
print "Invalid character in URL at line $.: $url\n";
next;
 }
 is saying:
if the variable $url contains any characters not in the set 
[A-Za-z0-9$-_.+!*'(),]+$/), print "Invalid ..."

So, I think I need help in two areas; Do I have my logic backwards because I'm trying 
to match any
character in a variable, and, How do I write the match statement to do what I want.

Thanks, again, for all your help and suggestions.

-Kevin

>>> Wiggins d Anconia <[EMAIL PROTECTED]> 01/09/04 05:01PM >>>


> I'm trying to throw out URLs with any invalid characters in them, like
> '@". According to http://www.ietf.org/rfc/rfc1738.txt :
>Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
>reserved characters used for their reserved purposes may be used
>unencoded within a URL.
> 
> I'd like to throw out a URL like
> 'http://jncicancerspectrum.oupjournals.org/cgi/content/full/jnci;91/3/252' 
> (even though this one works perfectly fine. Go figure.). I've tried:
> if ($url =~ /^[^A-Za-z0-9$-_.+!*'(),]+$/) { #if there are any
> invalid URL characters in the string
> # Remember, special
> regex characters lose their meaning inside []
>print "Invalid character in URL at line $.: $url\n";
>next;
> }
> 
> According to my Camel, special regex characters are supposed to lose
> their special functioning inside []. Yet, that obviously isn't true for
> '-' used to separate the start and end of a range. I thought the fourth
> '-' at '$-' was probably indicating a range, so I tried to escape it by
> preceding it with a backslash or '\Q' but both gave strange errors about
> uninitiated strings in concatenations.
> 
> Any suggestions? Thanks for your help and thoughts.
> 

Did you mean to leave out those characters the RFC mentions are reserved
for some schemes, 

"The characters ";", "/", "?", ":", "@", "=" and "&" are the characters
which may be reserved for special meaning within a scheme."

They should be in the class as well, since you are negating it right? 
Just trying to understand completely so I don't throw you off with any
dumb remarks...

http://danconia.org 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RFC: Package == class == object type

2004-01-12 Thread Gary Stainburn
Hi folks,

I'm after peoples opinions on my (beginner's) slant objects in perl.

In much of what I've read, there seems to be the implied rule that

Package Name == Class == Object Type,

specifically MyObject would be a object of class MyObject which would be held 
in a package MyObject,  and would probably be created by calling 
MyObject->new.

In my Package Trainset, I have class Trainset with variables global to that 
class.  However, I don't have an object type of Trainset (In a previous 
thread someone suggested creating one to hold the class variables instead of 
using globals, to enable me to create more than one trainset. I decided that 
would create more problems than it would solve here).

I do have object types:

* Block
* point (switch to american readers)
* signal
* lever
* signalbox

These are all created by calling Trainset->Block etc., and the code for all 
object types are in the Trainset package.

My question is:

Is there anything wrong with what I'm doing, or any pit-falls I need to watch 
out for?

Is there a better way to do this, without further complicating or slowing of 
the code (e.g. indirect access to the globals via Trainset methods as would 
be needed if I created a Trainset object)?
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Clearing Arrays

2004-01-12 Thread Rob Dixon
Colin (Support) wrote:
>
> I have this little memory blockage again.
> If I 'push' data from a database into an array to look/manipulate the data
> and then using the same array name, 'push' data into the array from another
> database, the data from the second DB file is added to the data of the
> first. How can I clear the first lot of data and start a fresh with an
> empty array ??

Hi Colin.

Use

  @array = ();

or

  undef @array;

(I like the easy ones!)

Cheers,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Clearing Arrays

2004-01-12 Thread Support
Hi All
I have this little memory blockage again.
If I 'push' data from a database into an array to look/manipulate the data 
and then using the same array name, 'push' data into the array from another 
database, the data from the second DB file is added to the data of the 
first. How can I clear the first lot of data and start a fresh with an 
empty array ??
Cheers
Colin (from the future)

---
www.rentmyplace.co.nz
The ultimate in that holiday spot away from the maddening crowd
Join as a member today its FREE
List your holiday accommodation for FREE
 

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.209 / Virus Database: 261.6.1 - Release Date: 8/01/2004


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Do Else Unless Statements Exist?

2004-01-12 Thread Rob Dixon
Dan Anderson wrote:
>
> Does Perl have any kind of else / unless statements, sort of like
> elsif?  I tried:
>
> if ($foo) {
> }
> else unless ($bar) {
> }
>
> but it just gave me syntax errors.  And I guess I could just do:
> if ($foo) {
> }
> else {
>   unless ($bar) {
>   }
> }
>
> But the place in the code I was trying it was for clarity, and all the
> nested unlesses don't seem to add to clarity.

Hi Dan.

No, there's no 'else unless'. It would have to be a single language word
anyway, the obvious choice being 'elsunless' which looks awful.

What you can do is

  unless () {
:
  }
  elsif () {
:
  }
  else {

  }

which may help if you can rewrite your conditions in these terms.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]