Maybe Stupid RegEx Question

2004-02-12 Thread Bastian Angerstein

Hi 

I have two strings 0x1479ee und 0x1479fe. 

The strings a in $var1 and $var2.

if I do:
  if ( $var2 =~ /\Q$var1\E/) 

 It matches.

  how can I match an the string and not on each sign? 


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




Re: Which is better, opening and closing, or a massive file opening and a massive closing?

2004-02-12 Thread Jenda Krynicky
From: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> I am wondering if it is more processor intensive to open the 42
> separate files at one time, parse the data, and then close all the
> files, or if I should try to re-write the parse to open the correct
> file, dump the data, and then close that file, then repeat the
> process.  I know programmatically it is probably better to open and
> close the files as there would be no more copy and pasting, but was
> thinking processor intensive.  As it is right now it takes the script
> about 5 seconds to parse the 557 lines of data.

If you have this small data it would be best to  in the memory, into 
42 separate strings (in an array or hash of course!) and then at the 
end loop through them and flush their contents to the files.

If you expect more data in the future you'd better open all 42 files 
in the beginning, put their handles into an array or hash, then print 
the lines as you go and close all files at the end.

Otherwise you spend most of the time opening and closing files. IMHO 
of course.


something like

my @filees = ('102','104',118');

my %handles;
foreach my $fileno (@filees) {
my $FH;
open $FH, '>', "/home/multifax/$fileno" or die "Can't open $fileno 
!";
$handles{$fileno} = $FH;
}

...
if (grep $fields[4] eq $_, @filees) {
print {$handles{$_}} "[EMAIL PROTECTED]";
}
...

foreach my $FH{values %handles} {
close $FH;
}


Jenda
=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me


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




Re: Maybe Stupid RegEx Question

2004-02-12 Thread James Edward Gray II
On Feb 12, 2004, at 7:34 AM, Bastian Angerstein wrote:

Hi
Hello.

I have two strings 0x1479ee und 0x1479fe.

The strings a in $var1 and $var2.

if I do:
  if ( $var2 =~ /\Q$var1\E/)
 It matches.
You sure about that?

#!/usr/bin/perl

my($var1, $var2) = ("0x1479ee", "0x1479fe");

if ($var2 =~ /\Q$var1\E/) { print "They matched.\n"; }
else { print "They didn't match.\n"; }
__END__

The above gives me "They didn't match." as expected.

  how can I match an the string and not on each sign?
The obvious answer is that they can't.  Because of that, those 
variables probably don't contain what you think they contain.

Hope that helps.

James

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



Re: RFC - implementing callbacks

2004-02-12 Thread Gary Stainburn
On Wednesday 11 Feb 2004 2:54 pm, R. Joseph Newton wrote:
> James Edward Gray II wrote:
> > On Feb 10, 2004, at 3:29 AM, Gary Stainburn wrote:
> > > Hi folks,
> >
> > Hello again.
> >
> > [snipped history]
> >
> > > One of the points made in the previous threads was that there should
> > > be no
> > > need for sub-classes to have a link back to it's parent, and through
> > > the
> > > correct splitting of functions (inter-instance in class, intra-instance
> > > within container) I've done this okay.
> >
> > Let's not say you should "never" have links back to the parent object.
> > I've seen places where it made fine sense.  I actually have I server
> > I've been working on that does this.  Individual connections keep a
> > link to the main server, to inform it of changes in their status, based
> > on network reads/writes and to access server wide functionality, like
> > logging.
> >
> > Generally though, what you say is a good rule of thumb.
> >
> > > My problem is now:
> > >
> > > I need to be able to pass to the Trainset instance a ref to a callback
> > > within
> > > Program (to refresh a PerlTk window, or to send a signal to a model
> > > railway
> > > controller).  This callback then needs to be triggered by the Trainset
> > > instance itself, but also from Signals, Gantries, and Tcbs.
> >
> > I should warn that I have no familiarity with TK, though I do have
> > general GUI toolkit knowledge.
> >
> > The above sounds backwards to me.  Why should Trainset objects be tied
> > to their interface?  That limits their usefulness.  The interface is an
> > interface for representing Trainset objects, right?  Well, then it
> > makes sense for that interface to maintain a link to the Trainset
> > object it is currently representing, right?
> >
> > I assume TK is event driven.  So, when an event happens, I would think
> > you would access the Trainset in the event handler, make changes and
> > update.
> >
> > Now, if the Trainset object is somehow being modified by an outside
> > source (the model controller you mention perhaps), things get a little
> > trickier.  You could always poll the Trainset object every so often to
> > see if it has changed.  Polling is generally considered bad though, so
> > possibly better would be to have the code that is somehow changing
> > Trainset, to call an update routine on the interface.  If controller
> > signals are just another event being handled by the interface and the
> > interface is already keeping track of the Trainset, as I believe it
> > should, the controller event handler can pass along the change and call
> > for a refresh.
> >
> > Be aware, if the GUI allows changing the Trainset and the model
> > controller is changing the Trainset, you make have concurrent access
> > issues to deal with.
> >
> > Well, maybe that will give you some new ideas.
> >
> > James
>
> When I use Tk to describe an object sytem, I usually make an
> application-level object, aware of both the object system and the Tk
> interface structure, to control the overall
> process.  I also make wrapper classes for each major component widget, to
> manage its role
> in the overall process.
>
> These application-level classes assume the responsibility for being aware
> of the various classes
> and objects used.  Therefore the conceptual classes used to model the
> problem need not be
> aware of any extraneous factors.  They simply need to provide dependable
> performance at
> their own interfaces, to model their own concepts faithfully.
>
> So far, this approach has worked pretty well.  I am able to make major,
> radical changes to
> individual sections of my program, with minimal impact on other sections.
>
> Joseph

I have decided to have limited links to parents, where appropriate.  For 
example, a signal must be attached to a gantry, the state of the gantry being 
the sum of the states of it's signals.  It therefore makes sense for the 
signals to be able to pass on the state change to the gantry object.  The 
gantry can then perform a similar action with the Trainset object, and this 
call the callback method in the main program.

I plan to follow a system similar to what Joseph has suggested.  I plan to 
develop Trainset::Tk, which will know how to represent a signal gantry as a 
group of Tk widgets. Likewise with lever, TCB sections etc.

I can then simply use a callback method within Trainset::Tk from within the 
Trainset instance.  This idea I think tidies things up tremendously.

I can understand the point that James made, in that the update of the Trainset 
objects is being made by a Tk event trigger, and could therefore simply 
update the screen at the same time, e.g. clicking on a lever throws a signal 
*and* updates the screen.  The problem is that it's not allways possible to 
know every object that gets affected - the state of the signal may affect 
other objects, such as changing a locomotives state from 'Stopped' to 'Clear 
To Proceed'.  This is the reason behind needing the call

Re: RFC - implementing callbacks

2004-02-12 Thread Gary Stainburn
On Tuesday 10 Feb 2004 10:41 pm, Wiggins d Anconia wrote:
> > On Feb 10, 2004, at 3:29 AM, Gary Stainburn wrote:
> > > Hi folks,
> >
> > Hello again.
> >
> > [snipped history]
> I hate beating a dead horse... but this discussion of your callbacks and
> triggering events that are caught by a main controller, is exactly the
> type of thing POE was designed to handle.  Essentially a central kernel
> is running and dispatches events that happen elsewhere in the app to
> their event handlers. Which works for gui events as well as other
> environment changes (aka like the polling mentioned above).  Within
> individual object sessions other events can be sent to other sessions in
> a callback manner based on the session name through the kernel which
> controls all sessions, so keeping objects tied to each other directly
> isn't necessary, the running kernel does it for you.
>
> You may also want to check out (not sure if I have mentioned it before)
> Event.pm, though I prefer POE's complete buildout
>
> http://danconia.org

Hi,

You're not beating a dead horse, and I haven't forgotten your suggestion.  
It's just that last time I looked at POE, I got brain ache.  

The other reason I've tried to avoid POE is that I want my package to have as 
few dependancies as possible.  I intend once it's finished to make it 
available for others to use and therefore want the installation to be as 
painless as possible.

The only area I'm currently concerned about is the Model radio controller as I 
haven't actually had my hands on one yet, and don't know what the 
communications methods is yet.  If it's something like a standards serial 
cable link then I may need to use POE to drive this.

The argument against Event.pm is the same one as POE, but I will look into it 
if the need arrises.

Thanks again for your comments.
-- 
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: formatting the loop

2004-02-12 Thread Michael S. Robeson II
On Feb 11, 2004, at 2:55 PM, James Edward Gray II wrote:

[snip]

my @char = ( /[a-z]/ig, ( '-' ) x $len )[ 0 .. $len - 1 ];

If I may, yuck!  This builds up a list of all the A-Za-z characters in 
the string, adds a boat load of extra - characters, trims the whole 
list to the length you want and stuffs all that inside @char.  It's 
also receives a rank of "awful", on the James Gray Scale of 
Readability.  ;)
[snip]

