[22883] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5104 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 10 21:06:14 2003

Date: Tue, 10 Jun 2003 18:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 10 Jun 2003     Volume: 10 Number: 5104

Today's topics:
    Re: Beginning a script in the background (David Efflandt)
    Re: Beginning a script in the background <bdonlan@bd-home-comp.no-ip.org>
        Catching error code outside of the range of 0-255 <daniel.nichols@NOSPAMvirgin.net>
    Re: date, week of the year info? <bigj@kamelfreund.de>
    Re: Do yu know abetter way to do it ? <krahnj@acm.org>
        Html to text conversion <m.j.everitt@REMOVEME.iee.org>
    Re: Indenturing words into lists <mbudash@sonic.net>
        Mac and Line Breaks (Phil)
    Re: Mac and Line Breaks <mgjv@tradingpost.com.au>
        mod_perl memory leak? <swen@news.com>
    Re: need the ascii set for arrow down (Malcolm Dew-Jones)
        NEWBEE: Client-Server Timout implementation (Zack)
    Re: open2 under windows (Alan)
    Re: open2 under windows <ddunham@redwood.taos.com>
    Re: Perl CGI and Downloading Files - How? 10ghz@radiate.com
    Re: Perl Matrix Filter Module like in Excel? <tzz@lifelogs.com>
    Re: Perl Matrix Filter Module like in Excel? Dennis@NoSpam.com
    Re: Question about a counter. <e@1.com>
    Re: Regular expression <sumguy@hooker.com>
    Re: Regular expression <mbudash@sonic.net>
    Re: Regular expression (Tad McClellan)
    Re: Regular expression <mbudash@sonic.net>
    Re: setOutput in Perl <bigj@kamelfreund.de>
    Re: stripping leading zeros thru multiple fields <tzz@lifelogs.com>
    Re: stripping leading zeros thru multiple fields <krahnj@acm.org>
    Re: stripping leading zeros thru multiple fields (MF)
    Re: stripping leading zeros thru multiple fields (Greg)
    Re: Time limit <cwilbur@mithril.chromatico.net>
        using Dumper to save hash and retrieving it. <abc@nowhere.com>
    Re: virtual x server for Tk <chip@NO-Spam-afcoms.com>
    Re: Win32::ListView  sample please?? (Kenjis Kaan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Jun 2003 18:06:22 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Beginning a script in the background
Message-Id: <slrnbec7gt.3ks.efflandt@typhoon.xnet.com>

On 10 Jun 2003 10:31:35 -0700, Dave Ardrey <david.ardrey@analog.com> wrote:
> I posted this question yesterday but I may have been a little unclear
> as to what I need.  I understand how to, from within a script, start a
> process in the background:
> 
> system("command &");
> 
> However, what I need is for my entire script to immediately go into
> the background, as soon as I execute it from the unix command line.
> 
> I realize that I could have a tiny script that just does a system call
> like above to the "real" script, but that's kind of gross.
> 
> Is there another way to do it?

Have you read 'perldoc perlipc'?

Following is part of a script that either deamonizes into the background
and loops if $bg is set, or otherwise runs once and exits.

'checkip' is a sub that checks my WAN IP and either runs a DNS update
binary and returns something if it changed, or sleeps for awhile if not 
(it also logs less frequently, just so I know it is alive).  
'mylog' is a sub that either logs to a file or syslogd:

use POSIX 'setsid';     # to daemonize

sub daemonize {
    chdir '/' or die "Can't chdir to /: $!";
    open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
    open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
    defined(my $pid = fork) or die "Can't fork: $!";
    exit if $pid;
    setsid  or die "Can't start a new session: $!";
    open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
}

if ($bg) {
    mylog("Poll $di704 $poll/$tick sec");
    daemonize;
    while (1) { mylog($_) if $_ = checkip; }
} else {
    mylog("Polling $di704");
    checkip;
}

-- 
David Efflandt - All spam ignored  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Tue, 10 Jun 2003 15:46:11 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: Beginning a script in the background
Message-Id: <pan.2003.06.10.19.46.07.628916@bd-home-comp.no-ip.org>

On Tue, 10 Jun 2003 10:31:35 +0000, Dave Ardrey wrote:

> I posted this question yesterday but I may have been a little unclear
> as to what I need.  I understand how to, from within a script, start a
> process in the background:
> 
> system("command &");
> 
> However, what I need is for my entire script to immediately go into
> the background, as soon as I execute it from the unix command line.
> 
> I realize that I could have a tiny script that just does a system call
> like above to the "real" script, but that's kind of gross.
> 
> Is there another way to do it?

Put this in where you want it to background.
if(fork()) exit 0;


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

Date: Tue, 10 Jun 2003 19:44:02 +0000 (UTC)
From: Daniel Nichols <daniel.nichols@NOSPAMvirgin.net>
Subject: Catching error code outside of the range of 0-255
Message-Id: <0ndcev00jl2i58jb872205pfsjopkrabq3@4ax.com>

I'm using Perl to call Oracle's sqlplus program. The SQL I'm calling
makes sqlplus return with a return code that is the Oracle error code.
These codes are bigger than 255 and normally negative?.

In Perl I call it as follows: 
@args = ("sqlplus", "internal/$ora_internal_password\@$database",
"\@$sql_file"); 
system(@args); 
# Catch the 16-bit status word 
return $? >> 8; 

How can I call an OS program and handle return codes outside of the
range 0 to 255.

Thanks, 
Daniel. 



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

Date: Tue, 10 Jun 2003 19:40:37 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: date, week of the year info?
Message-Id: <pan.2003.06.10.17.28.30.984540@kamelfreund.de>

miao mao wrote at Tue, 10 Jun 2003 08:32:05 -0700:

> we are using a train system here. one train is associate with one
> week.
> For example, this week is train 308, next week is train 309, the week
> after is train 310, etc., etc.
> 
> my question is how I can calculate the current train number? 

I don't know,
but if you want to get the number of the current week,
you can just use:

use POSIX qw/strftime/;
my $nr_of_current_week = strftime "%W", localtime;

# or %U instead of %W, if you want that the first week of the year starts
# at sunday (instead of at monday)


Greetings,
Janek



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

Date: Tue, 10 Jun 2003 21:30:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Do yu know abetter way to do it ?
Message-Id: <3EE64DF3.761E8C4C@acm.org>

Jean-Luc BEAUDET wrote:
> 
> I've got smth like
> 
> $search_pattern = $d7tt[0]." ".$d7tt[2]." ".(sprintf '% 2s', $d7tt[1]);
> if ($read_line =~ m/^$search_pattern \d{2}:\d{2}:\d{2} MEST 2003/) {
> ../..
> }
> 
> Is there a better way to write
>  \d{2}:\d{2}:\d{2} # for time format to be detected
> 
> Or better to affect $search_pattern the whole pattern to be match so
> that i can write:
> 
> if ($read_line =~ m/$search_patern/ {
> ../..
> }

my $search_pattern = qr/@{[ sprintf '%s %s %2s \d{2}:\d{2}:\d{2} MEST 2003', @d7tt[0,2,1] ]}/;

if ( $read_line =~ m/$search_patern/ ) {
 ../..
}


John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 10 Jun 2003 23:22:04 GMT
From: Michael Everitt <m.j.everitt@REMOVEME.iee.org>
Subject: Html to text conversion
Message-Id: <qtpcevkce89dp3pvsfevd19m3bucij3v7f@4ax.com>

Apologies if this seems to be an idiotically simple problem, but I'm
relatively new to perl especially module programming.

 I can't seem to get this code to produce anything other than [IMAGE]
and [TABLE NOT SHOWN] instead of plain text as I would expect.
I know I could use the 'as_text' method to give me plain text straight
from the parse command (method!) but I could use line breaks etc!

    $html2text = new HTML::FormatText;
    $parser = new HTML::TreeBuilder;

    $mywebpage = get($weblink);
    $myhtml = $parser->parse($mywebpage);
    $parser->eof;

        $txtpage = $html2text->format($myhtml);
        $parser->delete;
    
    print $txtpage;

Cheers,

Michael Everitt
m.j.everitt@REMOVEME.iee.org


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

Date: Tue, 10 Jun 2003 18:04:37 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Indenturing words into lists
Message-Id: <mbudash-50FAD3.11044610062003@typhoon.sonic.net>

In article <30fe9f1e.0306100815.2a5d10a0@posting.google.com>,
 satishi@gwu.edu (slash) wrote:

> Hi,
> I am new to Perl and am trying to come up with an indentured list for
> my following output of another program, which uses the following
> segment (thanks to Jay Tilton's earlier posting)
> 
> for( @sorted ) {
>         printf "%s\n%s, %s\n", (split)[0, 1, 3];
>     }
>                    print for @sorted;
> 
> 
> 
> 2002    patent
> 2002    system
> 4       equal
> 4       each
> 4       equal
> 4       on
> 4       june
> 4       2002
> a       having 
> a       d     
> a       second
> a       d     
> a       signal
> a       d
> abstract        2002
> abstract        physical
> abstract        architectures
> abstract        digital
> abstract        cells
> abstract        device
> 
> 
> 
> the output is essentially two columns of words. What I am trying to
> get is the following:
> 
> 2002
>     patent
>     system
> 
> 4       
>     equal
>     each
>     equal
>     on
>     june
>     2002
> 
> a  
>     having 
>     d     
>     second
>     d     
>     signal
>     d
> 
> abstract        
>       2002
>       physical
>       architectures
>       digital
> 
> Any suggestions would be greatly appreciated!
> 
> Thanks,
> Satish

here's a bit of code that should help you:

my $savek;
foreach (@lines) {
  my ($k, $v) = split /\s+/;
  if ($k ne $savek) {
    $savek = $k;
    print "$k\n";
  }
  print "     $v\n";
}

hth-
-- 
Michael Budash


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

Date: Tue, 10 Jun 2003 23:06:16 GMT
From: me@there.com (Phil)
Subject: Mac and Line Breaks
Message-Id: <3ee6636c.5149764@news.t-online.de>

I want to read a text file written on MAC.
When I try to read it in a hash list, it seems to be only one line!

How can I read this file in my perl script, that I have all lines?

I read it in this way:

open(fHANDLE,"<news.txt");
@myList = <fHANDLE>;
close(fHANDLE);

and this does not bring the wished effect:

@myList=~s/^[\s\r\n]*(.*?)[\s\r\n]*$/$1/gm;


many thanks for help,
Phil


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

Date: 10 Jun 2003 23:52:29 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Mac and Line Breaks
Message-Id: <slrnbecrq4.115.mgjv@verbruggen.comdyn.com.au>

On Tue, 10 Jun 2003 23:06:16 GMT,
	Phil <me@there.com> wrote:
> I want to read a text file written on MAC.

And, I assume, this is on another platform?

> When I try to read it in a hash list, it seems to be only one line!

The best way to make sure that that works, is to make sure that you
transfer text files between the various platforms in such a way that
local end-of-line conventions get automatically translated. If that is
not possible, because you mounted a file system remotely, or something
like that, set $/ to the end-of-line character of a MAC file.

Read the section on newlines in the perlport documentation for an
understanding of what's going on.

> How can I read this file in my perl script, that I have all lines?
> 
> I read it in this way:
> 
> open(fHANDLE,"<news.txt");

You should always check that this succeeds.

> @myList = <fHANDLE>;
> close(fHANDLE);

I'd do something like this:

open FH, $file or die "Couldn't open '$file' for reading: $!";
$/ = "\015";
binmode FH;
chomp(my @lines = <FH>);
close FH;

The binmode() is probably not necessary, but I like to be explicit
about when I am working with non-text files. The chomp is there to get
rid of the non-native line endings.

If you need to open other text files, it's probably best to localise
the $/ value change.

Martien
-- 
                        | 
Martien Verbruggen      | Useful Statistic: 75% of the people make up
Trading Post Australia  | 3/4 of the population.
                        | 


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

Date: Tue, 10 Jun 2003 12:08:35 -0700
From: swen <swen@news.com>
Subject: mod_perl memory leak?
Message-Id: <3EE62CB3.935AD041@news.com>

win2k
mod_perl 1.27_01_dev
apache 1.3.27

I have a trivial cgi script (print "content-type: text/html\n\n"; print
'hello';) served by the machine described above under Apache::PerlRun.
The script runs fine, but each time I make a request to the script the
memory usage for the apache process increases by a few kB or so. If I
repeatedly make requests to this script apache's memory usage increases
indefinitely.

My mod_perl config is as follows:

PerlWarn On
 <Location /cgi-bin/>
      PerlSetVar PerlTaintCheck On
      SetHandler perl-script
      PerlHandler Apache::PerlRun # I've also tried Apache::Registry
with same results
      Options +ExecCGI
      PerlSendHeader On
 </Location>

Has anyone else encountered this problem? I know there are plenty of
people running with this setup (apache 1.3.x + mod_perl1.x + win2k) with
no problems, so there's something wrong with my install or
config...anything obviously wrong based on what I've presented here?

Thanks.



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

Date: 10 Jun 2003 12:33:11 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: need the ascii set for arrow down
Message-Id: <3ee63277@news.victoria.tc.ca>

gerrym (gerard.maloney@intel.com) wrote:
: Hello 
: I have aq ascii menu on a linux box which uses the arrow up and down
: to nagivate the menus.
: I want to automate it using Perl Expect.pm, but I cannot find the
: character set I need to send.

: Anyone come across a table of these before.

Not 100% sure what you mean.

When the user types the up or down arrow keys then a series of characters
are sent to the program.

I typically use od to check what characters are send for keys strokes.

So on one machine, I ran od and pressed down-arrow, and then Enter, and
then ^D (to exit od) and what I saw was

	$ od -c
	^[[B
	0000000 033   [   B  \n
	0000004

Which lets me know that pressing the down arrow key caused three
characters to be sent to the program, the escape character (033) the left
square bracket ([) and uppercase B.



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

Date: 10 Jun 2003 14:08:57 -0700
From: uzmargov@yahoo.com (Zack)
Subject: NEWBEE: Client-Server Timout implementation
Message-Id: <a5f6b9a8.0306101308.3c9cc9c2@posting.google.com>

Hi,  
I am very new to perl and network programming, so bear with me please.
I am trying to write the client-server app. that is going receive a
request from a client,
process the request and send the reply back.  The request process is
going to be some kind
outside program that will be started from my server.  
At this moment I successfully implemented the communication part
between client and server,
however I would like to add the timeout signal.  So, that if the
outside process would
take too much time (or would hang), the client would receive the
timeout message and the
server should kill the process. I wrote the ALRM signal handler
however there are some problems,
which I can't figure out. It seems that:
1. Any command is running for as long as alarm($timeout) value is set
(so if timeout is 15 seconds -- it takes 15 seconds for the child
process to execute) and I want to return the reply to client
immediately after process is done. For example if I set timeout for 20
minutes, I do not want to wait for this time just to receive an
acknowledgement (like "Hello", for instance)
2. The server always logs the timeout message.


Bellow is the code snippet for server:


$SIG{'ALRM'} = 'Signal_Handler';

%ERRORS = (
error1 => {error_id => 1, error_msg => "Couldn't bind to port
SERVER_PORT",},
error2 => {error_id => 2,error_msg => "Couldn't listen on port
$SERVER_PORT", },
error3 => {error_id => 3, error_msg => "Can't fork a process",},
error4 => {error_id => 4, error_msg => "Didn't understand the
question!"},
error5 => {error_id => 5, error_msg => "The process timeout
occured!"},
);

%WARNINGS = (
warning1 => {warning_id => 1,warning_msg => "Server is started on
$SERVER_NAME:$SERVER_PORT",},
warning2 => {warning_id => 2, warning_msg => "Caught the request from
a Client:",},
warning3 => {warning_id => 3, warning_msg => "Received request from
Client:",},
warning4 => {warning_id => 4, warning_msg => "Caught Signal:",},
);

MAIN: {
# some initialization code for sockets is skipped
 .................
 .................
 .................

# Accept and process connections
while ($client_paddr = accept($CLIENT, $SERVER)) {
  select((select($SERVER), $| = 1)[0]);           #enable command
buffering
  # do something with the new Client connection
  {
    my ($port, $iaddr) = sockaddr_in($client_paddr);
    my $cname = gethostbyaddr($iaddr,AF_INET);
    Log_Warning($WARNINGS{warning2},$cname);  #logs warning
  }

  # fork the child process for each connection
  FORK: {
    if ($pid = fork) {
      # parent here.  Child process pid is available in $pid
      alarm($TIMEOUT);
      waitpid($pid,WNOHANG);
      alarm(0);
    }
    elsif (defined $pid) { #$pid is zero here if defined
      # child here parent process pid is available with getppid
      work_with_client($client_paddr, $CLIENT);
    }
    elsif ($! == EAGAIN) {
      # EAGAIN is the supposedly recoverable fork  error
      sleep 5;
      redo FORK;
    }
    else {
      # Some weird fork error occurred
      die Log_Error($ERRORS{error3}, $!);  #Logs error
    }
   close($CLIENT);
  } # End FORK.
} # END while
close($SERVER);
} # END MAIN
#####################################################################
sub Signal_Handler {
  local($sig) = shift;
  my $msg;

  if ($sig eq "ALRM") {
    $msg  = "ERROR: ID = " . $ERRORS{error5}->{error_id} . "; ";
    $msg .= "MESSAGE: " . $ERRORS{error5}->{error_msg}. "||||";
    Log_Warning($WARNINGS{warning4},$sig);

    Send_Reply($CLIENT, $msg);
    kill 9, $pid if $pid;
  }

}
#####################################################################


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

Date: 10 Jun 2003 15:09:23 -0700
From: alan_grow@hotmail.com (Alan)
Subject: Re: open2 under windows
Message-Id: <e8791f31.0306101409.6d06c93e@posting.google.com>

Thanks everyone:

  To follow up, I finally got IPC::Open2 to work under Unix and Win,
so thanks. I'd say the key was using $| in the child process to force
flushing. However, it's still a little unsatisfying because there may
be programs I want to talk to that don't flush. Would I be sol then?

  -Alan


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

Date: Tue, 10 Jun 2003 22:30:17 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: open2 under windows
Message-Id: <ZZsFa.1246$KZ1.614@newssvr16.news.prodigy.com>

Alan <alan_grow@hotmail.com> wrote:
> Thanks everyone:

>   To follow up, I finally got IPC::Open2 to work under Unix and Win,
> so thanks. I'd say the key was using $| in the child process to force
> flushing. However, it's still a little unsatisfying because there may
> be programs I want to talk to that don't flush. Would I be sol then?

Yup.  That's the whole reason behind all the warnings in Open2.

% perldoc IPC::Open2
[snip...]
    This whole affair is quite dangerous, as you may block forever.  It
    assumes it's going to talke to something like bc, both writing to it and
    reading from it. This is presumably safe because you "know" that
    commands like bc will read a line at a time and output a line ata time.
    Programs like sort that read their entire input stream first, however, 
    are quite apt to cause deadlock.

    The big problem with this approach is that if you don't have control
    over source code being run in the child process, you can't control what
    it does with pipe buffering. Thus you can't just open a pipe to "cat -v"
    and continually read and write a line from it.

You may have noted that your child program behaved differently based on
whether it thought the output was to a pipe or to a tty.  Other
processes may do the same.  The POD goes on to talk about IO::Pty and
Expect, because they may provide a PTY to a process, so that its
behavior may be set to flush after a line.

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

Date: Tue, 10 Jun 2003 19:33:00 GMT
From: 10ghz@radiate.com
Subject: Re: Perl CGI and Downloading Files - How?
Message-Id: <5g8cevgclose1mf4a2od506nami6tcrje4@4ax.com>

On 10 Jun 2003 13:03:27 +0100, Brian McCauley <nobull@mail.com> wrote:

>Using CGI the best way is to make the CGI script's response be an
>internal redirect to a web location that is accessible only via
>internal redirects.  This is, of course, totally independant of the
>language in which the CGI script is written.

Probably the first intelligent thing anyone has said to me to me here. At least
it is slightly more clear than the other muddy rhetoric I've been given.
Although, I did find a much more Perlish way to do it, but if I can do it in
fewer lines of code another way then I will investigate that. Or, is this just
another goose-chase propagated by sarcasm and sophistry? It's so hard to tell in
this forum.  In either case, I appreciate the effort!


Hume's Fork: Our lives are either predetermined, in which case we are not
responsible for them, or the result of random events, in which case we are not
responsible for them.


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

Date: Tue, 10 Jun 2003 14:28:20 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Perl Matrix Filter Module like in Excel?
Message-Id: <4nsmqhpz23.fsf@lockgroove.bwh.harvard.edu>

On Tue, 10 Jun 2003, Dennis@NoSpam.com wrote:
> In Excel VBA you can filter any column of the spreadsheet, with
> commands like top 10% of column A and bottom 5% of column B and only
> thus rows that satisfy both conditions will show.
> 
> Is there a perl module that can do the same thing?

Perl can limit the data retrieved from a source to any percentage you
want, but displaying that data is not built into Perl the way Excel
does it.

Ask a more specific question, with sample data and what you're trying
to do, and we can help you better.

Ted


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

Date: Tue, 10 Jun 2003 14:59:35 -0500
From: Dennis@NoSpam.com
Subject: Re: Perl Matrix Filter Module like in Excel?
Message-Id: <eedcevot5dpfnba2fmtkpkve1rqbq0clkr@4ax.com>

Thanks Ted here is a more concrete example.

Suppose I have a matrix with 30 columns and 5000 rows.

Each row represents a different case calculation and each column represents a
specific calculation.  For instance Column A is the case #, Column B is the
standard deviation(std) of that case, Column C is the average (ave) of that case
and so forth with the other columns.

What I'd like to do in perl is create another matrix with the same columns but
whose rows satisfy some column criteria.  As an example I'd like to find all the
rows whose Column B std is in the bottom 10% of all 5000 std's in that column 
AND whose Column C ave is in the Top 10% of all 5000 ave's in the ave column.

This will create a new matrix with 30 columns and anywhere from 0 to N rows
where N<5000.

I don't care to display this new filtered matrix but I would like to save it or
write it to a new file.

Any perl modules that handles matrix filter manipulations like above.?

Thanks.

Dennis


Ted Zlatanov <tzz@lifelogs.com> wrote:

>On Tue, 10 Jun 2003, Dennis@NoSpam.com wrote:
>> In Excel VBA you can filter any column of the spreadsheet, with
>> commands like top 10% of column A and bottom 5% of column B and only
>> thus rows that satisfy both conditions will show.
>> 
>> Is there a perl module that can do the same thing?
>
>Perl can limit the data retrieved from a source to any percentage you
>want, but displaying that data is not built into Perl the way Excel
>does it.
>
>Ask a more specific question, with sample data and what you're trying
>to do, and we can help you better.
>
>Ted



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

Date: Tue, 10 Jun 2003 19:56:12 +0100
From: "scottlc" <e@1.com>
Subject: Re: Question about a counter.
Message-Id: <bc59k3$tvu$1@news7.svr.pol.co.uk>

You need to use SSI (server side includes).

"Joe Creaney" <mail@annuna.com> wrote in message
news:3EE3625F.2010002@annuna.com...
> I realize this a bit off topic but I wrote a counter that works I just
> want to access it from my web page.  How do I do it.  This is the only
> command I have:
>
> <!--#exec cgi="/cgi-bin/count1.pl" -->
>
> Is this right?
>




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

Date: Tue, 10 Jun 2003 18:09:47 GMT
From: "HongKongHooker" <sumguy@hooker.com>
Subject: Re: Regular expression
Message-Id: <L9pFa.638477$Si4.578115@rwcrnsc51.ops.asp.att.net>

Do you have (or could you include) any delimiters between the the key=value
pairs?
    Example: "UPDATE=June 3, 2003:OS=5.7:MEMORY=512 MB"
    Where the delimiter is ':'

Or should your application check for keywords? Example UPDATE, OS, MEMORY...
    Example:
     $_ = "UPDATE=June 3, 2003 OS=5.7 MEMORY=512 MB";
     /UPDATE=(.*).*OS=(.*).*MEMORY=(.*)/;
    $hash = {};
    $hash->{UPDATE} = $1;
    $hash->{OS} = $2;
    $hash->{MEMORY} = $3;
    #test
    print "$hash->{UPDATE} $hash->{MEMORY} $hash->{OS}";

Your particular problem can be handled in various ways, however, you'll need
to choose a record delimiting format (can be string size using pack() as
well).

Let us know.

"Ian" <iang@optonline.com> wrote in message
news:e3cb452a.0306100938.177b22e8@posting.google.com...
> I have the following working by a series of splits, I have tried to
> obtain the correct regular expression that woould work.
>
> Say I had the following input line:
>
> UPDATE=June 3, 2003 {maybe a time here or not} OS=5.7 MEMORY=512 MB
> {possibly more data following the KEY=VALUE notation.
>
> I would like to parse it so that I  create a hash such that
>
> $hash{UPDATE} = "june 3, 2003....."
> $hash{OS} = "5.7"
>
> so on.
>
> So ideally I would like to create a string such that I can say
>              %hash = ($string)
> where string is (UPDATE,"June 3, 2003",OS,"5.7",MEMORY,512).
>
>
> Can this be done as a single regex?  if so how.
>
> Thanks in advance.




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

Date: Tue, 10 Jun 2003 18:21:18 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Regular expression
Message-Id: <mbudash-04F9DF.11212810062003@typhoon.sonic.net>

In article <e3cb452a.0306100938.177b22e8@posting.google.com>,
 iang@optonline.com (Ian) wrote:

> I have the following working by a series of splits, I have tried to
> obtain the correct regular expression that woould work.
> 
> Say I had the following input line:
> 
> UPDATE=June 3, 2003 {maybe a time here or not} OS=5.7 MEMORY=512 MB
> {possibly more data following the KEY=VALUE notation.
> 
> I would like to parse it so that I  create a hash such that
> 
> $hash{UPDATE} = "june 3, 2003....."
> $hash{OS} = "5.7"
> 
> so on.
> 
> So ideally I would like to create a string such that I can say
>              %hash = ($string)
> where string is (UPDATE,"June 3, 2003",OS,"5.7",MEMORY,512).
> 
> 
> Can this be done as a single regex?  if so how.
> 
> Thanks in advance.

do you really need such a string? or do you just want to initialize the 
hash? this will do the latter:

$_ = "UPDATE=June 3, 2003 {maybe a time here or not} OS=5.7 MEMORY=512 
MB";

my %hash;

# get all dates
while (/(\S+)=(\w+\s+\d+,\s+\d{4})/g) {
  $hash{$1} = $2;
}

# get all KKK=VVV
while (/(\S+)=(\S+)/g) {
  (defined $hash{$1}) || ($hash{$1} = $2);
}


-- 
Michael Budash


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

Date: Tue, 10 Jun 2003 18:29:30 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regular expression
Message-Id: <slrnbecqeq.lbg.tadmc@magna.augustmail.com>

Ian <iang@optonline.com> wrote:

> Say I had the following input line:
> 
> UPDATE=June 3, 2003 {maybe a time here or not} OS=5.7 MEMORY=512 MB
> {possibly more data following the KEY=VALUE notation.
> 
> I would like to parse it so that I  create a hash such that
> 
> $hash{UPDATE} = "june 3, 2003....."
> $hash{OS} = "5.7"


> Can this be done as a single regex?  if so how.


Assuming the input string is in $_:

   my %hash = /(\w+)=(.*?)(?=\s*\w+=|$)/g;


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 10 Jun 2003 23:56:37 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Regular expression
Message-Id: <mbudash-28C212.16563710062003@typhoon.sonic.net>

In article <slrnbecqeq.lbg.tadmc@magna.augustmail.com>,
 tadmc@augustmail.com (Tad McClellan) wrote:

> Ian <iang@optonline.com> wrote:
> 
> > Say I had the following input line:
> > 
> > UPDATE=June 3, 2003 {maybe a time here or not} OS=5.7 MEMORY=512 MB
> > {possibly more data following the KEY=VALUE notation.
> > 
> > I would like to parse it so that I  create a hash such that
> > 
> > $hash{UPDATE} = "june 3, 2003....."
> > $hash{OS} = "5.7"
> 
> 
> > Can this be done as a single regex?  if so how.
> 
> 
> Assuming the input string is in $_:
> 
>    my %hash = /(\w+)=(.*?)(?=\s*\w+=|$)/g;

nice...

-- 
Michael Budash


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

Date: Tue, 10 Jun 2003 19:40:36 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: setOutput in Perl
Message-Id: <pan.2003.06.10.17.24.29.731737@kamelfreund.de>

big__smile wrote at Tue, 10 Jun 2003 09:09:13 -0700:

> now the xml output is being directed to another file but when i run
> the cgi script it displays the xml bit (which i don't wanna c)
> so i found this function called setOutput in perldoc XML::Writer
> but i get an error saying that the subroutine is undefined!!
> i use it on a line by itself 
> setOutput($output);

Well, XML::Writer is object oriented.
Usually, you would use it as something like

use XML::Writer;
 ...
my $writer = XML::Writer->new;
 ...
$writer->setOutput($output);

Have you called in that way or did you simply write
setOutput($output);
? (In that way Perl doesn't know that it has to use the setOutput method
from XML::Writer and apply it to this specific object)


Greetings,
Janek


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

Date: Tue, 10 Jun 2003 14:26:02 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: stripping leading zeros thru multiple fields
Message-Id: <4nwuftpz5x.fsf@lockgroove.bwh.harvard.edu>

On 10 Jun 2003, mfabache@yahoo.com wrote:
> I've come up with the following (via searches and copying code) to
> strip all leading zeros thru a date field, but I cannot figure how
> to get to the 2nd field+
> 
> Expected data: "06/06/2003"
> Expected output: "6/6/2003"
> Current output: "6/06/2003)" # How can I tweak this?
> 
> ----
> 
> use POSIX qw(strftime) ;
># $now_string = strftime "%m/%d/%Y", localtime;
> $now_string = "06/06/2003"; # for testing porposies
> print "$now_string\n";
> 
> $now_string =~ s/0(\d+)/$1/; #strip leading zero off of MONTH, now need DAY
> print "$now_string\n";

There are definitely better ways of doing this, but to answer your
question, one way of doing it with a regular expression:

s/(\d+)/$1+0/ge;

Ted


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

Date: Tue, 10 Jun 2003 21:40:01 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: stripping leading zeros thru multiple fields
Message-Id: <3EE65030.B2A8239C@acm.org>

MF wrote:
> 
> I've come up with the following (via searches and copying code) to
> strip all leading zeros thru a date field, but I cannot figure how to
> get to the 2nd field+
> 
> Expected data: "06/06/2003"
> Expected output: "6/6/2003"
> Current output: "6/06/2003)" # How can I tweak this?
> 
> use POSIX qw(strftime) ;
> # $now_string = strftime "%m/%d/%Y", localtime;
> $now_string = "06/06/2003"; # for testing porposies
> print "$now_string\n";
> 
> $now_string =~ s/0(\d+)/$1/; #strip leading zero off of MONTH, now need DAY

$now_string =~ s/\b0//g;

> print "$now_string\n";


John
-- 
use Perl;
program
fulfillment


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

Date: 10 Jun 2003 15:42:50 -0700
From: mfabache@yahoo.com (MF)
Subject: Re: stripping leading zeros thru multiple fields
Message-Id: <2855726c.0306101442.588e8f7a@posting.google.com>

> 
> There are definitely better ways of doing this, but to answer your
> question, one way of doing it with a regular expression:
> 
> s/(\d+)/$1+0/ge;
> 
> Ted

Yes, I can imagine many better ways to write what I wrote.  I'm new to
PERL, so these are all small, learning steps.  One day, I'll look back
and say, 'WTF?'

Thanks to you and Michael B. for helping us newbies...


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

Date: 10 Jun 2003 15:56:45 -0700
From: gdsafford@hotmail.com (Greg)
Subject: Re: stripping leading zeros thru multiple fields
Message-Id: <a8f367ed.0306101456.7ce57dd6@posting.google.com>

mfabache@yahoo.com (MF) wrote in message news:<2855726c.0306100923.3d82edc@posting.google.com>...
> I've come up with the following (via searches and copying code) to
> strip all leading zeros thru a date field, but I cannot figure how to
> get to the 2nd field+
> 
> Expected data: "06/06/2003"
> Expected output: "6/6/2003"
> Current output: "6/06/2003)" # How can I tweak this?
> 
> Thanks,
> Michael
> ----
> 
> use POSIX qw(strftime) ;
> # $now_string = strftime "%m/%d/%Y", localtime;
> $now_string = "06/06/2003"; # for testing porposies
> print "$now_string\n";
> 
> $now_string =~ s/0(\d+)/$1/; #strip leading zero off of MONTH, now
> need DAY
> print "$now_string\n";

If what you want is to delete any string of zeros not preceded by a
digit but with a digit following, another strategy would be to say
what you want directly:

my $s = '0010/002/003003/0';
$s =~ s/(?<!\d)0+(?=\d)//g;
print $s, $/; # prints 10/2/3003/0

I'm no Perl expert, so I can't say anything about efficiency.

FWIW


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

Date: Tue, 10 Jun 2003 22:10:00 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Time limit
Message-Id: <871xy1egno.fsf@mithril.chromatico.net>

"Jürgen Exner" <jurgenex@hotmail.com> writes:

> Zvezdoshka@nowhere.ru wrote:
> > In a quizz, I want setup a time limit for users to reply to each
> > question. What's the best way to do this ?
> 
> Did you see the FAQ "How do I timeout a slow event?"
> 
> > A cookie that expires in xx
> > seconds, is that the only way ?
> 
> Perl has cookies? Interesting....

Oatmeal chocolate chip, no less.

Charlton


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

Date: Wed, 11 Jun 2003 00:34:53 GMT
From: ktom <abc@nowhere.com>
Subject: using Dumper to save hash and retrieving it.
Message-Id: <3EE6795F.8030007@nowhere.com>

i have created a file using the Data::Dumper command..

the command used was
print OFILE Data::Dumper->Dump([\%pHash],['*xHash']);

it created the file whose first few lines look like.
%xHash = (
   '25' => {
     '1169' => {
       'value' => '3.157',
       'name' => 'PSSYNC_VOH'
     },
     '559' => {

i am trying to retrieve is using the do (as suggested in the book) and 
having troubles.  i have used the forms below and i haven't been able to 
access or print (using Dumper) the values that i thought i have brought in.

#my $xHash = do $inFile2 || die "can't consume dbFile $inFile2\n";
#%postHash = do $inFile2 || die "can't consume dbFile $inFile2\n";
do $inFile2 || die "can't consume dbFile $inFile2\n";
print Dumper(%postHash);
print Dumper(%{$xHash});
print %xHash;

what is the magic that allows me to recreate the hash that i output 
using the print OFILE Data::Dumper->Dump([\%pHash],['*xHash']); command.

thanks kevint



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

Date: Tue, 10 Jun 2003 21:07:46 GMT
From: "Chip" <chip@NO-Spam-afcoms.com>
Subject: Re: virtual x server for Tk
Message-Id: <CMrFa.3184$Jw6.2298881@news1.news.adelphia.net>


"Darren Dunham" <ddunham@redwood.taos.com> wrote in message
news:79oFa.2559$_P2.130646217@newssvr21.news.prodigy.com...
> It is unclear to me from your post what your intention is.  Do you want
> to see TK output on the screen in front of you?

Yes Darren, I am telneting ( or using ssh ) into a server from another
box and want the display to be on the box I am in front of, not the server.

>You say you used 'telnet' to reach the server, but telnet is
>insufficient to carry back the graphical information.

First year perl student and just writing small homework program for class.


> You might be able to run (or already be running) an X server in front of
> you (at your remote location).  If so, you could probably set the
> DISPLAY properly on the machine so the TK program knows where to send
> the output.

I'm Using putty to telnet in from a windows box.  I think your on
the right track because I have seen referances to redirecting the
display but that is where my problem is.

> None of this really has anything in particular to do with perl.  It just
> sounds like normal X traffic.

You are right because when sitting on the console of the server with
KDE running it works fine.  Tried this group because of the vast knowledge
available.  Was not aware of the comp.lang.perl.tk group will try there.

Thanks for your help and if you have any more information
please let me know.

Chip


"Darren Dunham" <ddunham@redwood.taos.com> wrote in message
news:79oFa.2559$_P2.130646217@newssvr21.news.prodigy.com...
> Chip <chip@no-spam-afcoms.com> wrote:
> > I am trying to use the Tk module with perl when I telnet
> > into my server from a remote location and keep getting
> > the following error:
>
> > <snip>
> > couldn't connect to display ":0"
> > at /usr/lib/perl5/site_perl/5.8.0/i386-linux/Tk/MainWindow.pm
> > </snip>
>
> > I have installed the Tk-800.0024.tar.gz and can run the scripts
> > from the server with the KDE 3.1 desktop so I know the scripts
> > and the Tk module are working correctly.
>
> > All the information I have found on google points to running a
> > virtual x server but I can't seem to find anything on how to set
> > it up.
>
> It is unclear to me from your post what your intention is.  Do you want
> to see TK output on the screen in front of you?  You say you used
> 'telnet' to reach the server, but telnet is insufficient to carry back
> the graphical information.
>
> You might be able to run (or already be running) an X server in front of
> you (at your remote location).  If so, you could probably set the
> DISPLAY properly on the machine so the TK program knows where to send
> the output.
>
> None of this really has anything in particular to do with perl.  It just
> sounds like normal X traffic.
>
> -- 
> Darren Dunham                                           ddunham@taos.com
> Unix System Administrator                    Taos - The SysAdmin Company
> Got some Dr Pepper?                           San Francisco, CA bay area
>          < This line left intentionally blank to confuse you. >




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

Date: 10 Jun 2003 11:30:14 -0700
From: tivolinewbie@canada.com (Kenjis Kaan)
Subject: Re: Win32::ListView  sample please??
Message-Id: <6a8ba9f8.0306101030.5ee5af04@posting.google.com>

"Mothra" <mothra@nowhereatall.com> wrote in message news:<3ee5e083$1@usenet.ugs.com>...
> Hi Kenjis,
> 
> "Kenjis Kaan" <tivolinewbie@canada.com> wrote in message
> news:6a8ba9f8.0306092248.78b6263c@posting.google.com...
> > Hi,  I am trying to create a listview program but no matter what I do
> > its is not working.  I wonder if its because of the activestate perl
> > (5.6.1) I am using.  I can open up a win32 window but the listview
> > just isn't what I wanted.
> 
> [snipped]
> 
> What is ListView? I checked CPAN and found no ListView.
> 
> Mothra

But to be honest, its not worth it.  Don't bother, you are wasting
your time, there is too much problems with thie Win32::GUI module.  I
am junking the whole development branch to start anew and will just
use a Web interface to display everything.


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 5104
***************************************


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