[22925] in Perl-Users-Digest
Perl-Users Digest, Issue: 5145 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 27 11:05:45 2003
Date: Fri, 27 Jun 2003 08:05:10 -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 Fri, 27 Jun 2003 Volume: 10 Number: 5145
Today's topics:
Re: Altering values by reference <nobull@mail.com>
Re: Altering values by reference <ubl@schaffhausen.de>
Re: Am I being boycotted? <goedicke@goedsole.com>
Re: Anybody making Windows interfaces w/ Perl? (Helgi Briem)
BTree examples ?? (Kenjis Kaan)
Re: BTree examples ?? <russ.jones2@boeing.com>
Re: BTree examples ?? <ubl@schaffhausen.de>
Re: Forking child process with WWW::Automate <Graham.T.Wood@oracle.com>
Fun with Threads - "Attempt to free unreferenced scalar <stjm2@hermes.cam.ac.uk>
Re: How does @LAST_MATCH_START work? <Olof.KarlbergNOSPAMatebc.uu.se>
Re: How does @LAST_MATCH_START work? <johannes.fuernkranz@t-online.de>
Re: How does @LAST_MATCH_START work? <abigail@abigail.nl>
Re: how to convert all invalid UTF-8 sequences to numer <flavell@mail.cern.ch>
Re: HTML::TableExtract Simple question (Helgi Briem)
Re: Installing CtCmd on Windows (Sherman Willden)
Re: need assistance understanding multilevel hashes. <allen.wooden@educate.invalid>
Re: Nutshell <johannes.fuernkranz@t-online.de>
Re: Nutshell <abigail@abigail.nl>
Re: Offer tips, comments on this code (generates html t (Anno Siegel)
Thank you all! Tk doesn't look hard to learn. <SeeMessageBody@nospam.com>
UNIX Domain sockets on HPUX <russ.jones2@boeing.com>
Re: Using local $/ (Anno Siegel)
Re: Using local $/ (Tad McClellan)
Using perl/shell scripts to kill processes more than x (Jimmy)
Re: Using perl/shell scripts to kill processes more tha <someone@somewhere.nl>
Re: Using perl/shell scripts to kill processes more tha <c.f.a.johnson@rogers.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 Jun 2003 12:51:59 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Altering values by reference
Message-Id: <u9brwjeo0w.fsf@wcl-l.bham.ac.uk>
Thens <thens@nospam.com> writes:
> sub doSomething{
> my ($arg1, $arg2) = @_;
> ..
> }
>
> sub doSomething{
> my $arg1 = shift;
> my $arg2 = shift;
> ..
> }
> Since you (and perldoc perlsub) say that the @_ contains aliases
> to scalar parameters and when you shift it they become values.
No, they remain aliases (lvalues) even when you shift. It is when you
evaluate then in an rvalue context (i.e. a context like that found on
RHS of an assignment) they become (r)values.
sub one {
# Due to a mis-feature of the Perl compiler this genreates spurious
# compile-time error:
# Can't modify shift in postincrement (++)
# If I try to do:
# shift()++;
# Actually you can, but you have to fool the compiler in to not noticing.
$_++ for shift;
}
sub two {
$_[0]++;
}
my $q = 1;
one($q);
print "After one(): $q\n";
two($q);
print "After two(): $q\n";
__END__
After one(): 2
After two(): 3
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 27 Jun 2003 16:24:10 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Altering values by reference
Message-Id: <bdhn6j$im6$1@news.dtag.de>
Brian McCauley wrote:
> $_++ for shift;
hehe :)
------------------------------
Date: Fri, 27 Jun 2003 13:55:25 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: Am I being boycotted?
Message-Id: <m34r2baam2.fsf@mail.goedsole.com>
Dear Jay et al -
>>>>> "Jay" == Jay Tilton <tiltonj@erols.com> writes:
William Goedicke <goedicke@goedsole.com> wrote:
I've had no response to my last dozen questions.
Jay> That sounds high. I only remember seeing two--one about a
Jay> universally convertible report format, and one about cycles
Jay> in graphs.
You're right I exaggerated. Thanks to all for alleviating my concerns.
Yours - Billy
============================================================
William Goedicke goedicke@goedsole.com
http://www.goedsole.com:8080
============================================================
Lest we forget:
We hold these truths to be self-evident, that all men are created
equal, that they are endowed [...] with certain unalienable Rights,
that among these are Life, Liberty and the pursuit of Happiness.
- The Declaration of Independence
------------------------------
Date: Fri, 27 Jun 2003 10:10:16 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Anybody making Windows interfaces w/ Perl?
Message-Id: <3efc174e.348813000@news.cis.dfn.de>
On Fri, 27 Jun 2003 05:59:53 GMT, "John" <SeeMessageBody@nospam.com>
wrote:
>The sample below makes a simple message box in MS Windows. The rest of the
>Win32 and Win32API modules includes handy interfaces to the OS, but no other
>GUI objects like the message box (e.g., radio boxes, pull-down menus,
>fill-in forms, etc.). Or am I missing something?
>
>I am about to install and learn Visual C++ 6 and want to make sure I'm not
>wasting my time. I would prefer to keep everything pure Perl if possible.
Use Perl/Tk then.
------------------------------
Date: 27 Jun 2003 06:01:26 -0700
From: tivolinewbie@canada.com (Kenjis Kaan)
Subject: BTree examples ??
Message-Id: <6a8ba9f8.0306270501.1b436eb0@posting.google.com>
Hello. I am wondering if anyone has an example of using BTree for
storing data on a disk file.?? I found some BTree modules on the
web, but none give example of how you would then store it and retrieve
it from disk drive. I have a need to store hundred of thousands of
key, data values but told not to use a RDBMS. It would be nice if I
can get some sample of that actually shows the write to disk and
subsequent retrieval from it, which then allows you to do search for
records by supplying a key. TIA
------------------------------
Date: Fri, 27 Jun 2003 13:34:19 GMT
From: Russ Jones <russ.jones2@boeing.com>
Subject: Re: BTree examples ??
Message-Id: <Xns93A7573436642russjones2boeingcom@192.54.3.19>
tivolinewbie@canada.com (Kenjis Kaan) wrote in
news:6a8ba9f8.0306270501.1b436eb0@posting.google.com:
> Hello. I am wondering if anyone has an example of using BTree for
> storing data on a disk file.?? I found some BTree modules on the
> web, but none give example of how you would then store it and retrieve
> it from disk drive. I have a need to store hundred of thousands of
> key, data values but told not to use a RDBMS. It would be nice if I
> can get some sample of that actually shows the write to disk and
> subsequent retrieval from it, which then allows you to do search for
> records by supplying a key. TIA
>
Using a hash to hold your data and then using the Storable module to save
and retrieve it comes immediately to mind, but that "hundreds of
thousands" of records sounds pretty big.
The venerable "Algorithms + Data Structures = Programs," Niklaus Wirth,
1975, contains (as I recall) some BTree code. It's in Pascal, but it might
be a starting place.
------------------------------
Date: Fri, 27 Jun 2003 16:57:37 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: BTree examples ??
Message-Id: <bdhp5a$kcd$1@news.dtag.de>
Kenjis Kaan wrote:
> Hello. I am wondering if anyone has an example of using BTree for
> storing data on a disk file.?? I found some BTree modules on the
> web, but none give example of how you would then store it and retrieve
> it from disk drive. I have a need to store hundred of thousands of
> key, data values but told not to use a RDBMS. It would be nice if I
> can get some sample of that actually shows the write to disk and
> subsequent retrieval from it, which then allows you to do search for
> records by supplying a key. TIA
Wouldn't DBD::SQLite be a solution? This module includes a complete
public domain RDBMS.
http://search.cpan.org/author/MSERGEANT/DBD-SQLite-0.25/lib/DBD/SQLite.pm
You could use it and not tell anybody :)
malte
------------------------------
Date: Fri, 27 Jun 2003 15:38:31 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Forking child process with WWW::Automate
Message-Id: <3EFC56E7.2EBBBBDC@oracle.com>
This is a multi-part message in MIME format.
--------------505D0441BB6C12AFF4C4993F
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Bart Lateur wrote:
> Graham Wood wrote:
>
> >I'm attempting to automate a login to a web server with WWW::Automate
> >and then to continue navigating through the website.
>
> Currently the favourite module to do this kind of thing is
> WWW::Mechanize, which is "inspired" by WWW::Automate. In addition,
> there's WWW::Mechanize::Shell, which lets you explore the website using
> WWW::Mechanize using an interactive prompt interface.
>
> It has built-in support for cookies.
>
> --
> Bart.
Thanks Bart, I've got the WWW::Mechanize stuff now.
Graham
--------------505D0441BB6C12AFF4C4993F
Content-Type: text/x-vcard; charset=UTF-8;
name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
filename="Graham.T.Wood.vcf"
begin:vcard
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.Wood@oracle.com
fn:Graham Wood
end:vcard
--------------505D0441BB6C12AFF4C4993F--
------------------------------
Date: Fri, 27 Jun 2003 13:58:58 +0100
From: Stuart Moore <stjm2@hermes.cam.ac.uk>
Subject: Fun with Threads - "Attempt to free unreferenced scalar during global destruction."
Message-Id: <Pine.SOL.4.44.0306271347280.25299-100000@orange.csi.cam.ac.uk>
My aim is to have a module, "ToolsThread", which I can pass commands to so
that it'll execute them in its own thread. However when I call join on the
thread, it seems to all go wrong. It all behaves as normal up to the point
I call join on the thread in the quit function, then it gives me the
message
Attempt to free unreferenced scalar during global destruction.
I'm not sure what that means, but I don't like it.
Here is the relevant code (ToolsThread.pm is the module, testToolsThread
is a basic test script. I would have more code in the loop eventually,
assuming I can get it to work)
##ToolsThread.pm
package ToolsThread;
use strict;
use warnings;
use threads;
use threads::shared;
use Thread::Queue;
our $queue = new Thread::Queue;
our $thread = threads->create(\&Run,$queue);
sub Run{
my $queue = shift;
while(1){
my $incoming = $queue->dequeue;
if ($incoming eq "quit"){
last;
}
}
}
sub Quit{
$queue->enqueue('quit');
$thread->join();
}
##testToolsThread.pl
use strict;
use warnings;
use threads;
use threads::shared;
use Thread::Queue;
use ToolsThread;
ToolsThread::Quit;
------------------------------
Date: Fri, 27 Jun 2003 12:44:02 +0200
From: Olof Karlberg <Olof.KarlbergNOSPAMatebc.uu.se>
Subject: Re: How does @LAST_MATCH_START work?
Message-Id: <20030627124402.290b5355.Olof.KarlbergNOSPAMatebc.uu.se@molev155.ebc.uu.se>
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> [A complimentary Cc of this posting was sent to
> Olof Karlberg
> <Olof.KarlbergNOSPAMat.ebc.uu.se>], who wrote in article <20030627091642.72fa3e9d.Olof.KarlbergNOSPAMatebc.uu.se@molev155.ebc.uu.se>:
> > $target =~ m/$query/g;
> > print "Number of matches: $#-\n";
>
> Some time ago the parser had a hard time groking this. I would try
> $#{'-'} or some such instead.
>
> Ilya
Thanks, but the result is the same. I also noted that $-[-1] == $-[0] which means that @- only holds one element although the string should match twice.
//Olof
------------------------------
Date: Fri, 27 Jun 2003 13:39:24 +0200
From: =?ISO-8859-1?Q?Johannes_F=FCrnkranz?= <johannes.fuernkranz@t-online.de>
Subject: Re: How does @LAST_MATCH_START work?
Message-Id: <bdhadp$jjn$04$1@news.t-online.com>
Olof Karlberg wrote:
> #!/usr/bin/perl -w
>
> my $target = "QWERTY QWERTY";
> my $query = "ERT";
>
> $target =~ m/$query/g;
> print "Number of matches: $#-\n";
> print "First match begins at: $-[0]\n";
> print "First match ends at: $+[0]\n";
> print "2:nd match begins at: $-[1]\n";
> print "2:nd match ends at: $+[1]\n";
>
> What is going on here? Have I totally misunderstood the docs?
Wow. I had never seen @- and @+ before. Are these new in 5.8? Perl in a
Nutshell (2nd ed for 5.8) does not seem to carry them either, however.
Anyways: Yes, you did misunderstand the docs.
@+ and @- do not contain multiple matches, but they contain the starting
indices of all (..) expressions. Replace
$target =~ m/$query/g;
with
$target =~ m/(E)R(T)/g;
and you'll see.
What you probably want to do is the following:
my $target = "QWERTY QWERTY";
my $query = "ERT";
my $i = 0;
while($target =~ m/$query/g) {
printf "Match %d begins at %d\n", ++$i, pos $target;
}
You also want to look at the \G anchor in perlre.
There's longer code example in perlop.
cheers, Juffi
------------------------------
Date: 27 Jun 2003 12:53:56 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: How does @LAST_MATCH_START work?
Message-Id: <slrnbfofj4.el.abigail@alexandra.abigail.nl>
Johannes Fürnkranz (johannes.fuernkranz@t-online.de) wrote on MMMDLXXXVII
September MCMXCIII in <URL:news:bdhadp$jjn$04$1@news.t-online.com>:
&&
&& Wow. I had never seen @- and @+ before. Are these new in 5.8?
No, they are new in 5.6.0.
&& Perl in a
&& Nutshell (2nd ed for 5.8) does not seem to carry them either, however.
I guess that says more about that book than about @- and @+.
Abigail
--
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";
------------------------------
Date: Fri, 27 Jun 2003 15:17:18 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: how to convert all invalid UTF-8 sequences to numeric equivalent?
Message-Id: <Pine.LNX.4.53.0306271512070.11164@lxplus076.cern.ch>
On Thu, Jun 26, Alan J. Flavell inscribed on the eternal scroll:
> > You're sort of correct. I am believing what I'm being told. After
> > checking the converted XML against the Xerces parser, it reports
> > errors as "invalid utf-8 sequence".
>
> You must have either told it, or at least implied, that it was to
> expect utf-8 on input.
If you're still reading this thread:
http://xml.apache.org/xerces-c/faq-parse.html#faq-20
| I keep getting an error: "invalid UTF-8 character". What's wrong?
Sounds rather applicable, doesn't it?
> > When I look at the character it's
> > referring to, it's something along the lines of £.
>
> As I said, you're not correctly describing the input that you're
> giving it.
The FAQ says:
Most commonly, the XML encoding = declaration is either incorrect or
missing. Without a declaration, XML defaults to the use utf-8
character encoding, which is not compatible with the default text
file encoding on most systems.
The XML declaration should look something like this:
<?xml version="1.0" encoding="iso-8859-1"?>
Make sure to specify the encoding that is actually used by file. The
encoding for "plain" text files depends both on the operating system
and the locale (country and language) in use.
Clear?
> > It has everything to do with Perl since I'm using Perl to convert the
> > text files to XML.
Didn't I say that it wasn't Perl-related? _Now_ would you believe me?
FAQs are good for you: take some frequently, and especially when
the symptoms occur. (SCNR).
have fun.
------------------------------
Date: Fri, 27 Jun 2003 10:05:10 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: HTML::TableExtract Simple question
Message-Id: <3efc16af.348653140@news.cis.dfn.de>
On Thu, 26 Jun 2003 17:18:42 -0500, tadmc@augustmail.com (Tad
McClellan) wrote:
>> Then I jsut
>
>(gulp)
Don't panic yet, Tad. It "may" just be a
coincidence.
Let's hope it is.
------------------------------
Date: 27 Jun 2003 07:54:02 -0700
From: sherman.willden@hp.com (Sherman Willden)
Subject: Re: Installing CtCmd on Windows
Message-Id: <3a80d8d6.0306270654.4247dac9@posting.google.com>
Thanks for everyone's replys. I now know where to start looking. I do
have Visual Studio installed and have scripted all the builds for
VC++, VB, etc. We just set up ClearCase client on my machine.
Sherman
------------------------------
Date: Fri, 27 Jun 2003 14:13:52 GMT
From: Allen Wooden <allen.wooden@educate.invalid>
Subject: Re: need assistance understanding multilevel hashes.
Message-Id: <09gofvc3irntir4uuqr34ou0k7lmmi39m7@4ax.com>
On Thu, 26 Jun 2003 22:18:31 GMT, tiltonj@erols.com (Jay Tilton)
wrote:
>
>Some clarification is needed there. Some example code would help.
>
The program is a report front-end to RRDTOOL which takes the customer
name as one of the command line args, the second being the date range
(MM-YYYY) and pulls the 95th % for that customer's port and prints out
a nice little summary of the utilization.
The config file looks like this: (i'll only show one customer for sake
of brevity, the others are similar.
Sorry if the wrapped lines make things difficult to follow.
configfile:
%customer1 = ( "ports" => "2", "rrd0" =>
'/usr/local/mrtg/rrdfiles/10.15.0.19.1.rrd', "rrd1" =>
'/usr/local/mrtg/rrdfiles/10.15.0.19.3
.rrd', "rrd2" => '/usr/local/mrtg/rrdfiles/10.15.0.7.1.rrd', "rrd3" =>
'/usr/local/mrtg/rrdfiles/10.15.0.7.3.rrd', "rate" => "450000
00", "page_num" => "2", "tag" => 'Customer1' );
At runtime, the user would enter.. ./prog ( -h (usage display)) or
./prog customer1 MM-YYYY
I'll include all the code, it is real messy and probably does stupid
redundant things.
#!/usr/local/bin/perl -w
## Script to run Monthly reports.
## Copyright 2003 Allen Wooden.
## awooden@pair.com
## $Id: report.pl,v 1.6 2003/06/19 14:53:15 awooden Exp $
use strict;
use diagnostics;
use Time::Local;
use Date::Calc qw(:all);
use Getopt::Std;
use lib qw(/usr/local/rrdtool/lib/perl);
use RRDs;
use CGI qw(:standard :html3 -no_xhtml -newstyle_urls );
use CGI::Carp qw( fatalsToBrowser);
#Initialize our vars.
my
($current_year,$current_month,$current_day,$help,$d,$m,$y,$custid,$day_to_begin,$day_to_end,$month,$epoch_month,$epoch_feed_start,$epoch_feed_end);
## declare the hashes, these will get assigned from bandwidth.cfg.
our ($opt_h,%customer1, %customer2);
my ($i,@b,$p,@v,$hash_count,%tmp_hash,%custid,%hash);
## Load up the config file's contents
do '/usr/local/apache/cgi-bin/bandwidth.cfg';
## How many hashes are in bandwidth.cfg subtracting 1 for the DMZ
Aggregate stats.
## Get a list of the hash names
open(FILE, "< /usr/local/apache/cgi-bin/bandwidth\.cfg") or die
"Cannot open file: $!";
@v = grep(/\%/,<FILE>);
close FILE;
$hash_count = (grep /^\%(?!dmzagg)/, @v);
print "$hash_count\n";
for ($i=0;$i <= $#v; $i++) {
push(@b,grep(/^\%(?!dmzagg)/,split(/\ \=\ /, $v[$i])));
}
foreach $p (@b) {
print "$p\n";
}
## Look at the flags and check for proper usage...
##
getopts('h');
sub help {
$help = <<_EOF;
Usage: $0 {-h} [entity] [date]
-h This help screen.
entity This is the customer name. ie: customer1.
date The month to report on. MM-YYYY.
Example: $0 customer1 05-2003
_EOF
print "$help\n";
exit 1;
}
if ( ! defined(@ARGV) || ($opt_h)){
# print "Usage: $0 \{\-h} entity_name\(s\) \[date\]\n";
print "$help\n";
help;
}
## Checking entity for an existing customer
if ( $ARGV[0] !~ /^customer1$|^customer2$/ ) {
print "Invalid entity specified. Exiting...\n";
exit 1;
}
## Checking for valid date.
($m,$y) = split(/\-/, $ARGV[1]);
if ( ! check_date($y,$m,1)){ print "Invalid date specified.
Exiting...\n";exit 1;}
## Today's date in case we ever need it.
($current_year, $current_day, $current_month) = Today();
$month = Month_to_Text($m);
## Mangle the entered date into epoch seconds..
$day_to_begin = 1; # Beginning of Month
$day_to_end = Days_in_Month($y,$m); # Last day of Month
$epoch_month = $m;
$epoch_feed_start = timelocal (0,0,0,$day_to_begin,$epoch_month-1,$y);
#Use epoch_month-1 to bring in line with months starting at 0
$epoch_feed_end = timelocal (0,55,23,$day_to_end,$epoch_month-1,$y);
#Same thing for month end.
## Print out a brief blurb showing the report range.
#print "Starting and ending epoch seconds are: $epoch_feed_start \/
$epoch_feed_end \n";
printf "The report range is: %s to %s\n", scalar localtime
$epoch_feed_start, scalar localtime $epoch_feed_end;
## Assign the Correct hash.
$custid = $ARGV[0];
## Loop over and determine the correct hash to use according to the
args passed.
#%custid =~ grep(/\%$custid/,@v);
foreach my $t ( 'customer1', 'customer2' ) {
if ( $custid =~ /^customer1$/ ){ %custid = %customer1r; last;}
if ( $custid =~ /^customer2$/ ) { %custid = %customer2; last;}
}
## Function which calcs 95th.
## Stripped from bandwidth.pl
## 95% sub here.
sub n_th {
##
## Some of get95 are used here.
#
# Version 1.0.2
# by Jon Rust <jpr@vcnet.com>
# http://www.vcnet.com/~jon/extract95.pl
#
my $rr0 = $_[2];
my $start = $_[0];
my $end = $_[1];
my $p = 1;
my $rr1 = $_[3] if (defined($_[3]));
$p = 2 if (defined($_[3]));
my @n_perc;
my $t = 1;
while ($t le $p) {
my ($data, $names, $step,$xperc);
# grab the last xx days worth of stats
# Test for two rrd files.
if ( $t eq "1" ) {
($start,$step,$names,$data) = RRDs::fetch ("$rr0",
"AVERAGE","-s $start", "-e $end");
} elsif ( $p eq "2" && $_[3]) {
($start,$step,$names,$data) = RRDs::fetch ("$rr1",
"AVERAGE","-s $start", "-e $end");
};
my $ERR = RRDs::error;
die "ERROR with RRDs::fetch: $ERR\n" if $ERR;
my $i = 0;
my (@in,@out);
foreach my $line (@$data) {
#print "Line zero: $$line[0]\n";
#print "Line one: $$line[1]\n";
if ($$line[0] eq 'NaN' && $$line[1] eq 'NaN') {
push @in,0 if defined($$line[0]);
push @out,0 if defined($$line[1]);
} else {
push @in,$$line[0] * 8 if defined($$line[0]);
push @out,$$line[1] * 8 if defined($$line[1]);
};
$i++;
last if ($i == $#$data - 1);
}
# sort in reverse numerical order
sub numerically { $b <=> $a; }
my @sortedIN = sort numerically @in;
my @sortedOUT = sort numerically @out;
my $target = ($#$data + 1) * .05;
$target = sprintf("%d", $target);
$target++;
if ($sortedIN[$target - 1] <= $sortedOUT[$target - 1] ) {
$xperc = $sortedOUT[$target - 1];
} else {
$xperc = $sortedIN[$target - 1];
}
push @n_perc,$xperc;
$t++;
}
return $n_perc[0] unless defined($n_perc[1]);
if ( $n_perc[0] <= $n_perc[1] ) {
return $n_perc[1]
} else {
return $n_perc[0]
}
}
## Now actually do something..
my $data = n_th($epoch_feed_start, $epoch_feed_end, $custid{rrd0},
$custid{rrd1});
my $band = sprintf("%6.3f ", $data/1000000);
my $body = <<_EOT;
Bandwidth Usage Report for $month $day_to_begin to $month $day_to_end
$y
________________________________________________________________________
Customer: $custid{tag} Usage: $band Mbs
________________________________________________________________________
_EOT
#printf "$custid{tag} data rate for $month is %6.3f Mbs\n",
$data/1000000;
print "$body";
>Are you saying the configuration file is executable Perl that defines
>hashes, and the desired hash can only be accessed by its name? E.g.
>
> %Fred = ( spouse => 'Wilma', child => 'Pebbles' );
> %Barney = ( spouse => 'Betty', child => 'Bam Bam');
>
I run the config file using 'do' to pull the hashes in. I found that I
had to use 'our (%customer_names) etc ahead of time in order for those
hashes I pull in to be seen. Seems that those hases go out of scope
and disappear right after I run the config file otherwise. Accessing
it by name is the only way I can see to do this, if there is a better
way by all means let a newbie know.. :)
>Like, say,
>
> $customer_name = 'Fred';
> %customer_data = %$customer_name;
>
Your making a symbolic reference there am I right? I read that that is
not a 'good thing to do'.
>If I've gauged the problem accurately, you're SOL due to a bad design
>decision from the past. Yes, the symbol table could be used as a
>hash-of-hashes,
A bad design decision on my part?
>
> %customer_data = %{ $::{$customer_name} };
>
>but that's just dodging the use of symbolic references without
>addressing the real issue. Don't dork with the symbol table unless
>there's no other way.
ok
>
>You should really want a private namespace--your own hash-of-hashes to
>thrash around in.
>
> %customers = (
> Fred => { spouse => 'Wilma', child => 'Pebbles' },
> Barney => { spouse => 'Betty', child => 'Bam Bam' },
> );
> $customer_name = 'Fred';
> %customer_data = %{ $customers{$customer_name} };
>
This is where I'm having some trouble.
I guess what I'm trying to do is get the config file to drive the
program and allow me not to have to modify the prog whenever I add a
new customer. Instead, all I would like to have to do is add the
customer to the config file and be done with it. Ultimately I'd also
like to throw on a ('-a) flag which would run the 95th for all
customers and output on a single page for the month in question.
>At the very least, sequester the config file in its own package to
>minimize the chances of clobbering symbols in other packages.
>
>The ideal solution would be to divorce code from data completely and
>forever.
Allen
Replace invalid with com to reply via email.
PGP key available @ keyserver.pgp.com
------------------------------
Date: Fri, 27 Jun 2003 15:10:40 +0200
From: =?ISO-8859-1?Q?Johannes_F=FCrnkranz?= <johannes.fuernkranz@t-online.de>
Subject: Re: Nutshell
Message-Id: <bdhfou$73t$06$1@news.t-online.com>
Abigail wrote:
>
> && Perl in a
> && Nutshell (2nd ed for 5.8) does not seem to carry them either, however.
>
> I guess that says more about that book than about @- and @+.
Might be. But I haven't found them in any of my other books either (all
of them are on 5 or higher, but I'm not sure whether they are >= 5.6).
Nutshell is the only one I have which covers 5.8., which is why I
mentioned it here. This was not necessarily meant to be a recommendation.
However, having said this, I found it very useful as a general
reference. It doesn't give you more than a condensed version of perldoc,
but I prefer look-up in well-indexed books. I rarely find things in
perldoc unless I know exactly what I'm looking for.
Juffi
------------------------------
Date: 27 Jun 2003 13:51:47 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Nutshell
Message-Id: <slrnbfoivj.el.abigail@alexandra.abigail.nl>
Johannes Fürnkranz (johannes.fuernkranz@t-online.de) wrote on MMMDLXXXVII
September MCMXCIII in <URL:news:bdhfou$73t$06$1@news.t-online.com>:
~~
~~ Nutshell is the only one I have which covers 5.8., which is why I
~~ mentioned it here. This was not necessarily meant to be a recommendation.
I'll bite. What parts of 5.8, which weren't in 5.6, does it cover?
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: 27 Jun 2003 11:22:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Offer tips, comments on this code (generates html to index image files)
Message-Id: <bdh9dq$rj3$1@mamenchi.zrz.TU-Berlin.DE>
Tina Mueller <usenet@expires082003.tinita.de> wrote in comp.lang.perl.misc:
> Janek Schleicher wrote:
> > You also could leave out something like
> > $_ =~ /.../
> > and
> > push @entries,$_
> > as the short versions
> > /.../
> > and
> > push @entries;
> > would also work
>
> no, push says: "Useless use of push with no values".
> but it would be nice if push() worked like shift()
> without arguments.
Ah, but push() and shift() don't correspond to each other, push() and
unshift() do. Unshift() behaves like push() in that it requires two
arguments. Of course, the second argument must be there only formally,
it is allowed to be an empty list.
> i think i never tried that out before,
> and now i was surprised that it didn't work =)
> (would be even more perlish if you could say "push;"
> instead of "push @_, $_;")
Perl doesn't use @_ as a default parameter nearly as much as it
uses $_. AFAIK only shift() and pop() do, plus one particular call
of split() which is deprecated. This is probably because $_ is really
a no-mans-variable while @_ is part of Perl's parameter passing
mechanism.
Anno
------------------------------
Date: Fri, 27 Jun 2003 14:19:35 GMT
From: "John" <SeeMessageBody@nospam.com>
Subject: Thank you all! Tk doesn't look hard to learn.
Message-Id: <XnYKa.14861$C83.1416111@newsread1.prod.itd.earthlink.net>
John:
> > fill-in forms, etc.). Or am I missing something?
"Alan C.":
> perldoc tk
Yep, I sure *was* missing something! :^)
> widget
Cool. Tk has kind of a funky look and feel, like a Java GUI, but it'll do.
I may be looking for a book on Tk soon.
------------------------------
Date: Fri, 27 Jun 2003 12:59:07 GMT
From: Russ Jones <russ.jones2@boeing.com>
Subject: UNIX Domain sockets on HPUX
Message-Id: <Xns93A7513BAAF9Brussjones2boeingcom@192.54.3.19>
I'm trying to use UNIX Domain sockets on HPUX 11.11, using Perl 5.6.1 for
PA-RISC2.0, the IO::Socket module, without much luck.
I've tried the code in Perl Cookbook, and many modifications. Here's my
code:
#!/usr/bin/perl
use IO::Socket;
use strict;
use warnings;
unlink "/tmp/mysock";
our $server = IO::Socket::UNIX->new(LocalAddr => "/tmp/mysock",
Type => SOCK_DGRAM,
Listen => 5)
or die $!;
while (my $client = $server->accept())
{
while (defined (my $buf = <$client>))
{
print "$buf\n";
}
}
close ($server);
exit(0);
When I run it, the ->new() call appears to work. No error codes and the
debugger reports that $server is a socket. The /tmp/mysock file doesn't
get created, though.
Then the while($client = ... ) just falls through. It doesn't wait for
the socket to say anything, it just skips to the close() statement and
exits.
I've done this with INET sockets a number of times with no problems, but
this is the first time I've tried UNIX sockets.
I wonder if it might be a HPUX issue. If anyone has any ideas, I'd
appreciate hearing about them.
Thanks
Russ Jones
------------------------------
Date: 27 Jun 2003 10:09:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Using local $/
Message-Id: <bdh551$n5m$1@mamenchi.zrz.TU-Berlin.DE>
derek / nul <abuse@sgrail.org> wrote in comp.lang.perl.misc:
> On 27 Jun 2003 09:04:12 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
> wrote:
>
> >derek / nul <abuse@sgrail.org> wrote in comp.lang.perl.misc:
> >> I am using the local $/ so that I can get the whole of a binary file into a
> >> variable.
> >
> >Speaking of "the local $/" seems to indicate a misunderstanding. There
> >is no local $/ as opposed to the global one. "local" gives the *same*
> >variable $/ a temporary value, where "temporary" means "valid until the
> >end of the current block, at which point it will be reset to the previous
> >value".
>
> I was misunderstanding its use,
> I assume it normally contains 'cr lf'?
By default $/ contains the string that indicates end-of-line. Its exact
content depends on your OS.
> as this is how the while operator gets a
> line at a time?
More misunderstanding. The while operator is a loop construct and has
nothing to do with reading from a file. Its behavior is independent
of the content of $/.
It is the so-called diamond operator <...> that does the IO, and *its*
behavior depends heavily on the content of $/.
Anno
------------------------------
Date: Fri, 27 Jun 2003 08:50:43 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Using local $/
Message-Id: <slrnbfoitj.2rt.tadmc@magna.augustmail.com>
derek / nul <abuse@sgrail.org> wrote:
> On 27 Jun 2003 09:04:12 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
> wrote:
>
>>derek / nul <abuse@sgrail.org> wrote in comp.lang.perl.misc:
>>> I am using the local $/
> I assume it normally contains 'cr lf'? as this is how the while operator gets a
> line at a time?
It is a variable.
You can print variables you know. :-)
See for yourself what it is before you local() it:
print "the value of \$/ is [$/]\n";
Or, even better, read the docs for it:
perldoc perlvar
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 27 Jun 2003 06:41:05 -0700
From: jimmy_mcnamara@hotmail.com (Jimmy)
Subject: Using perl/shell scripts to kill processes more than x days old
Message-Id: <e08ac7c8.0306270541.55c20f09@posting.google.com>
Hi Folks,
OS : Solaris 8
I have a question regarding killing processes on a unix server. I
would like to run a cron job to kill processes run by certain binaries
that are more than 2 weeks old. I had a look at using the awk combined
with the output of ps but this doesn'tgive me what I want as the
output of ps is limited in what
it outputs as a start date of the process. Has anyone used perl or
shell scripting to come up with a nice way of doing this.
Regards,
Jimmy
------------------------------
Date: Fri, 27 Jun 2003 16:11:13 +0200
From: "Stefan" <someone@somewhere.nl>
Subject: Re: Using perl/shell scripts to kill processes more than x days old
Message-Id: <3efc5018$0$122$e4fe514c@dreader4.news.xs4all.nl>
"Jimmy" <jimmy_mcnamara@hotmail.com> schreef in bericht
news:e08ac7c8.0306270541.55c20f09@posting.google.com...
> Hi Folks,
>
> OS : Solaris 8
>
> I have a question regarding killing processes on a unix server. I
> would like to run a cron job to kill processes run by certain binaries
> that are more than 2 weeks old. I had a look at using the awk combined
> with the output of ps but this doesn'tgive me what I want as the
> output of ps is limited in what
> it outputs as a start date of the process. Has anyone used perl or
> shell scripting to come up with a nice way of doing this.
>
> Regards,
>
> Jimmy
The ps-command still is the best way to get the information you want. You
can select alternative fields using the -o switch. If you execute and parse
the following command;
ps -A -o pid,user,etime,comm
you only need to convert/check the delta elapsed-time [[d-]hh:]mm:ss (etime)
and limit on user and/or binaries (comm). I suspect the ps/awk or ps/ksh or
ps/perl part won't be a problem.
Good luck,
Stefan
------------------------------
Date: 27 Jun 2003 14:29:53 GMT
From: "Chris F.A. Johnson" <c.f.a.johnson@rogers.com>
Subject: Re: Using perl/shell scripts to kill processes more than x days old
Message-Id: <bdhkd1$svhn7$1@ID-136730.news.dfncis.de>
On Fri, 27 Jun 2003 at 13:41 GMT, Jimmy wrote:
> Hi Folks,
>
> OS : Solaris 8
>
> I have a question regarding killing processes on a unix server. I
> would like to run a cron job to kill processes run by certain
> binaries that are more than 2 weeks old. I had a look at using the
> awk combined with the output of ps but this doesn'tgive me what I
> want as the output of ps is limited in what it outputs as a start
> date of the process. Has anyone used perl or shell scripting to come
> up with a nice way of doing this.
In what way is the output limited? On Solaris 8, the STIME field
gives "The starting time of the process, given in hours, minutes,
and seconds. (A process begun more than twenty-four hours before
the ps inquiry is executed is given in months and days.)"
Why isn't the date in months and days adequate?
The Solaris 8 version of ps has the -o<format> option which makes
parsing the output easy.
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2003, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
------------------------------
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 5145
***************************************