Ok, now I understand. I found that my problem was with how the "next" 
command was operating in conjunction with the grouping of characters. 
Ok, making progress.  :-)

Now, about that array slice I have:

my @char = ( /[a-z]/ig, ( '-' ) x $len) [0 .. $len - 1];

I know it wastes a lot of memory and makes perl do much extra work. 
However, when I try to replace that line with something like this:

my @char = ( /[a-z]/ig, ( '-' ) x ($len - length) ;

it doesn't work the way I thought it would (gee what a thought). I 
would like to express the code similar to
( '-' ) x ($len - length)
 because it is easy for me to read and it tells you clearly what is 
going on. However, every time I try to implement something like that I 
get unexpected output or I have to really rewrite the loop.  Which I 
have been unable to troubleshot as you have been seeing. :-)  I think 
the 'length' command it also counting any '\n' characters or something, 
because my out put ends up with different lengths like this when I use 
the ($len - length) way :

 a c u g a c g a g u - - - - - - - -   bob
 a c u g a c u a g c u g - - - - - - -   fred
with this input:

>bob
actgacgagt
>fred
actgactagctg
The reason I went with  /[a-z]/ig is because some sequence data uses 
other letters to denote ambiguity and other things. I guess I can only 
list the letters it uses but I was just lazy and typed in the entire 
range of "a to z".

I will be continuing to work on it but here is the code as it stands 
now (with that awful array slice).

#!/usr/bin/perl

use warnings;
use strict;
print "Enter the path of the INFILE to be processed:\n";

# For example "rotifer.txt" or "../Desktop/Folder/rotifer.txt"

chomp (my $infile = );

open(INFILE, $infile)
or die "Can't open INFILE for input: $!";
print "Enter in the path of the OUTFILE:\n";

