[28553] in Perl-Users-Digest
Perl-Users Digest, Issue: 9917 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 1 21:06:00 2006
Date: Wed, 1 Nov 2006 18:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 1 Nov 2006 Volume: 10 Number: 9917
Today's topics:
Re: Abysmal performance of Net::SFTP (and I have GMP & <sisyphus1@nomail.afraid.org>
Re: Abysmal performance of Net::SFTP (and I have GMP & usenet@DavidFilmer.com
Data Query/substitute operation <mislam@spam.uiuc.edu>
Re: Data Query/substitute operation <jgibson@mail.arc.nasa.gov>
Re: Data Query/substitute operation <mislam@spam.uiuc.edu>
Re: Data Query/substitute operation <tadmc@augustmail.com>
Re: Distributing application with modules as a single f <benmorrow@tiscali.co.uk>
Re: Distributing application with modules as a single f anno4000@radom.zrz.tu-berlin.de
Re: FAQ 4.29 How can I count the number of occurrences <benmorrow@tiscali.co.uk>
How to capture repeated subpatterns? <martin+spamfree+larsen@bigfoot.com>
Re: How to capture repeated subpatterns? <wahab@chemie.uni-halle.de>
Re: How to capture repeated subpatterns? <noreply@gunnar.cc>
Re: How to capture repeated subpatterns? <martin+spamfree+larsen@bigfoot.com>
Re: How to capture repeated subpatterns? <tadmc@augustmail.com>
Re: How to capture repeated subpatterns? <martin+spamfree+larsen@bigfoot.com>
Re: How to capture repeated subpatterns? <someone@example.com>
Re: How to capture repeated subpatterns? <wahab@chemie.uni-halle.de>
Information about file systems. dcruncher4@aim.com
Re: killing processes using perl (artsd) <rvtol+news@isolution.nl>
Re: killing processes using perl (artsd) <rvtol+news@isolution.nl>
Re: killing processes using perl (artsd) <tadmc@augustmail.com>
Re: longest common substring xhoster@gmail.com
Re: Putting a line in a specific place in a file <bryan@worldspice.net>
Re: Putting a line in a specific place in a file <veatchla@yahoo.com>
Re: Putting a line in a specific place in a file <tadmc@augustmail.com>
Re: Putting a line in a specific place in a file <someone@example.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 2 Nov 2006 11:34:40 +1100
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Abysmal performance of Net::SFTP (and I have GMP & Pari)
Message-Id: <45493e41$0$22937$afc38c87@news.optusnet.com.au>
<usenet@DavidFilmer.com> wrote in message
news:1162344640.624551.69420@f16g2000cwb.googlegroups.com...
.
.
>
> I ***DO*** have Math::GMP::BigInt installed (as well as
> Math::Pari::BigInt), and a diagnostic dump of %INC indicates these are
> being called (see below).
I would still entertain the possibility that Math::BigInt is being called
somehow. To check that's *not* the case I would rename Math/BigInt.pm to
(eg) Math/BigInt_hide.pm, re-run the script and see if performance improves.
If it makes no difference then we can assume that Math::BigInt is *not* to
blame - but if either the script croaks, or it runs significantly faster,
then there's your culprit.
I note that Math::BigInt *is* listed in %INC .... hence my suspicions about
it.
Cheers,
Rob
------------------------------
Date: 1 Nov 2006 17:53:40 -0800
From: usenet@DavidFilmer.com
Subject: Re: Abysmal performance of Net::SFTP (and I have GMP & Pari)
Message-Id: <1162432420.105832.200020@m7g2000cwm.googlegroups.com>
Sisyphus wrote:
> I would still entertain the possibility that Math::BigInt is being called
> somehow. To check that's *not* the case I would rename Math/BigInt.pm to
> (eg) Math/BigInt_hide.pm, re-run the script and see if performance improves.
Thanks for the suggestion, Rob (I was hoping you would notice and reply
to this thread; you've been very helpful to me on other SSH-ish issues,
and I've been grateful for your help).
I tried your suggestion and the test program blew up with:
Can't locate Math/BigInt.pm in @INC ... Crypt/DH.pm line 6
and further complained:
Compilation failed in require .../Net/SSH/Perl/Kex/DH1.pm line 13.
Compilation failed in require .../Net/SSH/Perl/Kex.pm line 6.
Compilation failed in require .../Net/SSH/Perl/SSH2.pm line 6.
Compilation failed in require .../Net/SSH/Perl.pm line 54.
Line 6 of Crypt::DH (version 0.06) says:
use Math::BigInt lib => "GMP,Pari";
which looks OK to me and would seem to account for the Math::BigInt
call in %INC (but, hey, what do I know?). FWIW, I tried to take GMP
out (leaving only Pari) but it made no noticeable difference.
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Wed, 01 Nov 2006 13:55:38 -0600
From: Sharif Islam <mislam@spam.uiuc.edu>
Subject: Data Query/substitute operation
Message-Id: <eiau3r$4aq$1@news.ks.uiuc.edu>
I need to perform a search and replace on the results of a SQL query.
First, I need to replace some control characters. Then change numbers to
strings. I am using a if statement inside the while. Is there a better
way to do this? I will have more fields like this (number to strings)
that will need to satisfy different conditions.
__start code snippets__
my $qry = "SELECT [Item0], [Item1], [Item2] FROM TABLE" ;
my $sth = $dbh->prepare($qry) or die "could not prepare SQL query $qry";
my $rv = $sth->execute ;
my @row;
while (@row = $sth->fetchrow_array)
{
my @data = map { replacectrlM($_) } @row ;
if ($data[2] == 0 ) { $data[2] = 'r'; }
print "$data[0]\t$data[1]\t$data[2]\n";
}
}
sub replacectrlM {
my $string = shift;
if ($string =~ /^M/)
{
($string=$string) =~ s/^M//g ;
}
if ($string =~ /\n/) {
($string = $string) =~ s/\n/^]/g;
}
return $string;
}
___end code____
------------------------------
Date: Wed, 01 Nov 2006 12:25:56 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Data Query/substitute operation
Message-Id: <011120061225564291%jgibson@mail.arc.nasa.gov>
In article <eiau3r$4aq$1@news.ks.uiuc.edu>, Sharif Islam
<mislam@spam.uiuc.edu> wrote:
> I need to perform a search and replace on the results of a SQL query.
> First, I need to replace some control characters. Then change numbers to
> strings. I am using a if statement inside the while. Is there a better
> way to do this? I will have more fields like this (number to strings)
> that will need to satisfy different conditions.
>
> __start code snippets__
Please post complete programs in the future. We can't tell what data
you are trying to convert, so it makes it difficult to help you.
Separate the SQL code from the conversion code and only post the part
with which you are having a problem, i.e., define scalar strings within
your program.
>
> my $qry = "SELECT [Item0], [Item1], [Item2] FROM TABLE" ;
> my $sth = $dbh->prepare($qry) or die "could not prepare SQL query $qry";
> my $rv = $sth->execute ;
> my @row;
> while (@row = $sth->fetchrow_array)
> {
> my @data = map { replacectrlM($_) } @row ;
> if ($data[2] == 0 ) { $data[2] = 'r'; }
If you have more than a few possible conversions, put the replacement
string in a hash or an array and use regular expressions to test the
string (untested):
%replacement = ( '1' => 'r', '2' => ... );
if( $data[2] =~ /^\d$/ ) {
$data[2] = $replacement{$data[2]};
}
> print "$data[0]\t$data[1]\t$data[2]\n";
> }
>
> }
>
>
> sub replacectrlM {
> my $string = shift;
> if ($string =~ /^M/)
> {
> ($string=$string) =~ s/^M//g ;
> }
There is no need to test whether the character exists within the string
before trying to substitute it. Replace the above with (untested):
$string =~ s/\012//g;
Exact character(s) to use depends upon your platform. For faster
execution, us the tr operator:
$string =~ tr/\012//d;
------------------------------
Date: Wed, 01 Nov 2006 15:11:07 -0600
From: Sharif Islam <mislam@spam.uiuc.edu>
Subject: Re: Data Query/substitute operation
Message-Id: <eib2hg$5ns$1@news.ks.uiuc.edu>
Jim Gibson wrote:
> In article <eiau3r$4aq$1@news.ks.uiuc.edu>, Sharif Islam
> <mislam@spam.uiuc.edu> wrote:
>
> Please post complete programs in the future. We can't tell what data
> you are trying to convert, so it makes it difficult to help you.
> Separate the SQL code from the conversion code and only post the part
> with which you are having a problem, i.e., define scalar strings within
> your program.
>
[...]
ok.
>
> If you have more than a few possible conversions, put the replacement
> string in a hash or an array and use regular expressions to test the
> string (untested):
>
> %replacement = ( '1' => 'r', '2' => ... );
>
> if( $data[2] =~ /^\d$/ ) {
> $data[2] = $replacement{$data[2]};
> }
>
>
The issue is replacement is based on the data. For example, if [Item1]
is '0', it needs to be replaced as 'r', but if [Item2] is '0' then it
is 'x'.
#!/usr/bin/perl
use strict;
# this will be data from the SQL query.
my @data = ("0","Name","0","1");
# while loop for the database row will be here.
if ($data[0] == 0) { $data[0]= 'r' ;}
if ($data[2] == 0) { $data[2]='x' ;}
print "$data[0]\t$data[1]\t$data[2]\t$data[3]\n"
# end while loop
Thanks.
--sharif
------------------------------
Date: Wed, 1 Nov 2006 17:38:24 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Data Query/substitute operation
Message-Id: <slrnekibvg.kkc.tadmc@tadmc30.august.net>
Sharif Islam <mislam@spam.uiuc.edu> wrote:
> #!/usr/bin/perl
> use strict;
> # this will be data from the SQL query.
> my @data = ("0","Name","0","1");
>
> # while loop for the database row will be here.
> if ($data[0] == 0) { $data[0]= 'r' ;}
> if ($data[2] == 0) { $data[2]='x' ;}
> print "$data[0]\t$data[1]\t$data[2]\t$data[3]\n"
> # end while loop
my %replacement = ( '0' => 'r', '2' => 'x' );
foreach my $i ( keys %replacement ) {
$data[$i] = $replacement{$i} if $data[$i] == 0;
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 31 Oct 2006 19:43:18 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Distributing application with modules as a single file
Message-Id: <mjlk14-15b.ln1@osiris.mauzo.dyndns.org>
Quoth anno4000@radom.zrz.tu-berlin.de:
>
> You can replace a statement
>
> use My::Module arg1, ..., argn;
>
> with this functional equivalent
>
> BEGIN {
> # content of My/Module.pm here
> }
> BEGIN {
A slight nit: I would put
$INC{'My/Module.pm'} = $0;
here, just in case anything is checking.
> My::Module->import( arg1, ..., argn);
> }
>
> If My::Module doesn't have an import method that part can go.
>
> It shouldn't be hard to do that transformation for certain modules
> automatically.
...but of course it doesn't work for XS modules (which the OP wasn't
asking about, but it's worth noting anyway, especially as it will
probably seem to work on the dev box that has the modules installed :)
).
Ben
--
"Awww, I'm going to miss her."
"Don't you hate her?"
"Yes, with a fiery vengeance."
[benmorrow@tiscali.co.uk]
Miles to go. Little Miss Muffet counting down from 7-3-0.
[ben@morrow.me.uk]
------------------------------
Date: 1 Nov 2006 23:03:27 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Distributing application with modules as a single file
Message-Id: <4qsndvFop10oU1@news.dfncis.de>
Ben Morrow <benmorrow@tiscali.co.uk> wrote in comp.lang.perl.misc:
>
> Quoth anno4000@radom.zrz.tu-berlin.de:
> >
> > You can replace a statement
> >
> > use My::Module arg1, ..., argn;
> >
> > with this functional equivalent
> >
> > BEGIN {
> > # content of My/Module.pm here
> > }
> > BEGIN {
>
> A slight nit: I would put
>
> $INC{'My/Module.pm'} = $0;
>
> here, just in case anything is checking.
Yes, good idea.
>
> > My::Module->import( arg1, ..., argn);
> > }
> >
> > If My::Module doesn't have an import method that part can go.
> >
> > It shouldn't be hard to do that transformation for certain modules
> > automatically.
>
> ...but of course it doesn't work for XS modules (which the OP wasn't
> asking about, but it's worth noting anyway, especially as it will
> probably seem to work on the dev box that has the modules installed :)
> ).
Both true. Inline should work, but the initial startup will be slow.
Another thing that breaks is __DATA__ sections. __FILE__ and __LINE__
will also be affected. There's probably more...
Anno
------------------------------
Date: Tue, 31 Oct 2006 19:35:37 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: FAQ 4.29 How can I count the number of occurrences of a substring within a string?
Message-Id: <95lk14-15b.ln1@osiris.mauzo.dyndns.org>
Quoth Michele Dondi <bik.mido@tiscalinet.it>:
> On Fri, 27 Oct 2006 15:41:50 -0500, brian d foy
> <brian.d.foy@gmail.com> wrote:
>
> >In article <1161955782.576895.233190@h48g2000cwc.googlegroups.com>,
> >werwer <drubnone@yahoo.com> wrote:
> >
> >
> >> > 4.29: How can I count the number of occurrences of a substring within a
> >> > string?
> >
> >> $count = split(/this/, $s);
> >
> >split() in scalar context is deprecated because of its side effects.
> >See perlfunc.
>
> I was about to say that you're wrong and that would be in *void*
> context. However I checked and not surprisingly it turned out that *I*
> am wrong. Still, one may wonder why *that* behaviour was chosen in the
> first place:
The behaviour is very old, and dates from before Perl had void context
distinct from scalar context. The only reason it is deprecated rather
than removed is because p5p are (rightly) obsessed with maintaining
backwards-compatibility.
Ben
--
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
benmorrow@tiscali.co.uk (Kate Rusby)
------------------------------
Date: Wed, 01 Nov 2006 21:28:11 +0100
From: Martin Larsen <martin+spamfree+larsen@bigfoot.com>
Subject: How to capture repeated subpatterns?
Message-Id: <eib00n$240d$1@newsbin.cybercity.dk>
Hi,
One thing that puzzles me is whether it is possible to capture each
repeated subpattern.
Here is a simple regex that will match a string consisting of individual
words:
(?:(\w+) ?)+
If the subject is "three little mice" the regex will match the string,
and the subpattern match ($1) would be "mice". That is, the last
subpattern match will be returned.
But what if I wanted to extract all submatches?
So that $1 = three, $2 = little and $3 = mice
It could be done by repeating an expression like this:
(?:(\w+) ?)?(?:(\w+) ?)?(?:(\w+) ?)?(?:(\w+) ?)?
as many times as needed. Each "(?:(\w+) ?)?" will match one optional
word, separated by a space from the next word.
But that is not an elegant solution!
So my question is: Is it in fact possible to repeat AND capture subpatterns?
Martin
------------------------------
Date: Wed, 01 Nov 2006 21:46:05 +0100
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: How to capture repeated subpatterns?
Message-Id: <eib1aj$dv$1@mlucom4.urz.uni-halle.de>
Thus spoke Martin Larsen (on 2006-11-01 21:28):
> Here is a simple regex that will match a string consisting of individual
> words:
> (?:(\w+) ?)+
> If the subject is "three little mice" the regex will match the string,
> and the subpattern match ($1) would be "mice". That is, the last
> subpattern match will be returned.
>
> But what if I wanted to extract all submatches?
> So that $1 = three, $2 = little and $3 = mice
>
> It could be done by repeating an expression like this:
> (?:(\w+) ?)?(?:(\w+) ?)?(?:(\w+) ?)?(?:(\w+) ?)?
Why don't you use the /g modifier
(match as much is possible)?
...
my $text = 'three little mice';
my @words = $text =~ /\b(\w+)\b/g; # <== /g repeats matches
print "@words";
...
Regards
Mirco
------------------------------
Date: Wed, 01 Nov 2006 21:52:55 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to capture repeated subpatterns?
Message-Id: <4qsft3Foj4ujU1@individual.net>
Martin Larsen wrote:
> But what if I wanted to extract all submatches?
> So that $1 = three, $2 = little and $3 = mice
You don't need to use the dollardigit variables.
my @matches = 'three little mice' =~ /(\w+) ?/g;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 02 Nov 2006 00:36:39 +0100
From: Martin Larsen <martin+spamfree+larsen@bigfoot.com>
Subject: Re: How to capture repeated subpatterns?
Message-Id: <eibb24$29og$1@newsbin.cybercity.dk>
Thanks for your responses, but you both misunderstand what I aim at.
I simplified the expression to make it more clear, but I realize that it
does the opposite by confusing you into thinking that all I need is to
capture all the words.
That is not the case at all.
In fact, it is a matter of extracting parameters from an expression. So
let me try again, this time with some html code.
Here is an image declaration:
<img src="mypic.jpg" class="myclass" alt="description" title="some text">
I need to match the full expression and also to capture the individual
attributes.
The declation shown could be matched by
<img *(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")?>
That gives:
submatch 1 = src="mypic.jpg"
submatch 2 = class="myclass"
submatch 3 = alt="description"
submatch 4 = title="some text"
Fine, but what if the html code had yet another attribute, like:
<img src="mypic.jpg" class="myclass" alt="description" title="some text"
border="0">
Then the expression wouldn't match anymore. Of course I could just add a
bunch of the subpatterns to the expression, because since I have made
them optional the regex will match even if there are less attributes
than subpatterns.
For example, this would match up to 8 attributes:
<img *(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")?
*(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")?>
But as you see, it is certainly not elegant.
Well, then ... if it was just a matter of matching an arbitrary number
of attributes, the regex would simply be:
<img(?: *(\w+="[^"]*"))+>
But the only submatch would then be border="0". Only the last submatch
is captured.
Instead I need to extract ALL the parameters individually, so the
million dollar question is:
Is it possible to define a regex using repeated subpatterns in such a
way that all subpatterns can be captured individually?
The real usage is a little more complicated than matching html
attributes, and yes: I could use a parser etc!
But I would really like to know if my quest is possible!
Martin
------------------------------
Date: Wed, 1 Nov 2006 17:26:19 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to capture repeated subpatterns?
Message-Id: <slrnekib8r.kkc.tadmc@tadmc30.august.net>
Mirco Wahab <wahab@chemie.uni-halle.de> wrote:
> my @words = $text =~ /\b(\w+)\b/g; # <== /g repeats matches
I'm pretty sure that this is equivalent:
my @words = $text =~ /(\w+)/g;
Isn't it?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 02 Nov 2006 01:11:50 +0100
From: Martin Larsen <martin+spamfree+larsen@bigfoot.com>
Subject: Re: How to capture repeated subpatterns?
Message-Id: <eibd43$2al8$1@newsbin.cybercity.dk>
Thanks for your responses.
Now, my example was simplified for clarity, but I am still unsure if
your suggestions can accomplish what I need.
In fact, it is a matter of extracting parameters from an expression. So
let me try again, this time with some html code.
Here is an image declaration:
<img src="mypic.jpg" class="myclass" alt="description" title="some text">
I need to match the full expression and also to capture the individual
attributes.
The declation shown could be matched by
<img *(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")?>
That gives:
submatch 1 = src="mypic.jpg"
submatch 2 = class="myclass"
submatch 3 = alt="description"
submatch 4 = title="some text"
Fine, but what if the html code had yet another attribute, like:
<img src="mypic.jpg" class="myclass" alt="description" title="some text"
border="0">
Then the expression wouldn't match anymore. Of course I could just add a
bunch of the subpatterns to the expression, because since I have made
them optional the regex will match even if there are less attributes
than subpatterns.
For example, this would match up to 8 attributes:
<img *(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")?
*(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")? *(\w+="[^"]*")?>
But as you see, it is certainly not elegant.
Well, then ... if it was just a matter of matching an arbitrary number
of attributes, the regex would simply be:
<img(?: *(\w+="[^"]*"))+>
But the only submatch would then be border="0". Only the last submatch
is captured.
Instead I need to extract ALL the parameters individually.
Is this also possible using the /g modifier, and if so, how?
Thanks,
Martin
------------------------------
Date: Thu, 02 Nov 2006 00:22:05 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: How to capture repeated subpatterns?
Message-Id: <NSa2h.77065$E67.57227@clgrps13>
Tad McClellan wrote:
> Mirco Wahab <wahab@chemie.uni-halle.de> wrote:
>
>> my @words = $text =~ /\b(\w+)\b/g; # <== /g repeats matches
>
>
> I'm pretty sure that this is equivalent:
>
> my @words = $text =~ /(\w+)/g;
>
> Isn't it?
As is:
my @words = $text =~ /\w+/g;
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Thu, 02 Nov 2006 01:46:25 +0100
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: How to capture repeated subpatterns?
Message-Id: <eibfd8$4tf$1@mlucom4.urz.uni-halle.de>
Thus spoke Martin Larsen (on 2006-11-02 01:11):
> Here is an image declaration:
>
> <img src="mypic.jpg" class="myclass" alt="description" title="some text">
> <img src="mypic.jpg" class="myclass" alt="description" title="some text" border="0">
> Instead I need to extract ALL the parameters individually.
Hmmm, I can slowly figure what you are trying to do ;-)
What about pulling the attributes into a hash?
...
my $t1 = '<img src="mypic.jpg" class="myclass" alt="description" title="some text">';
my $t2 = '<img src="mypic.jpg" class="myclass" alt="description" title="some text" border="0">';
my %attrs;
my $rg = qr {<\w+([^>]+)(?{%attrs=map +(split '='), split '"', $1})};
%attrs=();
if ($t1 =~ /$rg/) {
print "$_ ==> $attrs{$_}\n"for keys %attrs;
}
%attrs=();
if ($t2 =~ /$rg/) {
print "$_ ==> $attrs{$_}\n"for keys %attrs;
}
...
This pulls each key/value attribute pair into
the corresponding hash entry. Maybe that won't
work in any case, but it should be some
starting point.
Rergards
Mirco
------------------------------
Date: 1 Nov 2006 12:59:25 -0800
From: dcruncher4@aim.com
Subject: Information about file systems.
Message-Id: <1162414765.458628.21050@f16g2000cwb.googlegroups.com>
How can I get a list of file systems and find out whether it is a local
FS or NFS.
thanks.
------------------------------
Date: Wed, 1 Nov 2006 23:57:14 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: killing processes using perl (artsd)
Message-Id: <eibcfp.dg.1@news.isolution.nl>
andreas schreef:
> Dr.Ruud:
>> use warnings ;
>> use strict ;
>
> ok - I will look for that and try to figure out why?
perllexwarn
perlsub (look for "Private Variables" or "lexical")
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Wed, 1 Nov 2006 23:50:50 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: killing processes using perl (artsd)
Message-Id: <eibbsv.1bc.1@news.isolution.nl>
andreas schreef:
> Dr.Ruud:
>> print "kill '$_'\t?\n" for @pids ;
>
> this use of 'for' is not only perl it is a pearl !
> Could be the death of 'foreach' ;-)
<quote source="perlsyn(1)">
The "foreach" keyword is actually a synonym for the "for" keyword,
so you can use "foreach" for readability or "for" for brevity.
</quote>
Also test the code on a BSD system:
<quote source="ps(1)">
-C Change the way the cpu percentage is calculated by using a
``raw'' cpu calculation that ignores ``resident'' time
(this normally has no effect).
</quote>
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Wed, 1 Nov 2006 13:35:16 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: killing processes using perl (artsd)
Message-Id: <slrnekhtnk.jua.tadmc@tadmc30.august.net>
andreas <andreas./@> wrote:
> Am Wed, 01 Nov 2006 08:44:04 +0100 schrieb Dr.Ruud:
>> Remove the -w, and add:
>>
>> use warnings ;
>> use strict ;
>
> ok - I will look for that and try to figure out why?
Short version:
Because they catch many common programmer mistakes, such as typos.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 01 Nov 2006 20:05:24 GMT
From: xhoster@gmail.com
Subject: Re: longest common substring
Message-Id: <20061101150532.308$G1@newsreader.com>
xhoster@gmail.com wrote:
>
> my $count=0;
> while(1) {
> my @common= grep {$hash->{$_}>1 and length == $max} keys %$hash;
> $count+=@common;
> print length $_, "\t$hash->{$_}\t$_\n" foreach @common;
> last if $count>10 or $max==0;
> my %hash2;
> $max--;
> $hash2{substr $_, 0, $max}++ foreach keys %$hash;
But this should be:
$hash2{substr $_, 0, $max}+=$hash->{$_} foreach keys %$hash;
> $hash=\%hash2;
> }
>
> Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 1 Nov 2006 12:16:00 -0800
From: "samasama" <bryan@worldspice.net>
Subject: Re: Putting a line in a specific place in a file
Message-Id: <1162412160.349630.131730@k70g2000cwa.googlegroups.com>
> That would be because you are not looping through the file when you
> print $. . You've slurped the whole file into @file and are looping
> through @file. It's no surprise that $. is equal to the last line
> number of the input file.
>
> You may want to loop through the file handle vs looping on @file. Or
> loop through @file using
> for my $i ( 0 .. $#file ) {
> if ( $line =~ ...
> }
> --
>
Thanks, that does make sense : )
I did a while (<FH>) and am able to find the line it's line number, but
how would I go about finding the first instance of $line =~ /gpgkey/
below it? And get the line number.
Thanks
--
samasama
------------------------------
Date: Wed, 01 Nov 2006 14:55:15 -0600
From: l v <veatchla@yahoo.com>
Subject: Re: Putting a line in a specific place in a file
Message-Id: <12ki2ddilpo9h8c@news.supernews.com>
samasama wrote:
>> That would be because you are not looping through the file when you
>> print $. . You've slurped the whole file into @file and are looping
>> through @file. It's no surprise that $. is equal to the last line
>> number of the input file.
>>
>> You may want to loop through the file handle vs looping on @file. Or
>> loop through @file using
>> for my $i ( 0 .. $#file ) {
>> if ( $line =~ ...
>> }
>> --
>>
>
> Thanks, that does make sense : )
> I did a while (<FH>) and am able to find the line it's line number, but
> how would I go about finding the first instance of $line =~ /gpgkey/
> below it? And get the line number.
>
> Thanks
>
> --
> samasama
>
My first thought would be set a switch when you found "base" and
continue looping through the file until you found what you are looking
for *and* the switch was set. That is a simplistic approach and may not
scale to your actual task at hand.
--
Len
------------------------------
Date: Wed, 1 Nov 2006 17:41:56 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Putting a line in a specific place in a file
Message-Id: <slrnekic64.kkc.tadmc@tadmc30.august.net>
samasama <bryan@worldspice.net> wrote:
> I did a while (<FH>) and am able to find the line it's line number, but
> how would I go about finding the first instance of $line =~ /gpgkey/
> below it? And get the line number.
while ( <FH> ) { # skip some lines
last if $. == $magic_line_number;
}
while ( <FH> ) { # start search "below it"
print "found on line $.\n" if /gpgkey/;
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 02 Nov 2006 00:33:32 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Putting a line in a specific place in a file
Message-Id: <w1b2h.77069$E67.28800@clgrps13>
Tad McClellan wrote:
> samasama <bryan@worldspice.net> wrote:
>
>>I did a while (<FH>) and am able to find the line it's line number, but
>>how would I go about finding the first instance of $line =~ /gpgkey/
>>below it? And get the line number.
>
>
> while ( <FH> ) { # skip some lines
> last if $. == $magic_line_number;
> }
>
> while ( <FH> ) { # start search "below it"
> print "found on line $.\n" if /gpgkey/;
> }
while ( <FH> ) {
( $. == $magic_line_number .. /gpgkey/ ) =~ /E/
&& print "found on line $.\n";
}
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 9917
***************************************