[22959] in Perl-Users-Digest
Perl-Users Digest, Issue: 5179 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 4 11:06:23 2003
Date: Fri, 4 Jul 2003 08:05:09 -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, 4 Jul 2003 Volume: 10 Number: 5179
Today's topics:
Re: "Word too long" ? And exactly WHAT word might that news@roaima.freeserve.co.uk
Re: Alternative to use vars <REMOVEsdnCAPS@comcast.net>
Re: Alternative to use vars <REMOVEsdnCAPS@comcast.net>
Re: Alternative to use vars <rev_1318@hotmail.com>
Re: Alternative to use vars <bik.mido@tiscalinet.it>
Re: Automatic page forwarding in cgi perl script (Helgi Briem)
Re: Call parent method indirectly <REMOVEsdnCAPS@comcast.net>
Re: Call parent method indirectly <ubl@schaffhausen.de>
Confused with array and references <kasp@epatra.com>
Re: Confused with array and references <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Confused with array and references <thens@nospam.com>
Displaying a picture until program has completely loade (Math55)
Re: fork, childs, zombies, start a process in the backg (Rex Gustavus Adolphus)
Re: From floating point to fraction (Gilgames)
Re: From floating point to fraction <nospam-abuse@ilyaz.org>
Re: From floating point to fraction <Wolfgang_.fischer@freenet.de>
Re: Getting the size of files from a list? (Math55)
IP regex? (Gareth Glaccum)
Re: IP regex? <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: IP regex? <abigail@abigail.nl>
Non-Blocking read from pipe (Gareth Glaccum)
Re: Perl for Win32 (Gilgames)
Re: Please explain this .sig... [was: "Re: Is there a g <bik.mido@tiscalinet.it>
Re: Reading JPEG file <zvone.zagar@siol.net>
Re: Reading JPEG file <asu1@c-o-r-n-e-l-l.edu>
Re: renaming badly named files... <jurgenex@hotmail.com>
STDIO problem (Jan)
Re: using 'DB_File' versus just plain tie() ? <bik.mido@tiscalinet.it>
Re: Win32 hidden Perl program <andrew_harton@agilent.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 4 Jul 2003 14:28:48 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: "Word too long" ? And exactly WHAT word might that be? Curious
Message-Id: <g1cgt-klk.ln1@moldev.cmagroup.co.uk>
Steve Grazzini <grazz@pobox.com> wrote:
> The shell never looks at the shebang -- that's handled by
> the kernel during execve().
For newer shells, yes, that's true. However, on older systems there was
a notorious csh problem that meant /bin/sh scripts had to start with a
colon as the only character on the first line, otherwise it would assume
it had a csh script. Gack.
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: Fri, 04 Jul 2003 06:46:46 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Alternative to use vars
Message-Id: <Xns93AE4F10B2B99sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
gbacon@hiwaay.net (Greg Bacon) wrote in
news:vg88n1d6cso44d@corp.supernews.com:
> You can use our's lexical scope to cross package boundaries, as this
> example (ibid.) shows:
>
> package Foo;
> our $bar; # declares $Foo::bar for rest of lexical scope
> $bar = 20;
>
> package Bar;
> print $bar; # prints 20
See now, that seems more confusing than beneficial.
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPwVpCmPeouIeTNHoEQK/2QCfQY6ia36pCq18hP9RTGloP9HjUqMAoLyu
Ah76aA1fgi2WU2lq/yMNXlvs
=rGnU
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 04 Jul 2003 06:47:31 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Alternative to use vars
Message-Id: <Xns93AE4F30E1929sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in
news:be10p4$m6m$1@nets3.rz.RWTH-Aachen.DE:
> Also sprach Eric J. Roode:
>
>> Maybe I'm dense.... I have yet to grasp the advantage of 'our' over
>> 'use vars'.
>
> You are not the only one trying to grasp that.
Oh good, I'm glad I'm not the only one :-)
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPwVpNmPeouIeTNHoEQJ6IQCfcwah2/v88iJeVY4dBWyVwQ3U19IAnjLb
I14yeyTv7IGNWZSHaQ20cvAb
=Le5p
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 04 Jul 2003 15:01:33 +0200
From: "Paul van Eldijk" <rev_1318@hotmail.com>
Subject: Re: Alternative to use vars
Message-Id: <pan.2003.07.04.13.01.33.573943@hotmail.com>
On Fri, 04 Jul 2003 08:29:58 +0000 Bart Lateur wrote:
> Martien Verbruggen wrote:
>
>>> You are not the only one trying to grasp that. The concept of lexically
>>> scoped global (that is, dynamic) variables truely escapes me. The only
>>> advantage I see is that you can introduce new global variables
>>> everywhere easily like so:
>>
>>You can limit (with our) where that global variable is accessible:
>
> The part that makes no sense to me, is how use of these var now crosses
> package boundaries...
>
> $Bar::x = 123;
> package Foo;
> our $x = "abc";
> package Bar;
> print $x;
>
> Guess what that'll print?
However, if you change it to
$Bar::x = 123;
package Foo;
use vars qw($x);
$x = "abc";
package Bar;
print $x;
you get the expected result. I guess I´m confued too....
Paul
--
$_=q{ ^4;c;14;1b:a^5;16:c^17:e^a;11;19:h^9;15:j^0:k^18:l^13
:n^6:o^7:p^10:r^b;12;1a:s^2:t^3;8:u^1};s{(?<=[;^])(\d)?([\d
abc])}{$a=$1;$2=~/([abc])/?$a*13+ord($1)%87:$1*13+$2}egx;
for(split/:/){($a,@_)=split/[;^]/;@@[@_]=($a)x@_}print@@
------------------------------
Date: Fri, 04 Jul 2003 16:16:14 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Alternative to use vars
Message-Id: <hb1bgvskod982autngrkfmi5q8hf5r68ps@4ax.com>
On 04 Jul 2003 00:04:39 GMT, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
>C<use vars> is still deprecated, so it's probably better (unless you
>have to write code for 5.005) to not use it anymore.
FWIM in my experience it helped me a lot to understand C<our> to see
how I could use it with -n (or -p) and strict:
perl -Mstrict -wlne 'our $c++ if /\bfoo$/; END{print $c}' file
However, while the "less typing" issue has been discussed here,
another aspect has not been touched yet: the psychological/aesthetical
one.
Referring to the example above , it wouldn't have been bad to
'use vars qw/$c/;' instead, since one, after some practicing with
perl, has the *feeling* that C<use> has to do with something that is
done *before* anything else, say, at C<BEGIN>.
However IMHO, C<use vars>, somehow smells like a "dirty trick", while
C<our> is better integrated with the language syntax. Of course when
it comes to software maintenance, as mentioned by another poster, it's
another matter!
Michele
--
$\=q.,.,$_=q.print' ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;
------------------------------
Date: Fri, 04 Jul 2003 12:45:57 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Automatic page forwarding in cgi perl script
Message-Id: <3f0576e3.963110921@news.cis.dfn.de>
On 3 Jul 2003 13:56:10 -0700, maximuszen@optonline.net (Max) wrote:
>I found out the problem. The
>
>print "Location: http://localhost/dir/dir/file";
You have been warned many times about
top-posting. Enough is enough.
<plonk>
------------------------------
Date: Fri, 04 Jul 2003 06:54:46 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Call parent method indirectly
Message-Id: <Xns93AE506BECFD9sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Bart Lateur <bart.lateur@pandora.be> wrote in
news:0dfagvkdarvcrtfs0ht14d5h4q1akjjjae@4ax.com:
> Steve Grazzini wrote:
>
>>You can also do:
>>
>> $self->can("SUPER::$method")->(@args);
>
> You forgot to pass along the object itself.
>
> $self->can("SUPER::$method")->($self, @args);
I had no idea that can() returned a function pointer. I thought it was
just a boolean (1 or '').
I should know by now that when Perl has the option of returning something
*useful* as a true value, it does! Thanks, Steve and Bart.
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPwVq5WPeouIeTNHoEQK8owCg2QWpwfR5qSDTwNCt8FlM0TDSjfAAoI3B
Vv7y8R1WvlGgqC01osoFHij8
=BUwY
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 04 Jul 2003 16:09:08 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Call parent method indirectly
Message-Id: <be44ub$gmn$1@news.dtag.de>
Bart Lateur wrote:
> Steve Grazzini wrote:
>
>
>>You can also do:
>>
>> $self->can("SUPER::$method")->(@args);
>
>
> You forgot to pass along the object itself.
>
> $self->can("SUPER::$method")->($self, @args);
Not that many people would care, but this is not thread safe!
The return value of C<can> can change over time, and time passes between:
$self->can("SUPER::$method")
and:
->($self, @args);
No biggie, if you are not messing with @ISA at runtime or put code
references in it:
push @ISA, sub { rand > 0.5 ? "Hello::World" : "Destroy::HD" }
bye
malte
------------------------------
Date: Fri, 4 Jul 2003 14:37:33 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Confused with array and references
Message-Id: <be3qka$l1u$1@newsreader.mailgate.org>
Hi,
I am toying around with references and have some questions.
See this test script below...
use strict;
use warnings;
my $x = (5,6,7);
print "$x\n";
my $arrayRef = [1,2,3,['d','g','z']];
print "$arrayRef->[3][1]\n";
my $arrayRef2 = [1,2,3,('d','g','z')];
print "$arrayRef2->[3]\n";
The output is :
$ perl ref.pl
Useless use of a constant in void context at ref.pl line 4.
Useless use of a constant in void context at ref.pl line 4.
7
g
d
Now these are some doubts I have:
1. (5,6,7) represents an array, while [5,6,7] represents an array reference.
Am I right?
2. The warning that I get : "Useless use of a constant in void context at
ref.pl line 4." is beacuase I am assigning the array (5,6,7) to $x - a
sscalar. The two warning messages are coming as 5 and 6 are being used
unnecessarily. An assignment of scalar to an array will assign the last
element of the array to the scalar ie 7 in this case.
3. In my $arrayRef2 = [1,2,3,('d','g','z')];.........how can I print 'g' ?
Thanks.
-
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.
------------------------------
Date: Fri, 4 Jul 2003 12:14:51 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Confused with array and references
Message-Id: <Xns93AE907C9C1B8elhber1lidotechnet@62.89.127.66>
Kasp wrote:
> Hi,
> I am toying around with references and have some questions.
> See this test script below...
>
> use strict;
> use warnings;
Good. :-)
> my $x = (5,6,7);
> print "$x\n";
> my $arrayRef = [1,2,3,['d','g','z']];
> print "$arrayRef->[3][1]\n";
> my $arrayRef2 = [1,2,3,('d','g','z')];
> print "$arrayRef2->[3]\n";
>
> The output is :
> $ perl ref.pl
> Useless use of a constant in void context at ref.pl line 4.
> Useless use of a constant in void context at ref.pl line 4.
> 7
> g
> d
>
> Now these are some doubts I have:
> 1. (5,6,7) represents an array, while [5,6,7] represents an array
> reference. Am I right?
No. (5, 6, 7) is a list, not an array. See the FAQ for the difference.
[5, 6, 7] is indeed a reference to an array.
> 2. The warning that I get : "Useless use of a constant in void context
> at ref.pl line 4." is beacuase I am assigning the array (5,6,7) to $x
> - a sscalar. The two warning messages are coming as 5 and 6 are being
> used unnecessarily. An assignment of scalar to an array will assign
> the last element of the array to the scalar ie 7 in this case.
You are not assigning an array to a scalar. You are interpreting a list
in scalar context, the result of which is the last element of the list
being assigned to $x. Your interpretation of the amount of warnings is
correct.
> 3. In my $arrayRef2 = [1,2,3,('d','g','z')];.........how can I print
> 'g' ?
print 'g'; # :-)
But seriously, folks:
print $arrayRef2->[4];
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Fri, 4 Jul 2003 18:02:29 +0530
From: Thens <thens@nospam.com>
Subject: Re: Confused with array and references
Message-Id: <20030704180229.4392d661.thens@nospam.com>
On Fri, 4 Jul 2003 14:37:33 +0530
"Kasp" <kasp@epatra.com> wrote:
>Hi,
>I am toying around with references and have some questions.
>See this test script below...
>
>use strict;
>use warnings;
>my $arrayRef2 = [1,2,3,('d','g','z')];
>print "$arrayRef2->[3]\n";
>d
>3. In my $arrayRef2 = [1,2,3,('d','g','z')];.........how can I print 'g' ?
In your assignment
>my $arrayRef2 = [1,2,3,('d','g','z')];
the list ('d', 'g', 'z') will get flattened out and the assignment is same as
my $arrayRef2 = [ 1, 2, 3, 'd', 'g', 'z' ];
So to print 'g' you will have to find the index and print it ;-)
see
perldoc perldata - for more details on arrays, lists, hashes
perldoc perlred - on references
Regards,
Thens
------------------------------
Date: 4 Jul 2003 07:59:20 -0700
From: magelord@t-online.de (Math55)
Subject: Displaying a picture until program has completely loaded?
Message-Id: <a2b8188a.0307040659.1be9b60b@posting.google.com>
hi, i want to display the little swirling line. thats the code:
$zaehler;
my $i;
while($i<25){
print ".";
print("|");
$zaehler=0.0;
while($zaehler<100000.0){
$zaehler++;
}
print("\b");
print("/");
$zaehler=0.0;
while($zaehler<100000.0){
$zaehler++;
}
print("\b");
print("-"); $zaehler=0.0;
while($zaehler<100000.0){
$zaehler++;
}
print("\b");
print("\\");
$zaehler=0.0;
while($zaehler<100000.0){
$zaehler++;
}
print("\b");
$i++;
}
but how long? how do i know my program is ready to start?
THANK YOU!!:)
------------------------------
Date: 4 Jul 2003 03:12:11 -0700
From: uffesterner@spamhole.com (Rex Gustavus Adolphus)
Subject: Re: fork, childs, zombies, start a process in the background without waiting for it
Message-Id: <c70a85ff.0307040212.67689e89@posting.google.com>
uffesterner@spamhole.com (Rex Gustavus Adolphus) wrote:
> I think I found the solution in PerlFAQ 8.12: "double fork"
> (I must admit I thougt my previous method was "double fork" but I now
> realize it isn't):
> You immediately wait() for your first child, and the init daemon will
> wait() for your grandchild once it exits.
>
> unless ($pid = fork) {
> unless (fork) {
> exec "what you really wanna do";
> die "exec failed!";
> }
> exit 0;
> }
> waitpid($pid,0);
>
>
Hi, back again...
Now I tried double forking, and that seems to work in simple
testscripts,
but when I used it in my real app, witch involves DBI to connect
to an Oracle-database, my grandparent loses the db-connection as soon
as the grandparent spawns kids and grandkids (the grandkids connects
to the same database, but I'm not sending any db-handles to the kids
or anything like that).
(I have not yet been able to figure out at what exact moment the
grandparent loses it's db-connection)
I quote from "Programming Perl": "File descriptors ... are shared,
while everything else is copied--or at least made to look that way."
What does this mean?
If I have:
my $dbh = ${&db_connect()};
in the forking program
is $dbh copied to the kids and therefore dropped when the kids dies?
Anyway, now I'm trying this method instead, it seems to work:
# found something to do:
system("what I really wanna do &"); # NB the '&' at the end
# I can keep on immediately, because of the '&' above
# doing more system-calls if needed
Simple!
No forking, no waiting, no zombies, no hassles!
Why didn't I do this from the beginning?
Is there any disadvantage?
Anything I'm missing?
/RGA
------------------------------
Date: 04 Jul 2003 10:56:56 GMT
From: gilgames@aol.coma (Gilgames)
Subject: Re: From floating point to fraction
Message-Id: <20030704065656.11516.00000079@mb-m10.aol.com>
<<
> I'd like to, from inside my Perl script, go from a floating point number,
Sort of depends on what you mean. Does the numerator always have to be "1" ?
If not, how do you determine in advance the number it should be set to ?
>>
The computers are fast, don't think, let them work, try it. The result for the
second decimal is 314/375 with 6 digit accuracy
my $x = "0.33333333333333333";
my $x2 = "0.83733333333333333";
my $y = frac($x);
my $y2 = frac($x2);
println $y;
println $y2;
sub frac {
my $limit = 1000000;
my $x = shift;
my $i = 1;
while (1) {
my $y = fracti($x, $i);
if (abs(eval($y) - $x) < 1/$limit/2)
{return $y;}
$i++;
if ($i > $limit) {return "No result below 1000000 as numerator"};
}
}
sub fracti {
my $whole = int($_[1] / $_[0] + 0.5);
return "$_[1]/". $whole;
}
------------------------------
Date: Fri, 4 Jul 2003 12:31:49 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: From floating point to fraction
Message-Id: <be3s3l$pc7$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
jon rogers
<jon.rogers@tv.tu>], who wrote in article <be3h74$3tj$1@news.gu.se>:
> I'd like to, from inside my Perl script, go from a floating point number,
> like 0.33333333333333333, to a fraction, in this case 1/3. Is that
> possible? And if so, how?
[Untested]:
perl -MMath::Pari=algdep,polcoeff -wle 'sub fract($){my $p = algdep shift, 1, 10; -polcoeff($p,0)/polcoeff($p,1)} print fract shift' 0.333333333333333333333
Change 10 to a number to suit your needs; the docs (perldoc
Math::libPARI) give:
algdep(x,n,{flag=0}): algebraic relations up to degree n of x. flag
is optional, and can be 0: default, uses the algorithm of Hastad et
al, or non-zero, and in that case is a number of decimal digits which
should be between 0.5 and 1.0 times the number of decimal digits of
accuracy of x, and uses a standard LLL.
Hope this helps,
Ilya
------------------------------
Date: Fri, 04 Jul 2003 16:14:09 +0200
From: Wolfgang Fischer <Wolfgang_.fischer@freenet.de>
Subject: Re: From floating point to fraction
Message-Id: <pan.2003.07.04.14.14.06.737194@freenet.de>
On Fri, 04 Jul 2003 11:37:39 +0200, jon rogers wrote:
> Hi
>
> I'd like to, from inside my Perl script, go from a floating point number,
> like 0.33333333333333333, to a fraction, in this case 1/3. Is that
> possible? And if so, how?
>
> / JR
perl -p -e '$_=sprintf("%6f",$_);my($a,$b)=/(\d*)\.(\d*)/;$_=($a*"9"x length($b))+$b."/"."9" x length($b)."\n";'
------------------------------
Date: 4 Jul 2003 03:14:38 -0700
From: magelord@t-online.de (Math55)
Subject: Re: Getting the size of files from a list?
Message-Id: <a2b8188a.0307040214.3ff633c4@posting.google.com>
gbacon@hiwaay.net (Greg Bacon) wrote in message news:<vg8iancknatk3c@corp.supernews.com>...
> In article <a2b8188a.0307030543.19cea0e7@posting.google.com>,
> Math55 <magelord@t-online.de> wrote:
>
> : how can i get the size from the 9 files in /var/log/ksymoops and how
> : the size of the 8 files in /var/log? the list is noct always the same,
> : it can have more or less directories. i tried it like that so far:
>
> Here's my implementation:
>
> #! /usr/local/bin/perl
>
> use strict;
> use warnings;
>
> use File::Basename;
>
> sub to_bytes {
> my $size = shift;
>
> if ($size =~ s/k$//) {
> $size *= 1024;
> }
> elsif ($size =~ s/M$//) {
> $size *= 1024 * 1024;
> }
>
> $size;
> }
>
> sub to_unit {
> my $size = shift;
>
> if ($size > 1024 * 1024) {
> $size = sprintf "%.1fM", $size / (1024*1024);
> }
> elsif ($size > 1024) {
> $size = sprintf "%.1fk", $size / 1024;
> }
>
> $size;
> }
>
> ## main
> my %size;
> my @files = <DATA>;
>
> for (@files) {
> chomp;
> my($size,$path) = split;
>
> my $bytes = to_bytes $size;
> my $dir = dirname $path;
> $size{$dir} += $bytes;
> }
>
> # pass two: zap subdirs from parents' totals
> for (@files) {
> chomp;
> my($size,$path) = split;
>
> next unless exists $size{$path};
>
> my $dir = dirname $path;
> my $bytes = to_bytes $size;
> $size{$dir} -= $bytes;
> }
>
> for (sort { $a cmp $b } keys %size) {
> print "$_ - ", to_unit($size{$_}), "\n";
> }
>
> __DATA__
> 32k /var/log/XFree86.0.log
> 76k /var/log/auth.log
> 116k /var/log/auth.log.0
> 8.0k /var/log/auth.log.1.gz
> 228k /var/log/kdm.log
> 20k /var/log/kern.log
> 1.2M /var/log/kern.log.0
> 12k /var/log/kern.log.1.gz
> 2.8M /var/log/ksymoops
> 228k /var/log/ksymoops/20030628062520.ksyms
> 4.0k /var/log/ksymoops/20030628062520.modules
> 228k /var/log/ksymoops/20030629062502.ksyms
> 4.0k /var/log/ksymoops/20030629062502.modules
> 12k /var/log/ksymoops/20030630.log
> 228k /var/log/ksymoops/20030630062525.ksyms
> 4.0k /var/log/ksymoops/20030630062525.modules
> 12k /var/log/ksymoops/20030701.log
> 228k /var/log/ksymoops/20030701062504.ksyms
>
> I make two passes. On the first, I sum the sizes, using dirname
> from the File::Basename module to grab the parent directory's name.
> On the second pass, I substract reported directories' sizes from
> their parents' totals (e.g., /var//var/log/ksymoops in this example).
>
> : this is what i want to have:
> :
> : /var/log:1720.8
> : /var/log/ksymoops:3815.2
> :
> : is therea better and less complicated way to do that?
>
> My results are below:
>
> % ./try
> /var/log - 1.7M
> /var/log/ksymoops - 948.0k
>
> Hope this helps,
> Greg
hi, i got this to work. now i can submit an argument and i get the
size of this argument. but there is one little problem. when a
directory has a size near 1mb i get a size like 1020.4 for example.
how can i make this a bit more accurate?
THANKS FOR YOUR EFFORTS:)
------------------------------
Date: 4 Jul 2003 05:23:50 -0700
From: verycoldpenguin@hotmail.com (Gareth Glaccum)
Subject: IP regex?
Message-Id: <991491a9.0307040423.7c9bf2e9@posting.google.com>
>Can anyone help out with a match regular expression for an ip
address?
>I am feeling kinda dopey today.
>^[1,2]*[0-9]{1,2}\.[1,2]*[0-9]{1,2}\.[1,2]*[0-9]{1,2}\.[1,2]*[0-9]{1,2}$
>that restricts it to 0-299, how do I get it to do 1-255
Followup:
Ok, the following seems to work:
^(([0-9]|1*[0-9]{2,2}|2[0-4][0-9]|25[0-5])(\.|$)){4,4}
Any advances on making it nicer?
Test code:
@match=("255","1","","
","123","300","127.0.0.1","2556.34.24.1","129.1241.14.1","129.1234.12","192.168.101.1");
$match='^(([0-9]|1*[0-9]{2,2}|2[0-4][0-9]|25[0-5])(\.|$)){4,4}';
foreach $item (@match){
if($item=~/$match/){
print "$item\tpasses\t$match \n";
}else{ print "$item\tfails\t$match \n";
}}
Gareth
------------------------------
Date: Fri, 4 Jul 2003 12:29:48 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: IP regex?
Message-Id: <Xns93AE9308FAA6Felhber1lidotechnet@62.89.127.66>
Gareth Glaccum wrote:
>>Can anyone help out with a match regular expression for an ip
> address?
>>I am feeling kinda dopey today.
>
>>^[1,2]*[0-9]{1,2}\.[1,2]*[0-9]{1,2}\.[1,2]*[0-9]{1,2}\.[1,2]*[0-9]{1,2}
>>$ that restricts it to 0-299, how do I get it to do 1-255
>
>
> Followup:
> Ok, the following seems to work:
> ^(([0-9]|1*[0-9]{2,2}|2[0-4][0-9]|25[0-5])(\.|$)){4,4}
> Any advances on making it nicer?
How about using m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ and testing $1 - $4 for
compliance? Much cleaner.
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: 04 Jul 2003 12:36:01 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: IP regex?
Message-Id: <slrnbgat5h.ecp.abigail@alexandra.abigail.nl>
Bernard El-Hagin (bernard.el-hagin@DODGE_THISlido-tech.net) wrote on
MMMDXCIV September MCMXCIII in <URL:news:Xns93AE9308FAA6Felhber1lidotechnet@62.89.127.66>:
__ Gareth Glaccum wrote:
__
__ >>Can anyone help out with a match regular expression for an ip
__ > address?
__ >>I am feeling kinda dopey today.
__ >
__ >>^[1,2]*[0-9]{1,2}\.[1,2]*[0-9]{1,2}\.[1,2]*[0-9]{1,2}\.[1,2]*[0-9]{1,2}
__ >>$ that restricts it to 0-299, how do I get it to do 1-255
__ >
__ >
__ > Followup:
__ > Ok, the following seems to work:
__ > ^(([0-9]|1*[0-9]{2,2}|2[0-4][0-9]|25[0-5])(\.|$)){4,4}
__ > Any advances on making it nicer?
__
__
__ How about using m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ and testing $1 - $4 for
__ compliance? Much cleaner.
use Regexp::Common;
/$RE{net}{IPv4}/;
*Much* simpler.
Abigail
--
perl -wlpe '}$_=$.;{' file # Count the number of lines.
------------------------------
Date: 4 Jul 2003 05:25:29 -0700
From: verycoldpenguin@hotmail.com (Gareth Glaccum)
Subject: Non-Blocking read from pipe
Message-Id: <991491a9.0307040425.3e0ae9e9@posting.google.com>
Ok, a couple of weeks ago I asked for how to perform some IPC reads
using threads, found a nice way of doing it.
Now however, due to a recent necassary OS upgrade the reads are
blocking/unusable.
Previously was using $count=read(FH,$var,-1) -1 is no longer valid.
read now blocks if you use any value greater than 0
Any ideas:
$r=read(CHILD,$t,1);
while($r>0){
$line.=$t;
print "a-$r:$t:$line\n";
$r=read(CHILD,$t,1); #This line blocks if there are no
characters. How can I test for this?
print "b-$r:$t:$line\n";
}
Running Perl 5.8.0 on Redhat 9 based, kernel from kernel.org, 2.4.21
SMP on dual Xeon.
Gareth
------------------------------
Date: 04 Jul 2003 11:00:41 GMT
From: gilgames@aol.coma (Gilgames)
Subject: Re: Perl for Win32
Message-Id: <20030704070041.11516.00000080@mb-m10.aol.com>
<<
I am learning Perl, and I have never programed before.
I wrote a script that uses a Network path, but in the network path
thee is a space, and it's not working; this is a sample:
$PVCSDatabase = "\\\\PC\\Vault\\temp\\my folder";
>>
Try to set one more double quote around the address
$var = "\"your path\"";
------------------------------
Date: Fri, 04 Jul 2003 16:16:10 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Please explain this .sig... [was: "Re: Is there a good free/not so expensive Perl IDE for Linux"]
Message-Id: <s3tagvc71kqd5hg1tuhsq68o6en3ruqqcr@4ax.com>
On 02 Jul 2003 21:20:44 GMT, Abigail <abigail@abigail.nl> wrote:
>$$ > perl -wlne '}{print$.' file
>$$
>$$ I guess this has to do with "the code -n puts around" -e's argument...
>
>I share that guess.
But you don't *explain* "this .sig"... and 'perldoc perlrun' doesn't
help either... Oh no! it does!! But then why wasn't it so yesterday?!?
Michele
--
perl -wpe 'last if/^-- $/}while(<>){' file
------------------------------
Date: Fri, 04 Jul 2003 15:22:03 +0200
From: Zvone Zagar <zvone.zagar@siol.net>
Subject: Re: Reading JPEG file
Message-Id: <iafNa.2024$78.139057@news.siol.net>
A. Sinan Unur wrote:
> Zvone Zagar <zvone.zagar@siol.net> wrote in
> news:GdKLa.1908$78.104444@news.siol.net:
>
>> I would like to read a jpg image, get data (decode) out of it and make
>> a postscript file from scratch. I can get width, height, color depth
>> but I don't know how to make a hex string needed for postscript.
>> Postscript line should look like: width height depth matrix {<hex
>> data>} false 3 colorimage.
>
>> Eric J. Roode wrote:
>>
>>> Zvone Zagar <zvone.zagar@siol.net> wrote in
>>> news:l_4La.1859$78.94796@news.siol.net:
>>>
>>>> I have searched for days, but found almost nothing (except some
>>>> excerpts from C code). I hope I made myself clear enough. Any help
>>>> would be appreciated.
>>>
>>> How about Image::Magick, or the GD module?
>>>
>> Thanks for the tip.
>> I have tried Image::Magick. A picture could be saved as PS file.
>> It is not exactly what I want, but it will help me.
>
> ImageMagick can save image data in raw RGB format. Although I have never
> used it, and do not have it installed, I thought pointing that out might
> help.
>
> Sinan.
I appologize for my late answer.
The raw RGB format is unfortunately not the proper one.
At first my lips smiled, but code generated is not PS digested.
I will dig deeper.
Thanks Zvone Zagar
------------------------------
Date: 4 Jul 2003 14:05:31 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Reading JPEG file
Message-Id: <Xns93AE66A93415Basu1cornelledu@132.236.56.8>
Zvone Zagar <zvone.zagar@siol.net> wrote in news:iafNa.2024$78.139057
@news.siol.net:
> A. Sinan Unur wrote:
>
>> Zvone Zagar <zvone.zagar@siol.net> wrote in
>> news:GdKLa.1908$78.104444@news.siol.net:
>>
>>> I would like to read a jpg image, get data (decode) out of it and make
>>> a postscript file from scratch. I can get width, height, color depth
>>> but I don't know how to make a hex string needed for postscript.
>>> Postscript line should look like: width height depth matrix {<hex
>>> data>} false 3 colorimage.
...
>> ImageMagick can save image data in raw RGB format. Although I have
>> never used it, and do not have it installed, I thought pointing that
>> out might help.
>>
>> Sinan.
> I appologize for my late answer.
> The raw RGB format is unfortunately not the proper one.
> At first my lips smiled, but code generated is not PS digested.
> I will dig deeper.
If I understand correctly, you need to get to the raw RGB data somehow (I
have no idea how one embeds jpegs in postscript), and then insert those
data in the document as ascii hexadecimal numbers. Is that the case? If so,
once you get the raw RGB data, you can easily get what you want. So, raw
RGB would not be the solution to your problem, but the first step in a
solution.
I should probably shut up because I am a little fuzzy on what you are
trying to do. If you can post a link to the specification of the output
file format (for your particular case) or maybe just explain it a little,
we might be able to help more.
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Fri, 04 Jul 2003 11:16:58 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: renaming badly named files...
Message-Id: <KmdNa.19358$n%5.14907@nwrddc02.gnilink.net>
[Please do not top post! Jeopardectomy performed]
[Please don't full-quote. Reduced to reasonable excerpt]
Naran Hirani wrote:
> Tim Hammerquist wrote:
>> Naran Hirani graced us by uttering:
>>> I am looking for a perl code fragment, or utility that will
>>> enable me to rename badly named files and/or dir elements to
>>> such files, by replacing the dubious character with an
>>> underscore. [...]
>> You can find the rename.pl utility here:
>> http://borkware.com/quickies/files/rename.pl
[...]
> Thanks for your suggestion. It sounds quite promising to me, but will
> it handle the following scenario:
>
> I/have a badly named sub_dir/with some more badly named files here.txt
>
> I.e. will it deal with sub dirs in the path as well as the final files
> under the sub dirs?
Did you actually check those 7 lines of code in the file? There is no piece
of code that would read a directory/change to a different directory/recurse
over a directory tree, so no, it won't.
> Of course, I am thinking of using rename in conjunction with the unix
> find util.
Why not using Perl Find::Find module?
Note: you should do a depth-first approach. I am not sure if Find::File
still recurses correctly when you change a directory name on it in the
middle of the operation.
jue
------------------------------
Date: 4 Jul 2003 06:46:48 -0700
From: jan_buys@hotmail.com (Jan)
Subject: STDIO problem
Message-Id: <11971c2c.0307040546.700d307b@posting.google.com>
Hi,
I think my perl knowledge must have shrunk to the size of a neutron...
*sigh*.
I'm trying to do some STD I/O on a cmd console from within a script
called by another script. I narrowed down the problem to the smallest
full scripts I could. test.pl is the main script, calling test2.pl in
which the problems with the IO exist.
Code of the 2 scripts :
#!c:\perl\bin\perl.exe # Activeperl 5.6.1 - win32 build 633
# script : test.pl
print `cqperl -w test2.pl`;
#!c:\program files\Rational\clearquest\cqperl.exe
# Cqperl, derived from Activeperl 5.6.0, win32
# script : test2.pl
$| = 1 ;
print "Hello there\n" ;
chomp($answer = <STDIN>);
print "$answer to you too...\n";
The problem is the STDOUT msgs only are flushed to screen once the
input is entered... Meaning I get something like this when running
the script :
C:\Data\scripts\>perl -w test.pl
hi
Hello there
hi to you too...
Thanks for any hint, solution or reference to a must-read perl
manpage,
Jan
------------------------------
Date: Fri, 04 Jul 2003 16:16:11 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: using 'DB_File' versus just plain tie() ?
Message-Id: <po0bgv8acqjkrukgcuo9sdbsf9dno8e3vc@4ax.com>
On 2 Jul 2003 19:47:48 -0700, botfood@yahoo.com (dan baker) wrote:
>> AFAIK, DB_File is portable between machines and even big-endian
>> and little-endian architectures (unlike GDBM or NDBM).
>>
>> You may be running into version bifurcation -- many DB_File
>> modules still use 1.x, and a lot have moved to 2.x/3.x.
>
>huh, I wonder how I can tell if this is the issue? All I know is that
>if I FTP the tied()ed file from the unix host to my pc, the app can't
>read it when run on my localhost... I was hoping there would be a
Despite what you've been told, in my *experience* DB_File databases
are definitely not portable across platforms. Not that I'm a big
expert either, so I asked here, and I got the following answer:
SH>The DB library uses platform specifics in the database. Things like
SH>the endianness of the machine, and the size of ints. That means a
SH>database created on one machine isn't necessarily readable on
SH>another.
[...]
SH>One reason *DBM isn't made cross platform is that the performance
SH>trade off (no longer being able to directly copy data from the file
SH>to memory) isn't considered worth the benefit. After all you can
SH>just read the data and write it out in a transport format (text for
SH>example) and create a *DBM database in on the target machine. Well
SH>I think anyway, not being the designer/author I'm just guessing.
To which another valuable contributor to this ng added:
BL>That's right. You can blame C, which is used to compile the
BL>database engine for that. C tends to use pretty abstract names for
BL>its data types, like int(), which physically are stored in the for
BL>the machine most efficient way, but with no garantees at all about
BL>portability. So all bets on endianness, or number of bits per
BL>integer, are off.
BL>
BL>It is often possible to compile a database engine to use a portable
BL>file format, but with a bad impact on efficiency. Speed could
BL>easily halve.
[Both quotations have been slightly edited for clarity]
Michele
--
$\=q.,.,$_=q.print' ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;
------------------------------
Date: Fri, 4 Jul 2003 15:41:34 +0100
From: "Andrew Harton" <andrew_harton@agilent.com>
Subject: Re: Win32 hidden Perl program
Message-Id: <1057329618.736735@cswreg.cos.agilent.com>
David A wrote:
> I want to write a program in Win32 Perl (ActiveState v5.6) that will
> run as a hidden window (or otherwise in the background on a user's
> machine). Every 5 minutes it will perform some tasks and if certain
> conditions are true I want it to make a non-modal pop-up or balloon
> appear to inform the user (or perhaps fire the user's web browser
> with a given html page on it). Then it will go back to sleep for 5
> minutes. There shouldn't be any icons showing in the toolbar and it
> shouldn't put any heavy load on the user's machine while 'asleep'.
>
> I know how to do this is Win32 C, but can't find anything on it in my
> books or searches on how to do it in Perl.
>
> The two specific things are:-
>
> 1. How to make a perl program run as hidden process on a Win32 machine
> 2. How to make a non-modal pop-up window appear that won't interfere
> with the user's current task.
>
> Any suggestions would be appreciated.
>
> David A.
This'll do almost what you want :
#!/usr/bin/perl
use warnings;
use strict;
use Win32;
while(1)
{
my $test = Win32::MsgBox("Hello World" , 1 , "Box Test");
last if $test == 2;
sleep 300;
}
Check the Win32 section of ActiveState's documentation for more details.
To run it without a console window, you need to run it with wperl.exe,
either
from the Start->Run menu, or through a shortcut.
The only thing is that it does pop up over whatever else you're doing.
Hope that helps.
Andrew
--
$s="acehJklnoPrstu ";$_="4dbce078c32ae92a6e30152a";
split//;for(0..$#_){print substr($s,hex $_[$_],1);}
------------------------------
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 5179
***************************************