# For example "rotifer_out.txt" or "../Desktop/Folder/rotifer_out.txt"

chomp (my $outfile = );

open(OUTFILE, ">$outfile")
or die "Can't open OUTFILE for input: $!";
print "Enter in the LENGTH you want the sequence to be:\n";
my ( $len ) =  =~ /(\d+)/ or die "Invalid length parameter";
print OUTFILE "R 1 $len\n\n\n\n"; # The top of the file is supposed

$/ = '>';  # Set input operator

while (  ) {
chomp;
next unless s/^\s*(.+)//;  # delete name and place in memory
my $name = $1;	 # what ever in memory saved as $name
my @char = ( /[a-z]/ig, ( '-' ) x $len) [0 .. $len -1];	# take only 
sequence letters and
		# and add '-' to the end
my $sequence = join( ' ', @char);		# turn into scalar
$sequence =~ tr/Tt/Uu/;	# convert T's to U's
print OUTFILE " $sequence   $name\n";
}

close INFILE;
close OUTFILE;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: RFC - implementing callbacks

2004-02-12 Thread James Edward Gray II
On Feb 12, 2004, at 9:21 AM, Gary Stainburn wrote:

I can understand the point that James made, in that the update of the 
Trainset
objects is being made by a Tk event trigger, and could therefore simply
update the screen at the same time, e.g. clicking on a lever throws a 
signal
*and* updates the screen.  The problem is that it's not allways 
possible to
know every object that gets affected - the state of the signal may 
affect
other objects, such as changing a locomotives state from 'Stopped' to 
'Clear
To Proceed'.  This is the reason behind needing the callback method.
This shouldn't be an issue at all.  Remember when we talked about the 
Trainset object being an interface to the whole underlying system?  
That's to solve exactly this problem, and many others.

Trianset, at any given time, should be able to describe the entire 
setup.  That's it's job.  That's also why the TK widgets, should hold 
onto a link to the sucker.

Here's how I envision an event happens:  Event handler locates correct 
signal box to flip or train to change, however it does that, and make 
the change.  Event handler calls update/refresh on the appropriate 
interface object(s), maybe the whole window.  Update/refresh do their 
thing and eventually, I assume we end up in some kind of draw/paint 
method.  In draw/paint we don't care about signal boxes and trains, we 
just want to do our job.  We pull up our stored link to the Trainset, 
and ask it to tell us what it looks like right now.  That will of 
course include whatever change we recently made to some signal box or 
train.  When it tells us, we draw that.

Trainset just needs to do its job, which is to worry about Trainset 
stuff, not interfaces.  We let the interface objects worry about 
interfaces and how to display Trainsets, because that's their job.

You're always very quick to resort to serious cross linking in your 
discussions.  This will only increase your pain, remember that.  Heck, 
isn't that the main reason you keep shooting down POE?

I said I had a network server that maintained the links to it's 
connections, and vise versa.  I didn't say it was easy.  It was very 
hard to get right.  The problem is that I can be in a connection and 
need to change my read/write status.  Unfortunately, because of the 
linking, I can't do that, the server would get out of sink.  So what 
should be simple is painful.  I call into the server and have it change 
my read/write status, so both objects stay in sink.

Also remember that creating all these circular links will defeat Perl's 
garbage collection system, forcing you to manage your own cleanups.  I 
know others have warned you about this in the past.

I know I'm a broken record, but the reason I keep stressing these 
points is simple:  I don't believe you need to do this to yourself.  If 
you keep focused on the top down view and keep your interactions going 
through Trainset, I truly believe you can spare yourself this pain.  
I'm just trying to provide the best tips I know how, given the 
information I have.

The choice is, of course, yours.

If you're going to tie all these things together like that though and 
keep track of everything, I think you should take Wiggin's advice and 
go with POE.  It's a road tested solution designed to help you solve 
this problem and you're going to have a learning curve either way you 
go.  Might as well spend your study time gaining skill with a good 
system that will help you do this and more.

Okay, I'm going to shut up about this now.  I am glad you're making 
progress with your code and I wish you the best of luck, with any 
implementation you choose.

James

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



Re: formatting the loop

2004-02-12 Thread James Edward Gray II
On Feb 12, 2004, at 10:06 AM, Michael S. Robeson II wrote:

On Feb 11, 2004, at 2:55 PM, James Edward Gray II wrote:

[snip]

my @char = ( /[a-z]/ig, ( '-' ) x $len )[ 0 .. $len - 1 ];

If I may, yuck!  This builds up a list of all the A-Za-z characters 
in the string, adds a boat load of extra - characters, trims the 
whole list to the length you want and stuffs all that inside @char.  
It's also receives a rank of "awful", on the James Gray Scale of 
Readability.  ;)
[snip]

Ok, now I understand. I found that my problem was with how the "next" 
command was operating in conjunction with the grouping of characters. 
Ok, making progress.  :-)
Excellent.  I knew we would get there.

Now, about that array slice I have:

my @char = ( /[a-z]/ig, ( '-' ) x $len) [0 .. $len - 1];

I know it wastes a lot of memory and makes perl do much extra work. 
However, when I try to replace that line with something like this:
Ah, it's pretty small potatoes to quibble over, really.  I don't think 
it's in any danger of slowing your code significantly or making you buy 
more RAM.

