kordaff 1 Newbie Poster

If you've named your table phonelist and your columns name and number, insert this at line 23:

my $sth = $dbh->prepare("SELECT name,number from phonelist where name=?");
$sth->execute($name);
my @row;

At line 33, insert this:

while (@row = $sth->fetchrow_array)
  {print "Found:  Name=$row[0] Phone Number=$row[1]<br>\n";
kordaff 1 Newbie Poster

Since I just answered another question similar to this, I'd suggest using fork() depending on if it works on your OS or not (works fine on Linux/Unix and for me just now on Win7)

Change:

if ($time_difference > 180) {
system("perl create_cache.pl");
}

to:

if ($time_difference > 180) {
my $pid=fork();
if (undef $pid){die "fork failed: $!\n";}
if (!pid)
  {
  # May want to close any open sockets or filehandles
  # here in the child, before running the system 
  # command to avoid them hanging if the parent 
  # closes them before the system call completes in 
  # the child process.
  system("perl create_cache.pl");
  exit; # child exits
  }
else
  {
  # parent continues on...
  }
}
kordaff 1 Newbie Poster

The child process gets a pid of 0, the parent process gets a new pid that is not equal to zero. You'll probably only want to run the exec once, in either the child process from fork, or in the parent. All the code after fork() runs in each process, unless it was unsuccessful then pid will be undefined.

Put your exec where you want it to run, in the child process section, or in the parent process section:

if (this_condition is true) 
{
$mypid = fork(); ##?? not sure how this actually works

if (! $mypid)
{
# put your exec here to run in the child process.
}
elsif (undef $mypid)
{
# fork() failed.
}
else
{
# put exec here to run in the parent process
}
# you may want to exit one or both processes somewhere in 
this block too...
}
kordaff 1 Newbie Poster

If you had a label that was formatted like this:

119,201,119,217

You could parse it like this:

using System.Text.RegularExpressions;

string[] coords = Regex.Split(label1.Text,@"\D+");
            label2.Text = coords[0]+ "," + coords[1];
            label3.Text = coords[2] + "," + coords[3];
kordaff 1 Newbie Poster

Try this:

bool MouseClicked = false;
        double x1;
        double y1;

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (MouseClicked)
            {
                this.label2.Text = "second point " + e.X + ", " + e.Y + ".";
                MouseClicked = false;

                double x2 = Convert.ToDouble(e.X);
                double y2 = Convert.ToDouble(e.Y);
                double dist = Math.Sqrt(Math.Pow((x1 - x2), 2.0) + Math.Pow((y1 - y2), 2.0));
                label5.Text = "From " + x1.ToString() + "," + y1.ToString() + " to " +
                    x2.ToString() + "," + y2.ToString() + " is " + dist.ToString() + " pixels.";
                label6.Text = (x1 - x2).ToString() + " is the change in X.";
                label7.Text = (y1 - y2).ToString() + " is the change in Y.";
            }
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (!MouseClicked)
            {
                this.label1.Text = "first point " + e.X + ", " + e.Y + ".";
                MouseClicked = true;
                x1 = Convert.ToDouble(e.X);
                y1 = Convert.ToDouble(e.Y);
                label5.Text = "";
                label6.Text = "";
                label7.Text = "";
            }
        }

You may need to declare x2,y2 outside of the Mouse_Up event, if you need them to persist a bit longer...

kordaff 1 Newbie Poster

Attach your checkbox's CheckChanged event to the method below.

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                this.Text = string.Empty;
                this.ControlBox = false;
            }
            else
            {
                this.Text = "Title On";
                this.ControlBox = true;
            }
        }

Kordaff

kordaff 1 Newbie Poster

Try this snippet:

private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            label1.Text = "Local position is " + e.X + ", " + e.Y + ".";
            label2.Text = "Global position is " + Cursor.Position.X + ", " + Cursor.Position.Y + ".";
        }
kordaff 1 Newbie Poster

Myself, I'd use perltk. The Tk module comes with activestate's version, so portability to windows, if required, is less of an issue. The usenet group comp.lang.perl.tk is helpful. The O'Reilly book 'Mastering Perl/Tk' also has a great deal of helpful information. The man pages are what I usually refer to but keep the book handy just in case. There are some examples on www.perltk.org too and there have been articles on Perl/Tk in various spots across the net.

