[24586] in Perl-Users-Digest
Perl-Users Digest, Issue: 6762 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 3 03:05:43 2004
Date: Sat, 3 Jul 2004 00:05:06 -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 Sat, 3 Jul 2004 Volume: 10 Number: 6762
Today's topics:
Re: finding every combination of n values at y position <krahnj@acm.org>
Re: Newbie: How do I filter output to the screen and w (Mav)
Re: Newbie: How do I filter output to the screen and w (Mav)
Re: Newbie: How do I filter output to the screen and w <tadmc@augustmail.com>
Re: Newbie: How do I filter output to the screen and w <postmaster@castleamber.com>
Re: Newbie: How to I extract word <nilram@hotpop.com>
Re: Q: re the kind of reference to be bless()ed in OO p (Anno Siegel)
Re: threads and getlocaltime <noreply@gunnar.cc>
win32::job window attributes (Cameron)
Re: Writing installation script with Perl? <dug@plusthree.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 02 Jul 2004 23:06:38 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: finding every combination of n values at y positions
Message-Id: <40E5EA63.E53C56BD@acm.org>
"Steve (another one)" wrote:
>
> I have just wasted a crazy amount of time trying to populate an array
> containing every combination of n values at y positions. It feels as
> though it should be trivial and the sort of thing I do every day, but in
> fact I could not find the simple solution that surely must exist.
>
> Below is my best attempt - it will also explain the task if I haven't
> been clear - can someone tell me if there is a simpler way of doing it.
>
> [snip]
You could do it like this:
#!/usr/bin/perl
use warnings;
use strict;
my $min_value = 1;
my $max_value = 4;
my $number_of_positions = 3;
my $glob = ( '{' . join( ',', $min_value .. $max_value ) . '}' ) x $number_of_positions;
$individual = 0;
print $individual++, " - @$_\n" for map [ /./g ], glob $glob;
__END__
:-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: 2 Jul 2004 22:09:02 -0700
From: mluvw47@yahoo.com (Mav)
Subject: Re: Newbie: How do I filter output to the screen and writing the orginal output to a file?
Message-Id: <dfaafecd.0407022109.2e94fffd@posting.google.com>
I need to execute (using system(@args)) in order to get the output.
Would you give me an example? I read the perl section but still don't
quite understand how to make it work for my case.
Any comments or input are welcome.
TIA,
Mav
John Bokma <postmaster@castleamber.com> wrote in message news:<40e5dd99$0$189$58c7af7e@news.kabelfoon.nl>...
> Mav wrote:
>
> > Hi, all
> >
> >
> > I need to write a perl script that execute (using system) command
> > to do build.
> >
> > While it is doing the build, I would like to print out the item is
> > build on the screen,
> > the orginal build output will go to the a log file (build.log).
> >
> >
> > @args = ("\"$devPath\\devenv.com\" Solution\\my.sln /build Release");
> >
> > open (OLDSTDOUT, ">&STDOUT") or die "Couldn't dup STDOUT: $!";
> > open(STDOUT, "> build.log") || die "Can't redirect stdout";
>
> use or or || this is confusing.
>
> > #once this execute it starts writing to build.log
> > $buildResult = system(@args);
>
> use strict;
> use warnings;
>
> > #The following write to build.log
> > #--Build Item A
> > #compiling a1.cpp
> > #compiling a2.cpp
> > ...
> > #--Build Item B
> > #compiling b1.cpp
> > #compiling b2.cpp
> > ...
> >
> > At the same time, how do I only print the following on the screen?
> > #To screen
> > Build Item A
> > Build Item B
> >
> > Do I need to start a another process in order to do it?
> > How do I filter the STDOUT(to file) at the same time output to screen?
>
> use a pipe instead of system
------------------------------
Date: 2 Jul 2004 22:11:36 -0700
From: mluvw47@yahoo.com (Mav)
Subject: Re: Newbie: How do I filter output to the screen and writing the orginal output to a file?
Message-Id: <dfaafecd.0407022111.420da8ca@posting.google.com>
I need to execute (using the system (@args)) in order to get the
output.
Would you give me an example?
I read the perl section for pipe, still don't quite understand how to
make my code work.
Any input or comments are welcome,
TIA,
Mav
John Bokma <postmaster@castleamber.com> wrote in message news:<40e5dd99$0$189
$58c7af7e@news.kabelfoon.nl>...
> Mav wrote:
>
> > Hi, all
> >
> >
> > I need to write a perl script that execute (using system) command
> > to do build.
> >
> > While it is doing the build, I would like to print out the item is
> > build on the screen,
> > the orginal build output will go to the a log file (build.log).
> >
> >
> > @args = ("\"$devPath\\devenv.com\" Solution\\my.sln /build Release");
> >
> > open (OLDSTDOUT, ">&STDOUT") or die "Couldn't dup STDOUT: $!";
> > open(STDOUT, "> build.log") || die "Can't redirect stdout";
>
> use or or || this is confusing.
>
> > #once this execute it starts writing to build.log
> > $buildResult = system(@args);
>
> use strict;
> use warnings;
>
> > #The following write to build.log
> > #--Build Item A
> > #compiling a1.cpp
> > #compiling a2.cpp
> > ...
> > #--Build Item B
> > #compiling b1.cpp
> > #compiling b2.cpp
> > ...
> >
> > At the same time, how do I only print the following on the screen?
> > #To screen
> > Build Item A
> > Build Item B
> >
> > Do I need to start a another process in order to do it?
> > How do I filter the STDOUT(to file) at the same time output to screen?
>
> use a pipe instead of system
------------------------------
Date: Sat, 3 Jul 2004 01:05:09 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Newbie: How do I filter output to the screen and writing the orginal output to a file?
Message-Id: <slrncecj4l.ag4.tadmc@magna.augustmail.com>
Mav <mluvw47@yahoo.com> wrote:
> I need to execute (using system(@args)) in order to get the output.
system() does not give you the output!
You need something else ("perldoc -f system" may suggest what "else" is).
[ snip 50 lines of upside-down full-quote.
Please do not do that.
]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 02 Jul 2004 17:11:36 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Newbie: How do I filter output to the screen and writing the orginal output to a file?
Message-Id: <40e5dd99$0$189$58c7af7e@news.kabelfoon.nl>
Mav wrote:
> Hi, all
>
>
> I need to write a perl script that execute (using system) command
> to do build.
>
> While it is doing the build, I would like to print out the item is
> build on the screen,
> the orginal build output will go to the a log file (build.log).
>
>
> @args = ("\"$devPath\\devenv.com\" Solution\\my.sln /build Release");
>
> open (OLDSTDOUT, ">&STDOUT") or die "Couldn't dup STDOUT: $!";
> open(STDOUT, "> build.log") || die "Can't redirect stdout";
use or or || this is confusing.
> #once this execute it starts writing to build.log
> $buildResult = system(@args);
use strict;
use warnings;
> #The following write to build.log
> #--Build Item A
> #compiling a1.cpp
> #compiling a2.cpp
> ...
> #--Build Item B
> #compiling b1.cpp
> #compiling b2.cpp
> ...
>
> At the same time, how do I only print the following on the screen?
> #To screen
> Build Item A
> Build Item B
>
> Do I need to start a another process in order to do it?
> How do I filter the STDOUT(to file) at the same time output to screen?
use a pipe instead of system
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 02 Jul 2004 22:06:00 -0500
From: Dale Henderson <nilram@hotpop.com>
Subject: Re: Newbie: How to I extract word
Message-Id: <87k6xldc2v.fsf@camel.tamu-commerce.edu>
>>>>> "JM" == Josef Moellers <josef.moellers@fujitsu-siemens.com> writes:
JM> Dale Henderson wrote:
>> The following makes no such assumption:
>> my $project = $string =~ /Project: ([^,]+),/;
JM> Nitpicking: That's not what Mav wrote and it's not even
JM> correct:
What isn't what Mav wrote?
As to the correctness, I know better than to post untested code.
The correct version is:
my ($project) = $string =~ /Project: ([^,]+),/;
JM> my $project;
JM> ($project = $string) =~s/.*Project:([^,]+),.*/$1/;
JM> At least with Perl v5.8.1 without the parentheses around the
JM> assignment, the value of $project is 1
Yes. the problem is without the parenthesis, the replacement is
being evaluated in scalar context and returning the number of
matches. Not the first match which is what you want.
An equivalent way to do this is:
(my $project = $string) =~ s/.*Project:([^,]+),.*/$1/;
However, this makes $project pointless since the replacement
modifies $string to be the $1 and then $project is assigned the
value of $string.
Note also your solution leaves a leading space returning
" Myproject" not "Myproject" which is what the OP requested but
at the same time requested everything between "Project:" and
",". So we have a specification error. I suspect the OP wanted to
eliminate leading spaces (and possibly trailing ones) which can
be done with
my ($project)=$string=~/Project:\s*([^,]+),/
JM> with the "my", I get "Can't declare scalar assignment in "my"
JM> at - line 2, near ") =~"" without the substitution, I get the
JM> entire string,
That's because your assigning $project to $string and ignoring the
match.
JM> without the .*'s, I get another string.
You need the .*'s to delete the rest of the string. Your
essentially replacing $string with $1.
JM> You can also specify "non-greedyness": ($project = $string) =~
JM> s/.*Project:(.*?),.*/$1/;
A negated character class is the "right" answer in this case. For
one reason its more efficient. For a discussion of why you should
choose a negated character class over a non-greedy regex see
"Mastering Regular Expressions" (Owl) 1st edition pgs 226-227.
The way I would normally implement this is something like:
my $project;
if($string=~/Project:\s+([^,]+),/){
$project=$1;
}else{
print "Bad string: $string\n"
}
But this may not be necessary in this case.
--
Dale Henderson
"Imaginary universes are so much more beautiful than this stupidly-
constructed 'real' one..." -- G. H. Hardy
------------------------------
Date: 2 Jul 2004 22:56:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Q: re the kind of reference to be bless()ed in OO perl
Message-Id: <cc4p7f$gmf$1@mamenchi.zrz.TU-Berlin.DE>
<nobull@mail.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<cc3b4u$jcg$1@mamenchi.zrz.TU-Berlin.DE>...
> > Brian McCauley <nobull@mail.com> wrote in comp.lang.perl.misc:
> > > Michele Dondi <bik.mido@tiscalinet.it> writes:
> >
> > [...]
> >
> > > > Now I wonder if there are common/cool/smart/witty cases in which it is
> > > > natural to use a reference to some other kind of object, like e.g. a
> > > > sub, or filehandle, etc.
> > >
> > > tied) array and hashes. You can't sensibly define the %{} operator if
> > > the object is itself a blessed hash.
> >
> > Well, you can, for relaxed values of "sensibly".
> >
> > The trick is to make the overloading accessor caller dependent:
> >
> > sub as_hash {
> > my $ob = shift;
> > return $ob if caller eq __PACKAGE__;
>
> That's too relaxed a definition of sensible for me. It means that
> every access to the blessed hash has to go throught the accessor.
> This is rather a high price to pay.
Well, if it's fast enough, it's fast enough. Sometimes brute force
is what you need, temporarily or for good. The technique has helped
me to establish inheritance between otherwise incompatible classes.
Anno
------------------------------
Date: Sat, 03 Jul 2004 02:11:07 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: threads and getlocaltime
Message-Id: <2kmc3pF46j3jU1@uni-berlin.de>
Charlie wrote:
> So the question I have is does anyone know other api that I can
> use, which give me the local time in mseconds and is thread safe ?
Have you tried Time::HiRes?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 2 Jul 2004 18:40:10 -0700
From: cam@ntwk.net (Cameron)
Subject: win32::job window attributes
Message-Id: <e4dad21a.0407021740.7ee5cec5@posting.google.com>
Hello All --
I am trying to launch a windows application either in the background
or with a minimized window using the following code:
my $job = Win32::Job->new;
$job->spawn(q{D:\Link32\Link32.exe}, q{Link32.exe}, {
stdout => 'output.txt',
stderr => 'error.txt',
window_attr => 'hidden'
});
The app is spawned successfully, but no matter how I try to redirect
stdout or set window_attr to hidden or minimized, it launches full screen.
Any thoughts or suggestions appreciated. I am not married to this module, so
if anyone has done this successfully in the past using something else, I'll
give it a try.
Thnx,
Cameron
------------------------------
Date: 2 Jul 2004 22:49:23 GMT
From: Douglas Hunter <dug@plusthree.com>
Subject: Re: Writing installation script with Perl?
Message-Id: <slrncebpgb.2v3.dug@plusthree.com>
On 2004-06-30, minjie <minjie@excite.com> wrote:
> Hello,
>
> Does anyone have experience in writing installation script with Perl?
> Is it feasible to use Perl to package programs for installation, if I
> do not use a professional installation buidling tool (such as
> InstallShield)? If so, is there any Perl module for this purpose?
> Where can I find examples?
Krang (http://krang.sourceforge.net/) has a nice set of install scripts.
/bin/krang_build is a nice place to start.
>
> Note: I need to build installation packages for both Windows and
> Linux.
>
> Thanks.
-- Douglas Hunter
------------------------------
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 6762
***************************************