my @char = ( /[a-z]/ig, ( '-' ) x ($len - length) ;

it doesn't work the way I thought it would (gee what a thought). I 
would like to express the code similar to ( '-' ) x ($len - length)
Na, something like this won't work because you won't know the length of 
those characters, until you stick the somewhere.  Length by default 
works on $_, which still contains a big mess of sequence characters and 
whitespace.

I think your big hang up is trying to do it all in one line.  Two or 
three is fine, right?And of course, there's nothing wrong 
with the current solution.  It does work.  You only need to replace it 
if you want to.  There's always more than one way.  Use what you like.

I'll see if I can add a suggestion below...

#!/usr/bin/perl

use warnings;
use strict;
print "Enter the path of the INFILE to be processed:\n";

# For example "rotifer.txt" or "../Desktop/Folder/rotifer.txt"

chomp (my $infile = );

open(INFILE, $infile)
or die "Can't open INFILE for input: $!";
print "Enter in the path of the OUTFILE:\n";

# For example "rotifer_out.txt" or "../Desktop/Folder/rotifer_out.txt"

chomp (my $outfile = );

open(OUTFILE, ">$outfile")
or die "Can't open OUTFILE for input: $!";
print "Enter in the LENGTH you want the sequence to be:\n";
my ( $len ) =  =~ /(\d+)/ or die "Invalid length parameter";
print OUTFILE "R 1 $len\n\n\n\n"; # The top of the file is supposed

$/ = '>';  # Set input operator

while (  ) {
chomp;
next unless s/^\s*(.+)//;  # delete name and place in memory
my $name = $1;   # what ever in memory saved 
as $name
Right here, $_ holds our sequence, plus some junk.  We can just work 
with $_ then, if we want to.

my @char = ( /[a-z]/ig, ( '-' ) x $len) [0 .. $len -1];	# take 
only sequence letters and
		# and add '-' to the end
my $sequence = join( ' ', @char);		# turn into scalar

Alternative to the above two lines:

tr/A-Za-z//cd;  # remove junk from $_
$_ .= '-' x ($len - length) if length() < $len;  # add dashes
s/\b|\B/ /g;# space out
$sequence =~ tr/Tt/Uu/;	# convert T's to U's
Then this would become:

tr/Tt/Uu/;

print OUTFILE " $sequence   $name\n";
And this:

print OUTFILE "$_  $name\n";

}

close INFILE;
close OUTFILE;
Hope that helps.

James

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



Re: RFC - implementing callbacks

2004-02-12 Thread Gary Stainburn
On Thursday 12 Feb 2004 4:19 pm, James Edward Gray II wrote:
> On Feb 12, 2004, at 9:21 AM, Gary Stainburn wrote:
> > I can understand the point that James made, in that the update of the
> > Trainset
> > objects is being made by a Tk event trigger, and could therefore simply
> > update the screen at the same time, e.g. clicking on a lever throws a
> > signal
> > *and* updates the screen.  The problem is that it's not allways
> > possible to
> > know every object that gets affected - the state of the signal may
> > affect
> > other objects, such as changing a locomotives state from 'Stopped' to
> > 'Clear
> > To Proceed'.  This is the reason behind needing the callback method.
>
> This shouldn't be an issue at all.  Remember when we talked about the
> Trainset object being an interface to the whole underlying system?
> That's to solve exactly this problem, and many others.
>
> Trianset, at any given time, should be able to describe the entire
> setup.  That's it's job.  That's also why the TK widgets, should hold
> onto a link to the sucker.
>
> Here's how I envision an event happens:  Event handler locates correct
> signal box to flip or train to change, however it does that, and make
> the change.  Event handler calls update/refresh on the appropriate
> interface object(s), maybe the whole window.  Update/refresh do their
> thing and eventually, I assume we end up in some kind of draw/paint
> method.  In draw/paint we don't care about signal boxes and trains, we
> just want to do our job.  We pull up our stored link to the Trainset,
> and ask it to tell us what it looks like right now.  That will of
> course include whatever change we recently made to some signal box or
> train.  When it tells us, we draw that.
>
> Trainset just needs to do its job, which is to worry about Trainset
> stuff, not interfaces.  We let the interface objects worry about
> interfaces and how to display Trainsets, because that's their job.

The penny's dropped. I see what you're getting at.  However there is a 
drawback.  The Tk interface of the training sim could do as you suggest and 
simply repaint the entire window on a regular basis using a snapshot of 
Trainset.

However, for the model railway use this is not sufficient.  The interface then 
needs to know about specific state changes in order to ensure that the 
correct commands are issued to the controller.

>
> You're always very quick to resort to serious cross linking in your
> discussions.  This will only increase your pain, remember that.  Heck,
> isn't that the main reason you keep shooting down POE?

I am aware of this and have taken on board the things you've said before.  
Rethinking which object performs which task will help reduce the need to loop 
backs.  For instance having a lever drive a gantry which drives a signal 
eliminates the need for a loopback from the signal to the gantry.

This I got from your previous replies and they have greatly helped simplify my 
code.  However, because of the extent of inter-dependancy, I don't think I 
can get away without them alltogether.

>
> I said I had a network server that maintained the links to it's
> connections, and vise versa.  I didn't say it was easy.  It was very
> hard to get right.  The problem is that I can be in a connection and
> need to change my read/write status.  Unfortunately, because of the
> linking, I can't do that, the server would get out of sink.  So what
> should be simple is painful.  I call into the server and have it change
> my read/write status, so both objects stay in sink.

This is pretty much what I had in mind. I.e. the gantry (connection) would 
simply tell the Trainset (server) ' I've changed, deal with it', and the 
Trainset would.

>
> Also remember that creating all these circular links will defeat Perl's
> garbage collection system, forcing you to manage your own cleanups.  I
> know others have warned you about this in the past.

This if you remember was why I started my first RFC thread.  Again, thanks to 
your replies and those of others on the list I hope to try to avoid this as 
much as possible.

>
> I know I'm a broken record, but the reason I keep stressing these
> points is simple:  I don't believe you need to do this to yourself.  If
> you keep focused on the top down view and keep your interactions going
> through Trainset, I truly believe you can spare yourself this pain.
> I'm just trying to provide the best tips I know how, given the
> information I have.

Agreed, and slowly I'm getting there.

>
> The choice is, of course, yours.
>
> If you're going to tie all these things together like that though and
> keep track of everything, I think you should take Wiggin's advice and
> go with POE.  It's a road tested solution designed to help you solve
> this problem and you're going to have a learning curve either way you
> go.  Might as well spend your study time gaining skill with a good
> system that will help you do this and more.
>

After Wiggin's and your responses t

Re: RFC - implementing callbacks

2004-02-12 Thread James Edward Gray II
On Feb 12, 2004, at 11:25 AM, Gary Stainburn wrote:

I am aware of this and have taken on board the things you've said 
before.
Rethinking which object performs which task will help reduce the need 
to loop
backs.  For instance having a lever drive a gantry which drives a 
signal
eliminates the need for a loopback from the signal to the gantry.

This I got from your previous replies and they have greatly helped 
simplify my
code.  However, because of the extent of inter-dependancy, I don't 
think I
can get away without them alltogether.
I bet your Trainset code is pretty involved, but I think we provide 
even better information when we're fixing code.  Perhaps when it's at a 
mostly functional level, and well documented, you could put it online 
somewhere and post a link here for the curious.  We might be able to 
provide some good insights that way.  Just a thought.

James

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



Re: RFC - implementing callbacks

2004-02-12 Thread Wiggins d Anconia
> On Thursday 12 Feb 2004 4:19 pm, James Edward Gray II wrote:
> > On Feb 12, 2004, at 9:21 AM, Gary Stainburn wrote:



> 
> >
> > The choice is, of course, yours.
> >
> > If you're going to tie all these things together like that though and
> > keep track of everything, I think you should take Wiggin's advice and
> > go with POE.  It's a road tested solution designed to help you solve
> > this problem and you're going to have a learning curve either way you
> > go.  Might as well spend your study time gaining skill with a good
> > system that will help you do this and more.
> >
> 
> After Wiggin's and your responses today, I think I'll have to revisit
POE and 
> see what it does.  I had hoped not to to maintain simplicity of code and 
> deployment, but I think I may end up needing it once I get to more
that one 
> input source so I may as well do it now.
> 

The simplicity of the code is going to be an interesting comparison,
originally your code thoughts were very simple, but as you wander
further down the path of the implementation you are seeing how little of
the whole thing you could see at the beginning and how complicated it
*could* get.  I will still hedge on the fact that once you grasp POE
that the code you have will become so incredibly simple that you will
ask yourself if it could possibly be right, because it *should* be
harder.  I only say that because I have had one of these epiphanies
(sp?) before. I wrote a ton of code to handle multiple forked processes
and event queues, and after spending some time with POE threw it all out
and accomplished the same thing in a couple hundred lines, naturally
much to my dismay :-).  You are right POE is a big dependency and one
that will have to be solved to distribute the app, but I also think that
the amount of time you can save implementing the whole thing by using it
would more than provide time to test and document the installation of
your app on multiple systems.