I've used it to monitor my laptops battery, edit files, display everquest map files, generate characters for Traveller(tm), and generally to expand my understanding of perl.

Kordaff - at plh.org

kordaff 1 Newbie Poster

Net::Ping defaults to a tcp connection to the echo port (7 according to my /etc/services file). Use this (from the Net::Ping man page) example to do a regular ICMP ping like the command line:

use Net::Ping;
my $p = Net::Ping->new('icmp');
print "$host is ";
print "NOT " unless $p->ping($host, 2);
print "reachable.\n";
sleep(1);
$p->close();

Kordaff

kordaff 1 Newbie Poster

I like this bit from the Time::HiRes manpage

# Arm an interval timer to go off first at 10 seconds and
# after that every 2.5 seconds, in process virtual time
                                                                                
use Time::HiRes qw ( setitimer ITIMER_VIRTUAL time );
                                                                                
$SIG{VTALRM} = sub { print time, "\n" };
setitimer(ITIMER_VIRTUAL, 10, 2.5);

I've used that in a chat script to run the main processing loop on my listening socket and the connected user sockets 10x per second, except my is $SIG{ALRM}, using ITIMER_REAL instead of the other.

Kordaff

kordaff 1 Newbie Poster

In perl, this works for non-numeric scalar variables too:

#!/usr/bin/perl 

$a="abcd";
$b="yyyyyy";

$a ^= $b;
$b ^= $a;
$a ^= $b;

print "$a $b\n";

To swap arrays, I cannot think of a way off hand without using a counter variable to iterate through the larger array...

Kordaff

kordaff 1 Newbie Poster

I see a couple problems with this script (besides it grabbing over 1025MB of memory when i ran it under linux, which it didn't do under windows)

First, you should always use this line at the top of your perl program:

use strict;

Fix all the warnings this will produce.
You can define the global hashes and arrays at the top of the file something like this:

my (%sender,%receiver,%schedule,@p_s,@totalorder);

The loop control variable $numevents only gets incremented if the elsif regex matches. Should it increment in the first regex's block? Initialize $timestamp too, even if to zero to avoid warnings from strict and -w. =)

The second problem was with $pid. $pid should be initialized to some value. Since $pid is an array index in the line:

if($p_e = pop @{$p_s[$pid]})

it should only be numeric. It isn't numeric when the second loop gets it. The lines:

my $p = "$1-$2";
 
#queue process on @p_s multi-dimensional array
unshift (@{$p_s[$1]},$p);

put the digit-dash-digit matches from the second regex onto the array @p_s. That causes an error when i tried a dummy file with lines like this:
1-2
5-6
7-8

The third problem is the two regular expressions:

if ($line =~ m/(\d)-(\d)->(\d)-(\d)/)
and
elsif($line =~ m/(\d)-(\d)/)

The first will match lines like this:

blahblah 1-2->3-4 blahblah

The second will match anything with a digit dash digit in it. Dig? hehe
If your process numbers have more than …

kordaff 1 Newbie Poster

You can try this bit of code to get the output and errors into a scrollable Tk::Text window:

#!d:\perl\bin\perl.exe -w

use strict;
use Tk;
use IPC::Open3;

my $filename="perl myfile.pl";  # change me for a different file
my $mw=Tk::MainWindow->new();  # makes a new Tk window

my $button=$mw->Button(-text => "Run $filename",
	-command => \&runme )->pack();   # this is the run button
my $text=$mw->Scrolled(qw/Text -height 20 -scrollbars e/)->pack();  # stdout goes into this window
my $texterr=$mw->Scrolled(qw/Text -height 10 -scrollbars e/)->pack();  # stderr goes into this one

MainLoop;  
# Tk's mainloop, all event processing takes place here
# if we don't reach MainLoop then the entire Tk window will be
# unresponsive.

sub runme {  
  # this subroutine is called when the button is pressed 
  my $pid = open3 (*PROG_IN, *PROG_OUT, *PROG_ERR, $filename) or die "Boom: $!\n";   # ok Boom is not best error msg. 
  close (PROG_IN);  
  # PROG_IN is for writing to programs that require input
  # see Ch16 for info on blocking and deadlock...
  foreach (<PROG_OUT>)
    { $text->insert('end',$_); $mw->update;}
   # each line is inserted into the widget, and update is called to 
   # refresh it - i was having probs not seeing anything in text
   # windows.
  foreach (<PROG_ERR>)
    { $texterr->insert('end',$_); $mw->update;}  
  }

Both Tk and IPC modules come with Activestate's perl install. The runme subroutine is mostly straight out of the Perl Cookbook Ch16. It reads the STDOUT and STDERR of the program and inserts each line into the appropriate Tk::Text window.

*.ppm's are packages to be used with …

kordaff 1 Newbie Poster

Yeah I proly just got too impatient and stopped the MSI version. The installer.bat is in the zip AS version too. I was using slower computer so that might have been why it seemed so slow :) Only thing I found I really needed full path for is the *.pl script itself. Just perl.exe works from both start/run and dos prompt as long as perl/bin directory is in path (which installer.bat makes sure of).

