[23444] in Perl-Users-Digest
Perl-Users Digest, Issue: 5659 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 14 14:10:38 2003
Date: Tue, 14 Oct 2003 11:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 14 Oct 2003 Volume: 10 Number: 5659
Today's topics:
Re: Net::SSH::Perl : multiple connections fails <vladimir@NoSpamPLZ.net>
Re: Perl Intros? (ascii graphics)... (Bill)
Please help re Perl script modification (Ron M.)
Re: Please help re Perl script modification <xx087@freenet.carleton.ca>
Process each input record as an array of elements (Dmitry)
Re: Process each input record as an array of elements <josef.moellers@fujitsu-siemens.com>
Re: Process each input record as an array of elements <go@away.spam>
Re: Process each input record as an array of elements (Roy Johnson)
Re: search result case problem (Jasper)
Threads and OO Question <Ed+nospam@ewildgoose.demon.co.uk@>
Re: Threads and OO Question (Bill)
Re: Why doesn't this work? <nospam@goawayspam.com>
Re: Why Is My Hash Assignment Taking So Long? (Anno Siegel)
Re: Why Is My Hash Assignment Taking So Long? <uri@stemsystems.com>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 14 Oct 2003 15:10:02 GMT
From: lostriver <vladimir@NoSpamPLZ.net>
Subject: Re: Net::SSH::Perl : multiple connections fails
Message-Id: <elUib.59496$kY1.1194411@weber.videotron.net>
On 13 Oct 2003 05:35:43 -0700, Helge Cramer wrote:
> Yes, I do run the script as root, so Net::SSH::Perl should set
> privileged=1 on its own (as described in the documentation).
> Any further suggestions (perhaps how to make connection 2 after
> connection 1)?
>
Post your code. It is hard to guess what you are doing...
This work just fine for me:
use Net::SSH::Perl;
foreach (1..3) {
$i = Net::SSH::Perl->new(localhost);
$i->login('username', 'password');
push @connections, $i;
next unless $_ == 2;
my ($stdout, $stderr, $exit) = $i->cmd('ls');
print "First loop: $_: $stdout\n";
}
foreach $i (@connections) {
my ($stdout, $stderr, $exit) = $i->cmd('ls');
print "Second loop: $stdout\n";
}
--
.signature: No such file or directory
------------------------------
Date: 14 Oct 2003 06:54:56 -0700
From: wherrera@lynxview.com (Bill)
Subject: Re: Perl Intros? (ascii graphics)...
Message-Id: <239ce42f.0310140554.697c3760@posting.google.com>
perlguy@hotmail.com (Philip Parker) wrote in message news:<3e5875d3.0310131942.2b697253@posting.google.com>...
> A couple of years ago I stumbled onto a site with ascii intros written
> in perl, and a few games I think. I cannot find that site now or
> anything similar to it. Anyone have any pointers? Thanks.
>
> Philip Parker
you might want to look at the code for 'perlblaster' on sourceforge
------------------------------
Date: 14 Oct 2003 07:32:47 -0700
From: rmorgan7@austin.rr.com (Ron M.)
Subject: Please help re Perl script modification
Message-Id: <d7fc3008.0310140632.4e968972@posting.google.com>
I have a Perl script that searches through a directory and its
subdirectories and finds all files with a certain string in the
filename. Then it replaces some text in each of those files. The
script is below. This is how it would appear to operate on all ".html"
files, replacing "oldstring" with "newstring":
perl -i.bak -pe 's/oldstring/newstring/g' `find . -name *.html\*`
My question is this: the script creates a backup of EVERY file with
the suffix ".bak" and I don't want it to do this. How do I modify the
above script so that this won't happen?
Thanks,
Ron M.
------------------------------
Date: 14 Oct 2003 14:36:19 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Please help re Perl script modification
Message-Id: <slrnboo2g6.fgj.xx087@smeagol.ncf.ca>
Ron M. <rmorgan7@austin.rr.com> wrote:
> perl -i.bak -pe 's/oldstring/newstring/g' `find . -name *.html\*`
Not a perl issue. Missing backslash in your find command:
perl -i.bak -pe 's/oldstring/newstring/g' `find . -name \*.html`
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: 14 Oct 2003 07:37:08 -0700
From: perluser@optonline.net (Dmitry)
Subject: Process each input record as an array of elements
Message-Id: <71ad9bef.0310140637.142122e9@posting.google.com>
Hello everyone,
I have a really simple question here:
I have a plain file with space delimited fields that I want to read with WHILE
loop 1 line at the time and process each input record as an array of
elements. Then, on the next iteration of the loop, clean up the array
and populate it with contents of the next input record. Each input
record consists of 7 fields / elements separated by spaces. The reason
I need this is because I have to switch FIRST and LAST elements of the
record by places. For example:
Before: aaa bbb ccc ddd eee fff ggg
After: ggg bbb ccc ddd eee fff aaa
I am having trouble assigning contents of each input record to an
array.
If I can do that, then I can use POP and UNSHIFT Perl functions to
switch the elements.
Here is what I have so far:
my $pop_element = '';
my @print_array = ();
open (OLD, "< $fname_out") || die "Cannot open OLD file
$fname_out!";
open (NEW, "> $temp") || die "Cannot open NEW file $temp!";
while (<OLD>) {
@print_array = "$_\n";
$pop_element = pop ( @print_array );
unshift ( @print_array, $pop_element );
$_ = @print_array;
print NEW "$_\n" || die "Cannot write NEW file $temp!";
}
close (OLD) || die "Cannot close OLD file $fname_out!";
close (NEW) || die "Cannot close NEW file $temp!";
rename ( $temp, $fname_out ) || die "Cannot rename NEW file $temp
to $fname_out!";
}
Any suggestions would be greatly appreciated.
Thanks,
Dmitry.
------------------------------
Date: Tue, 14 Oct 2003 16:56:10 +0200
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Process each input record as an array of elements
Message-Id: <3F8C0E8A.7CE83E3D@fujitsu-siemens.com>
Dmitry wrote:
> I am having trouble assigning contents of each input record to an
> array.
perldoc -f split
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Tue, 14 Oct 2003 15:47:30 GMT
From: "LaDainian Tomlinson" <go@away.spam>
Subject: Re: Process each input record as an array of elements
Message-Id: <mUUib.2835$En4.2605@twister.southeast.rr.com>
"Dmitry" <perluser@optonline.net> wrote:
> I have a plain file with space delimited fields that I want to read with
WHILE
> loop 1 line at the time and process each input record as an array of
> elements. Then, on the next iteration of the loop, clean up the array
> and populate it with contents of the next input record. Each input
> record consists of 7 fields / elements separated by spaces. The reason
> I need this is because I have to switch FIRST and LAST elements of the
> record by places. For example:
>
> Before: aaa bbb ccc ddd eee fff ggg
>
> After: ggg bbb ccc ddd eee fff aaa
>
> I am having trouble assigning contents of each input record to an
> array.
<snip>
You may not need to use an array as such. You could just do a substitution:
#!/usr/bin/perl
$\ = "\n";
while (<DATA>){
chomp;
s/^(\S+)\s+(.*?)\s+(\S+)$/$3 $2 $1/;
print;
}
__DATA__
aaa bbb ccc ddd eee fff ggg
hhh ii jjjj kk lllll m n
Hope that helps,
Brandan L.
--
bclennox AT eos DOT ncsu DOT edu
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.522 / Virus Database: 320 - Release Date: 9/29/2003
------------------------------
Date: 14 Oct 2003 09:56:41 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: Process each input record as an array of elements
Message-Id: <3ee08638.0310140856.22c88fb8@posting.google.com>
perluser@optonline.net (Dmitry) wrote in message news:<71ad9bef.0310140637.142122e9@posting.google.com>...
> If I can do that, then I can use POP and UNSHIFT Perl functions to
> switch the elements.
You can also just swap them by indexing:
@print_array[0,-1] = @print_array[-1,0];
------------------------------
Date: 14 Oct 2003 08:24:25 -0700
From: jasper@mccrea.demon.co.uk (Jasper)
Subject: Re: search result case problem
Message-Id: <b6891527.0310140724.7c2347be@posting.google.com>
"Ben Duffy" <duffy_ben@hotmail.com> wrote in message news:<YkQib.10592$jF3.409@news-binary.blueyonder.co.uk>...
> What perl functions should I use to be able to find a substring in a string,
> & replace it with bold text, similar to Google search results highlighting?
>
> for example
> search "120gb Hard Disk Drive" for "disk" to result in "120gb Hard
> <strong>Disk</strong> Drive"
>
> The way I am currently doing this is...
> $prodname = "120gb Hard Disk Drive" ;
> $where_desc = "disk";
> $prodname =~ s/$where_desc/<strong>$where_desc<\/strong>/gi;
>
> which gives... "120gb Hard <strong>disk</strong> Drive"
>
> The problem is that I want to retain the $prodname's original case.
Why not try:
$prodname =~ s/($where_desc)/<strong>$1<\/strong>/gi;
That seems to work for me. The brackets capture what you actually
match, not just what you're searching for, if you see what I mean.
Jasper
------------------------------
Date: Tue, 14 Oct 2003 14:41:34 GMT
From: "Edward Wildgoose" <Ed+nospam@ewildgoose.demon.co.uk@>
Subject: Threads and OO Question
Message-Id: <yWTib.222522$p36.2183344@news.easynews.com>
I have a peculiar problem with threads on Perl 5.8 (activestate on Win32)
My sample code is below, however, the problem is basically that if I run
this under the debugger then if "works" as expected. Works in this case
defined as some output goes to stdout.
However, if I simply run the program from the command line, then I only get
output from the thread running "MyPackage->start"... There is no output
from the main thread. Any ideas why (does it happen to anyone else? Linux?)
Is this to do with one of the threads grabbing stdout and the other not
being able to access it?
Secondly is this the "right" way to do thread programming? The "problem" I
am trying to solve is to have the main start thread showing a GUI interface,
where the MyPackage class is then a worker class which goes off and does
something. Then the GUI will periodically access the properties of
"MyPackage" to determine state and progress (and update the GUI). FWIW,
there is a deliberate attempt to keep the two processes seperate hence not
relying on the any abilities the GUI toolkit might provide to do background
processing.
Thanks
Ed W
>>>>>>>>>>>>>>>>>>>>>>>>>>>>
use threads;
use threads::shared;
use strict;
package MyPackage;
my $counter : shared;
$counter = 0;
sub new {
my $class = shift;
my $this = {COUNTER => 0};
threads::shared::share($this->{COUNTER});
$counter = 0;
return bless($this, $class);
}
sub start {
my $this = shift;
while (1) {
$counter += 1;
$this->{COUNTER} += 1;
sleep 1;
print STDOUT "In Counter: $counter \r\n";
}
}
sub getCounter {
my $this = shift;
return $this->{COUNTER};
# return $counter;
}
package main;
sub MainLoop {
my $a;
my $a = MyPackage->new();
my $thr = threads->new(sub{$a->start();});
sleep 1;
while (1) {
my $count = $a->getCounter();
print STDOUT $count;
sleep 1;
}
my @ReturnData = $thr->join;
print "Thread returned @ReturnData";
}
MainLoop();
------------------------------
Date: 14 Oct 2003 10:57:47 -0700
From: wherrera@lynxview.com (Bill)
Subject: Re: Threads and OO Question
Message-Id: <239ce42f.0310140957.3dee44@posting.google.com>
"Edward Wildgoose" <Ed+nospam@ewildgoose.demon.co.uk@> wrote in message news:<yWTib.222522$p36.2183344@news.easynews.com>...
> I have a peculiar problem with threads on Perl 5.8 (activestate on Win32)
>
It's not threads, it's io buffering
Add
$| = 1;
to the top of the program.
> My sample code is below, however, the problem is basically that if I run
> this under the debugger then if "works" as expected. Works in this case
> defined as some output goes to stdout.
>
------------------------------
Date: Tue, 14 Oct 2003 09:22:32 -0500
From: "Kubaton Lover" <nospam@goawayspam.com>
Subject: Re: Why doesn't this work?
Message-Id: <voo1lia5ecjd35@corp.supernews.com>
"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote in message
news:Pine.LNX.4.53.0310132250200.21768@ppepc56.ph.gla.ac.uk...
> On Mon, 13 Oct 2003, Kubaton Lover wrote:
>
> | Subject : Re: Why doesn't this work?
>
> You'll be needing this shortly[1]:
>
> http://catb.org/~esr/faqs/smart-questions.html#bespecific
>
> The rest of the page is also a good read, and will help you to help
> yourself, without waiting for the possibly acid remarks from a
> newsgroup.
There were a lot of good tips on that website.
The error I received wasn't specific, so I didn't list it. It stated, "CGI
Process error on server". My development environment consists of Notepad,
FTP, and an Apache Unix server. I have no other access to the server, nor
other tools allowed on the company machinery. It's frustrating to say the
least, but I do what I can. Hopefully, one of these days, I can convince
the boss to allow us a "real" development environment. Until then, I'm
stuck putting in print statements and going over code with a fine-toothed
comb.
My experience has been that only the Perl newsgroup takes the time to
totally trash people for their questions. As good at Perl as some of the
users in the forum are, it is definitely the most anal-retentive, nefarious
group I've ever met. It's the only group I've ever entered that cared more
about making sure people type "perl" or "Perl" instead of "PERL" rather than
trying to answer the question. I generally chalk that up to nerdiness or
immaturity. My programmer coworkers and I see that attitude occasionally in
other programmers, but this newsgroup has sort of become a running joke with
us. A perfect example is that someone would waste their time performing a
search on my name to see what other messages I had posted which have no
relationship to my current question. I guess it's just me, but if I don't
like the way a question is worded for whatever reason, I don't answer it.
It's a natural consequence, thus an excellent teaching tool. I find it more
productive then the flames that I usually see.
One newsgroups newbie is another newsgroups expert. I try to remember that,
and I wish more people did.
------------------------------
Date: 14 Oct 2003 17:04:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why Is My Hash Assignment Taking So Long?
Message-Id: <bmhab0$qm1$1@mamenchi.zrz.TU-Berlin.DE>
James E Keenan <nospam_for_jkeen@concentric.net> wrote in comp.lang.perl.misc:
>
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:bmdrkl$gji$1@mamenchi.zrz.TU-Berlin.DE...
> > James E Keenan <nospam_for_jkeen@concentric.net> wrote in
> comp.lang.perl.misc:
> > > I need to build a hash whose elements represent characteristics of each
> of
> > > 9600 files in a single directory. I am trying to figure out why this
[...]
> > The stat() operation takes longer for files that are "late" in the
> > directory, in the sense that readdir() produces them late. Since > > your directory is oversized, the difference is significant. Since
> > you process the files in the order in which they were found, the process
> > seems to slow down progressively.
>
> Very interesting!
[...]
> More generally, is the sort of too-many-files-in-a-directory slowdown I
> experienced here true across operating systems? Or just on this one
> (Windows98 SE)? (It does seem as if all directory-related operations
> calling upon this directory are slow.)
Generally very large directories are slow though there may be differences,
even large ones, between file various systems. Directories were invented
so you don't have all your files in one place, so they are perhaps not
optimized for large numbers. Most people would consider a few hundred
files in a directory quite crowded, especially if the directory is active.
Split them up so that no directory has more than 256 entries, that seems
to be a reasonable number.
When a directory is mostly passive (like, say, the fonts of something big
and bulky), you can store more files per directory, but even then I'd put
a limit at a thousand or so.
Anno
------------------------------
Date: Tue, 14 Oct 2003 17:51:15 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Why Is My Hash Assignment Taking So Long?
Message-Id: <x7ptgz3dyk.fsf@mail.sysarch.com>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
AS> When a directory is mostly passive (like, say, the fonts of
AS> something big and bulky), you can store more files per directory,
AS> but even then I'd put a limit at a thousand or so.
the size of a file has little to do with how many files should be in a
directory. classic unix file systems totally isolate the directory
entry from the file contents. directory searches are linear which is why
they get very slow when there are many entries. i ran into this many
years ago and redesigned a subsystem to use multiple subdirs before
finding a particular file. it effectively converted a linear search to a
tree search. i used 2 digits of the log file name for 2 levels keeping
the number of entries in any directory to under 100. it was much much
faster than the old system which had 10k+ entries in one dir. this is
still a common and easy technique. some modern unix/linux filesystems
use trees or hashes for lookup and are much faster than linear. but you
are always guaranteed to have a classic linear filesystem around so this
subdir trick will work anywhere.
and i would limit dir sizes to way less than 1000. 100-300 seems to be a
good value.
and this is way OT as it has no perl content at all.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5659
***************************************