I also think that the amount you have learned about objects and message
passing in the interim will make POE much easier for you to pick up. POE
can be daunting if you have to learn POE *and* OOP at the same time, but
I think you have enough OOP background to now only need to learn POE
itself.  Realize that POE itself is expansive, but you need only
concentrate on a tiny fraction of what it can offer to get all of your
parts talking.  Don't worry about any of the TCP stuff, or the chat
stuff (other than the examples), I would suggest concentrating on
POE::Session, and would also suggest scrapping the notion of stand-alone
sessions.  Use the POE object based sessions (you already have your
object layout pretty well set).

If you get stuck with POE ask questions! (which I know you are good at
;-)).  Either here, [EMAIL PROTECTED] or to me directly, I find this
interesting enough that I would be certainly willing to provide POE
advice.  If I find some time this weekend I will boil down an example
POE object I use in a successful production app and put it online. I
have been meaning to for a while anyways, and it may give you enough of
a start to see how to convert your current object scheme easily.

But remember, just because I speak with such belief does not mean you
are not headed in the right direction without POE, only you truly know
that

Good luck,

http://danconia.org

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




RE:help on picking up key & values

2004-02-12 Thread Singh, Ajit p
Comrades,


I have a function which takes up arguments as shown below:

$str = "./place_order -t " .
"/thus/axioss/serviceID:\"" . $self->{serviceID} . "\" " .
"/thus/axioss/supplierProduct:\"" . $self->{supplierProduct} . "\" "
.
"/thus/axioss/web/installationTelephoneNumber:\"" .
$self->{installationTelephoneNumber} . "\n"; 