Kordaff

kordaff 1 Newbie Poster

I've put screenshots showing how i run a script called getmap.pl on my win98 machine:

http://plh.org/getmap.jpg for start/run window
http://plh.org/msdos.jpg for msdos window

I added the die here line to stop all the debugging info from scrolling the command line off the screen =)

kordaff 1 Newbie Poster

I believe the installer.bat file (a perl script) does a lot of file path renaming in various scripts in the perl installation. Using perl without running installer.bat is problematic. You also may need to specify the full path for myfile.pl unless it is in your current directory (while in a DOS command window).

Kordaff

kordaff 1 Newbie Poster

I tried it on my win98 machine. The MSI version kept hanging at the making html step. Extracted the AS version to D:\ActivePerl-5.8.7-813-MSWin32-x86-148120\ActivePerl-5.8.7-813-MSWin32-x86-148120\
using winrar (like that better as it does rar, zip, tar, gz, etc)

I would have been happy with D:\Perl but oh well lol. Cd'd into that directory and typed perl\bin\perl.exe installer.bat That ran thru a bunch of commands that didn't hang on the making html bit although it did take quite a while.

It seems to work now with .pl files although many of my old version perl files are dying with this version...

Did winzip display an error when you tried to unzip the AS file?

Kordaff

kordaff 1 Newbie Poster

Anything I can do to help =)

kordaff 1 Newbie Poster

Thx =) Hmm my first comment in the subroutine is wrong though :(
It always enters the subroutine in state=1. The comment should have been

# always enters in $state=1 ie: whether it was a fresh line or it had a partial, before it gets to the subroutine, a partial is joined with the current line and it's considered a fresh line.

Kordaff

kordaff 1 Newbie Poster

Here's a bit of code that prints the multi-line error message from that log sample:

#!/usr/bin/perl -w
use strict;
my $log="log";
my $partial="";
my $state=1;
if ( $ARGV[0] ) { $log=$ARGV[0] }
open ( FILE,$log ) or die "Failed to open $log:$!\n";
while ( <FILE> )
  {
  if ( $state ) # watching two states, this one is waiting on new log line
    { check_for_complete_line($_) }
  else # 2nd state is waiting on another piece of previous partial line
    { $state=1; $partial .= $_ ; check_for_complete_line($partial); }
  }
close FILE;
sub check_for_complete_line
  {  # enters with $state=1 for new line, $state=0 for partial line previous
  my $line = shift;
  if ($line =~ /^####<(.*)> <(.*)> <(.*)> <(.*)> <(.*)> <(.*)> <(.*)> <(.*)> <(.*)> <.*>$/ms)
    {
    if ($2 eq 'Error')
      { # only 9 positional variables - probably would be better to use split here
      print "$1|$2|$3|$4|$5|$6|$7|$8|$9";
      $line =~ s/^####<.*> <.*> <.*> <.*> <.*> <.*> <.*> <.*> <.*> <(.*)>$/$1/ms;
      print "|$line\n";
      }
    else {} # handle info/warning
    $partial="";
    }
  else  # incomplete log line, save the part we have, indicate state change
    { $state=0; $partial = $line }  
  }
Comatose commented: Thumbs Up, I love commented Code +1
kordaff 1 Newbie Poster

Missed that bit in your previous post, my bad.

kordaff 1 Newbie Poster

Dang, no threading :( more stupidity from me

kordaff 1 Newbie Poster

Not that it's necessary to change something that works (believing this may be a perl sin, so i'll say a perl prayer later...) but you can change those two lines into one and eliminate the extra variable:

$FORM{'story'} =~ s/\n/<BR>/gi;

Kordaff