[24585] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6761 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 2 18:05:33 2004

Date: Fri, 2 Jul 2004 15:05:05 -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, 2 Jul 2004     Volume: 10 Number: 6761

Today's topics:
    Re: finding every combination of n values at y position <mritty@gmail.com>
    Re: Logfile name hack <magoo@hal-pc.org>
    Re: Logfile name hack <daedalus@videotron.ca>
    Re: Logfile name hack (J. Romano)
    Re: Logfile name hack <me@privacy.net>
        Newbie: How do I  filter output to the screen and writi (Mav)
    Re: Q: re the kind of reference to be bless()ed in OO p nobull@mail.com
    Re: use integer != int() <nospam-abuse@ilyaz.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 2 Jul 2004 14:20:24 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: finding every combination of n values at y positions
Message-Id: <20040702141223.N16568@barbara.cs.rpi.edu>

On Fri, 2 Jul 2004, 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.

You might want to consult CPAN the next time you feel yourself spending a
crazy amount of time doing anything in Perl.  Chances are, someone's
already done it.

You might also want to check the FAQ, which could possibly tell you if
someone's already done it, and if so, where to find their solution.

In this case,

perldoc -q permute

shows you first a straight Perl solution, which it itself claims is "very
inefficient".  It then tells you about two modules on CPAN which are
faster.  One requires a C compiler (Algoritm::Permute).  One does not
(List::Permutor):
http://search.cpan.org/~phoenix/List-Permutor-0.022/Permutor.pm

Note that this doesn't do *exactly* what you wanted, but it's so similar,
I'd think it'd be trivial to use or modify for your own goals.

Paul Lalli





------------------------------

Date: Fri, 2 Jul 2004 13:10:24 -0500
From: magoo <magoo@hal-pc.org>
Subject: Re: Logfile name hack
Message-Id: <MPG.1b4f610cf73f0b95989685@news.hal-pc.org>

In article <GCgFc.33804$t55.1002118@wagner.videotron.net>, 
daedalus@videotron.ca says...
> > > This creates a series of logfiles named:
> > >   logfile_v1.log
> > >   logfile_v2.log
> > >   etc
> > >
> > > I would be interested in hearing any input concerning creating,
> > > using, logfiles that anyone might want to share.
> 
> Anyway if you want the program to create a new log file each it runs, here's
> an simple example that would more simply do what you initialy wanted:
> 
> my $dir_name = "/your/log/dir/";
> my $file_name = "logfile_v";
> my $version = 1;
> $version++ while -e "$dir_name$filename$version.log";
> my $logfile = "$dir_name$filename$version.log";
> open LOGFILE, ">$logfile" or die "Failed to open LOGFILE: $!";
> 
> This would create : logfile_v1 then logfile_v2 and so on each time it runs.
> 
> DAE
> 
> 
> 
After much consideration, I am going to go with this now:

chomp($date = `date`);
$date =~ s/\s+/_/g;
$logfile = $my_directory/logfile.$date;

output file now is named somthing like:
    logfile.Fri_Jul_2_13:12:57_CDT_2004

Simplicity trumps complexity every time...



------------------------------

Date: Fri, 2 Jul 2004 15:19:05 -0400
From: "Daedalus" <daedalus@videotron.ca>
Subject: Re: Logfile name hack
Message-Id: <cwiFc.33816$t55.1067884@wagner.videotron.net>

> After much consideration, I am going to go with this now:
>
> chomp($date = `date`);
> $date =~ s/\s+/_/g;
> $logfile = $my_directory/logfile.$date;

Anyway your date format is different than the one I got on a w2k box, wich
is something like : Fri. 02-07-2004.
so the line : (my $date = `DATE`) =~ s/[^\d]//g; wich give to $date:
"02072004", wouldn't work as is on you *nix box.

> output file now is named somthing like:
>     logfile.Fri_Jul_2_13:12:57_CDT_2004

Sounds good...  *nix don't mind to have colons (:) in filenames. But this
wouldn't work under a windows or a Mac box since the colons have special
path meanings under these OS. You see if you want your code to be the more
portable possible.

> Simplicity trumps complexity every time...

Yep, as long as the simple gives you what you're looking for.

DAE







------------------------------

Date: 2 Jul 2004 12:34:33 -0700
From: jl_post@hotmail.com (J. Romano)
Subject: Re: Logfile name hack
Message-Id: <b893f5d4.0407021134.102d3ef2@posting.google.com>

magoo <magoo@hal-pc.org> wrote in message news:<MPG.1b4f3310d3e0384a989684@news.hal-pc.org>...
> Just got through writing a program which wrote some output to a logfile.
> 
> Not wanting to overwrite a previous log file, I threw this together:
   <code snipped>
> 
> This creates a series of logfiles named:
>   logfile_v1.log
>   logfile_v2.log
>   etc
> 
> I would be interested in hearing any input concerning creating,
> using, logfiles that anyone might want to share.

   That's a cool hack, but you can shorten it (to basically one line)
with the following:

      # Specify logfile name:
      $logfile = "logfile_v1.log";

      # Loop until we find a log file name that is not used yet:
      $logfile =~ s/(\d+)/$1+1/e  while (-e $logfile);

      # Open log file:
      open(LOGFILE, "> $logfile") or die "Cannot open $logfile: $!";

   Anyway, thanks for sharing your hack, magoo.

   -- Jean-Luc


------------------------------

Date: Sat, 3 Jul 2004 08:51:47 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: Logfile name hack
Message-Id: <2km06cF3vpiuU1@uni-berlin.de>


"magoo" <magoo@hal-pc.org> wrote in message
news:MPG.1b4f610cf73f0b95989685@news.hal-pc.org...
> In article <GCgFc.33804$t55.1002118@wagner.videotron.net>,
> After much consideration, I am going to go with this now:
>
> chomp($date = `date`);
> $date =~ s/\s+/_/g;
> $logfile = $my_directory/logfile.$date;
>
> output file now is named somthing like:
>     logfile.Fri_Jul_2_13:12:57_CDT_2004

I would suggest that a better (and certainly more portable) way is:

use POSIX 'strftime';
my $logfile = strftime("logfile-%Y-%m-%d",localtime);




------------------------------

Date: 2 Jul 2004 14:32:10 -0700
From: mluvw47@yahoo.com (Mav)
Subject: Newbie: How do I  filter output to the screen and writing the orginal output to a file?
Message-Id: <dfaafecd.0407021332.46182d9d@posting.google.com>

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";

#once this execute it starts writing to build.log
$buildResult =  system(@args);  

#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?


Thanks,
Mav


------------------------------

Date: 2 Jul 2004 14:19:45 -0700
From: nobull@mail.com
Subject: Re: Q: re the kind of reference to be bless()ed in OO perl
Message-Id: <4dafc536.0407021319.681001ee@posting.google.com>

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.


------------------------------

Date: Fri, 2 Jul 2004 20:57:20 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: use integer != int()
Message-Id: <cc4i7g$ea3$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
suedecold
<suedecold@yahoo.com>], who wrote in article <8dce2b7b.0406261308.a217ddc@posting.google.com>:
> Thanks for the help.  I first thought it may have been
> an overflow problem but my logic said it should have showed
> its self in both subs.  I was not aware that int() kept using
> doubles.

It did not.  But it does nowadays...

So if you have portablility in mind, check when this change was made.
I think I did it about 3 years ago.  Can't find it on p5p archives,
though - so maybe it was not me - but it should be quite recent anyway...

Hope this helps,
Ilya


------------------------------

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 6761
***************************************


home help back first fref pref prev next nref lref last post