My problem is to get away with the hard coded values i.e
/thus/axioss/serviceID:,/thus/axioss/supplierProduct:, and 
/thus/axioss/web/installationTelephoneNumber:

I am fetching the above arguments from a file which contains these values as
shown below.

/thus/axioss/serviceID:123456
/thus/axioss/supplierProduct:BT IPStream 500
/thus/axioss/web/installationTelephoneNumber:020837111663

How can I do away with the hard coded keys?

Thanks in advance..




regards,

Ajitpal Singh,

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




NDS user and group query

2004-02-12 Thread Michael Weber
Greetings!

I would like to create a web page that will allow users to look at my
Novell NDS tree groups and see what users are members, and look at users
to see what groups they are members of.

I don't want to give them ConsoleOne or NWAdmin since some of them are
still looking for the "Any" key.  Know what I mean, Verne?

I tried Google and CPAN but didn't come up with much.  Any experiences
guru's been there and done that?

I am running NDS 7 under NW 5.0.  The Perl script will be running in an
Apache cgi script under RedHat Enterprise 3.0.

Thanx!

-Michael

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




Re: RE:help on picking up key & values

2004-02-12 Thread Rob Dixon
Ajit P Singh wrote:
>
> Comrades,
>
>
> I have a function which takes up arguments as shown below:
>
> $str = "./place_order -t " .
> "/thus/axioss/serviceID:\"" . $self->{serviceID} . "\" " .
> "/thus/axioss/supplierProduct:\"" . $self->{supplierProduct} . "\" "
> .
> "/thus/axioss/web/installationTelephoneNumber:\"" .
> $self->{installationTelephoneNumber} . "\n";
>
> My problem is to get away with the hard coded values i.e
> /thus/axioss/serviceID:,/thus/axioss/supplierProduct:, and
> /thus/axioss/web/installationTelephoneNumber:
>
> I am fetching the above arguments from a file which contains these values as
> shown below.
>
> /thus/axioss/serviceID:123456
> /thus/axioss/supplierProduct:BT IPStream 500
> /thus/axioss/web/installationTelephoneNumber:020837111663
>
> How can I do away with the hard coded keys?
>
> Thanks in advance..

How is this 'RE:help on picking up key & values'?

It's not clear what your problem is. You need to

- Open the file
- Read its records
- Close it
- Build your string from the data read

What can't you do?

Rob




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




Re: NDS user and group query

2004-02-12 Thread Rob Dixon
Michael Weber wrote:
>
> I would like to create a web page that will allow users to look at my
> Novell NDS tree groups and see what users are members, and look at users
> to see what groups they are members of.
>
> I don't want to give them ConsoleOne or NWAdmin since some of them are
> still looking for the "Any" key.  Know what I mean, Verne?
>
> I tried Google and CPAN but didn't come up with much.  Any experiences
> guru's been there and done that?
>
> I am running NDS 7 under NW 5.0.  The Perl script will be running in an
> Apache cgi script under RedHat Enterprise 3.0.

I've never done anything like this, but I'm sure I could. But please say
exactly what it is that you can't do. I mean, if you can't write a CGI
script then we start in a very different place from where we would if you
don't know how to read the NDS data.

Rob



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




Re: can't use CPAN with Mandrake 9.2

2004-02-12 Thread Jerry M. Howell II
Understood but since I read it and had a similar issue not long ago I'll
post. from the command line type urpmi perl-devel

You are probably missing the header files needed by cpan.

On Mon, 2004-02-09 at 20:32, Brian's Linux Box wrote:
> This might be better off on a Mandrake list, but I was hoping for an
> answer here (esp. since I'm already subscribed here :-)
> 
> I tried to install Getopt:Simple via CPAN on my new Mandrake 9.2 box.
> I get this
> 
> Error: Unable to locate installed Perl libraries or Perl source
> code.
> 
> It is recommended that you install perl in a standard location
> before
> building extensions. Some precompiled versions of perl do not
> contain
> these header files, so you cannot build extensions. In such a
> case,
> please build and install your perl from a fresh perl
> distribution. It
> usually solves this kind of problem.
> 
> (You get this message, because MakeMaker could not find
> "/usr/lib/perl5/5.8.1/i386-linux-thread-multi/CORE/perl.h")
> As the note indicates - there is no perl.h in the indicated directory
> (but the directory is there)
> Do I really have to reinstall perl?  It works and is in /usr/bin
> which seems normal to me
> Brian


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




Reg. length of anonymous array

2004-02-12 Thread Balaji Thoguluva
Hi,
 
I am a novice to perl programming. I have a reference to a hash with a hash key as 
a reference to an anonymous array.
 
For clarity, I have something like this structure 
 
my $rhash = {
$rarray => [  ],
};
 
I would like to know the length of the anonymous array containing some elements. 
 
Thanks,
Balaji 
  
 
 

Yahoo! India Education Special: Study in the UK now.

Re: Reg. length of anonymous array

2004-02-12 Thread david
Balaji thoguluva wrote:

> For clarity, I have something like this structure
>  
> my $rhash = {
> $rarray => [  ],
> };
>  
> I would like to know the length of the anonymous array containing some
> elements.

the usual trick use be used:

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

my $h = {array => [1,3,5,7]};

print  @{$h->{array}} . "\n";
print $#{$h->{array}} . "\n";

__END__

prints:

4
3

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: Which is better, opening and closing, or a massive file opening and a massive closing?

2004-02-12 Thread wolf blaum
For Quality purpouses, [EMAIL PROTECTED] 's mail on Wednesday 11 February 
2004 22:08 may have been monitored or recorded as:

Hi, 

> I'm still working on the script, though it is cleaning up even better, I
> even have it running cleaner by dumping anything not matching some specs.
> What I am trying to figure out though is this:
>
> I have 42 places for the output to go, 1 of those is a constant dump, the
> others are all based on whether or not there is data in a field.  If the
> data is in the field, the data writes to a file with the same name as the
> data checked.  If not then it writes to a global catch-all.

If I recall your last mail correctly you were opening a lot of file handles, 
than running into the switch kind of thing and than closing all the files 
again.
That was: a lot of system calls (open) to eventually write to a few of the 
files in the SWITCH (the accumulated ifs) and then again a lot of sys calls 
to closethem, where you have actually writen to only a few of the opend 
files.

That sounds slow.
Wiggins allready suggested

if (grep $fields[4] == $_, @cities) {
  $tmptxt = $fields[10];
}
else {
  $tmptxt = '1-' . $fields[10];
}

for the first SWITCH like construct.
For the second one id say, make an array of your filenames and use the contend 
of filed[11] as index, like:

my @file_names=qw (/home/multifax/everyone /home/multifax/
pack-fishbait .);

if (defined $file_name[$fields[11] - 102]) {
  open OUTFILE ">${file_name[$fields[11] - 102]}" or die "Cant open 
${file_name[$fields[11] - 102]}:$!";

  print OUTFILE "[EMAIL PROTECTED]"; #your trailing ID
  close OUTFILE; 
 }
else {
  open OUTFILE ">default.out" or die "Cant open default.out :$!";
  print OUTFILE "[EMAIL PROTECTED]"; #your trailing ID
  close OUTFILE; 
}

However, this assumes that you have continous values from 102 upwards in 
$fields[11] - if not, come up with a formula that gives you the index of the 
wanted filename in @file_names depending on $fields[11]or use a hash instead:

$file_name{102}="whatever/filename/you.want";

I suggest you tell us, what the logic behind all these different files is, ie, 
what goes where of which cause: maybe someone can come up with a hash 
structure that incoorporates this knowledge.
Dont open and close 42 files if you only will ever print to 2 of them.

Enjoy, Wolf






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




strings

2004-02-12 Thread Mark Goland
Hi All,

I have a tring which contains 60 to 80 keywords, I need to know what position a 
keyword is in. I need an efficint way to extra position of key words, here is how I am 
currently finding positions,

$string="type,model,color,date";

# this is how I am currently getting position, which is nto very efficiant
@keys=split ",",$string;
foreach( @keys ){
 $position++;
 last if m/model/ig;
} 



RE: strings

2004-02-12 Thread Toby Stuart


> -Original Message-
> From: Mark Goland [mailto:[EMAIL PROTECTED]
> Sent: Friday, February 13, 2004 1:28 PM
> To: [EMAIL PROTECTED]
> Subject: strings
> 
> 
> Hi All,
> 
> I have a tring which contains 60 to 80 keywords, I need to 
> know what position a keyword is in. I need an efficint way to 
> extra position of key words, here is how I am currently 
> finding positions,
> 
> $string="type,model,color,date";
> 
> # this is how I am currently getting position, which is nto 
> very efficiant
> @keys=split ",",$string;
> foreach( @keys ){
>  $position++;
>  last if m/model/ig;
> } 
> 
> 


use strict;
use warnings;

my $str = "The cat sat on the mat";
print index($str, "sat"); # prints 8

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




Unique file names.

2004-02-12 Thread John McKown
I have a bit of a problem and I'm wondering if there is a better solution.  
I have a Perl program (of course) which reads STDIN and breaks it into
separate files based on a "report separator". I can construct an
appropriate file name based on information in the "trailing" separator.  
I.e. I don't know the name of the report until the report is complete.  
What I am doing at present is using the routine 'tempfile' in the
File::Temp package to create a unique file in the output directory.  Once
I get the report name from the "trailer" separator, I want to rename this
file to the correct name. However, it is possible that there will be
multiple, different reports coming in which have the same name. So, what I
want to do is put a "sequence number" as the last node in the file name.  
This means that I must generate a test file name, then see if that file
already exists. If it does, increment the sequence number, generate a new
test file name and loop. Oh, did I mention that it is possible for this
program to have several copies all running at the same time, possibly
producing different reports with identical names? So I must worry about
"race" conditions. My code, so far, looks like:

# $fn contains the file name generated by 'tempname'
# $report contains the report name
my ($number,$test);
for ($number=1;;$number++) {
$test = "$report.$number";
last if sysopen JUNK, $test, O_WRONLY|O_EXCL|O_CREAT;
}
close JUNK;
mv($fn,$test);

Using sysopen with those parameters, especially O_EXCL, is the only way
that I can think to ensure that the name in $test does not exist and is
created "atomically" so that no other incarnation of this program which
happens to be running at the same time will exit the for loop with the
same value in $test.  I then close this file (now a 0 length file). I then
use the "mv" function from File::Copy to rename my real data file to the
new name, replacing the 0 length file.

This is running on Linux. I don't know if the sysopen can guarantee the
"atomicity" of sysopen on other platforms.

All comments gratefully received.

--
Maranatha!
John McKown


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




Handling error with exception

2004-02-12 Thread Hari Fajri
Do perl have handling error (exception) mechanism?

for example: java use : try{...} catch{...}

Thanks

Including files to pick up variables

2004-02-12 Thread Robin Sheat
Hey there, what is the best way of including a Perl so that the contents 
of it override the existing variables. For example, I have:


...
my $comment = "Default\n";
my $resDir = "results";
...
if (@ARGV) {
my $c = shift;
$config = "testing/$c.pm";
unless (my $ret = do $config) {
die "couldn't parse $config: $@" if $@;
die "couldn't do $config: $!"unless defined $ret;
die "couldn't run $config"   unless $ret;
}
# Get the output filehandle
$output = getOutputFH();
}
...


$comment = "A not quite default test.";
my $resName = 'notdefault.res';

sub getOutputFH() {
open($fh, ">${resDir}/${resName}.res") or   ***
die "Can't open results file: $!";
return $fh;
}
1;

I would like the value of $comment defined in the testing file to 
override the value defined in the main program. I would also 
like for the value of $resDir to be picked up by the getOutputFH() sub, 
however neither of these happens. What is the best way of doing what I'm 
trying to acheive here?
(Obviously, in real life, more things are going to be set, but if I can 
make this example work, it is a short step to getting the rest working)

The error I get is "Use of uninitialized value in concatenation (.) or 
string" at the point marked '***'. I assume it is $resDir not being 
defined.

I know that I could simply have a function that returns a hash (list) 
that I walk through to set the variables, but I want to keep this as 
simple as possible, as I'll be creating lots of little versions of these 
testing files, and the more stuff in them, the more there is to go 
wrong.

-- 
Robin <[EMAIL PROTECTED]> JabberID: <[EMAIL PROTECTED]>

Hostes alienigeni me abduxerunt. Qui annus est?

PGP Key 0x776DB663 Fingerprint=DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663


pgp0.pgp
Description: PGP signature


Re: Handling error with exception

2004-02-12 Thread Randy W. Sims
On 2/12/2004 9:56 PM, Hari Fajri wrote:

Do perl have handling error (exception) mechanism?

for example: java use : try{...} catch{...}
perl has pretty poor build-in exception handling which consists of 
executing some code in an eval{...} block and then check $@ to see if an 
error occured. There are a couple of good modules that provide a very 
nice wrapper around the built-in mechanism. Probably the best is 'Error' 
which adds 'try', 'catch', and 'except' blocks. There are also 
Exception::Class, Exception and a bunch of others 
.

Regards,
Randy.


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



Re: Unique file names.

2004-02-12 Thread Randy W. Sims
On 2/12/2004 9:53 PM, John McKown wrote:

I have a bit of a problem and I'm wondering if there is a better solution.  
I have a Perl program (of course) which reads STDIN and breaks it into
separate files based on a "report separator". I can construct an
appropriate file name based on information in the "trailing" separator.  
I.e. I don't know the name of the report until the report is complete.  
What I am doing at present is using the routine 'tempfile' in the
File::Temp package to create a unique file in the output directory.  Once
I get the report name from the "trailer" separator, I want to rename this
file to the correct name. However, it is possible that there will be
multiple, different reports coming in which have the same name. So, what I
want to do is put a "sequence number" as the last node in the file name.  
This means that I must generate a test file name, then see if that file
already exists. If it does, increment the sequence number, generate a new
test file name and loop. Oh, did I mention that it is possible for this
program to have several copies all running at the same time, possibly
producing different reports with identical names? So I must worry about
"race" conditions.
If your code is the only code accessing the file, the standard way to 
handle this is to create a lock file. Try to write a file to a specific 
place as a lock file; if it fails, another process has already created 
it, so you poll until you can create it. Then run your routine to get a 
filename, move the file, and delete the lock file so that the next 
process can run.

Randy.



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



Data::Dumper trouble

2004-02-12 Thread Jan Eden
Hi all,

I want to store some complex data. My first solution made use of Storable, which 
worked just fine. Now I learned that neither Storable nor MLDBM are available on the 
machine I want to use the program on (and they cannot be made available).

So I retreat to the core and use Data::Dumper to write a reference to my data to a 
file ("..." indicates an omitted hash of arrays of hashes):

#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my %monate = ...

open OUT, "> monate.dbm";
print OUT Dumper(\%monate);
close OUT;

Next I try to restore the data. My first attempt is this:

open IN, "monate.dbm";
my $temp = join '', ;
my $reimport = eval $temp;

Unfortunately, $reimport has the same value as $temp:

$VAR1 = ...

Reading the Data::Dumper doc? Good idea. I found the $Data::Dumper::Terse variable, 
which made Data::Dumper leave out the variable name $VAR1.

Great, it works. But, from the perldoc

>$Data::Dumper::Terse  or  $OBJ->Terse([NEWVAL]) When set,
>Data::Dumper will emit single, non-self-referential values as
>atoms/terms rather than statements.  This means that the $VARn names
>will be avoided where possible, but be advised that such output may
>not always be parseable by "eval".

Hm. In my case, setting $Data::Dumper::Terse was absolutely necessary to make eval 
work the way I wanted it to. Is there another way to get the original data structure 
into a variable? In this context, I must admit that the different behaviour of eval's 
two forms (eval EXPR and eval BLOCK) is a bit mysterious for me.

I am grateful for hints.

Thanks,

Jan
-- 
A common mistake that people make when trying to design something completely foolproof 
is to underestimate the ingenuity of complete fools.

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