[27570] in Perl-Users-Digest
Perl-Users Digest, Issue: 9105 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 30 06:05:58 2006
Date: Thu, 30 Mar 2006 03:05:06 -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 Thu, 30 Mar 2006 Volume: 10 Number: 9105
Today's topics:
Re: file renamer... request feedback <noone@nowhere.com>
Re: file renamer... request feedback <rvtol+news@isolution.nl>
Re: Find duplicates in a dat file (Anno Siegel)
Re: for loop is not going to all array elements (Anno Siegel)
Re: More help requested on permutation code. <jack@abc.net>
NetServer::Generic -- welcome message ?? <babacio@free.fr>
Where to put Settings-Variables? <bernd_schneid@web.de>
Re: Where to put Settings-Variables? jussi.mononen-asdf@asdf-comptel.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 30 Mar 2006 06:19:47 GMT
From: TOC <noone@nowhere.com>
Subject: Re: file renamer... request feedback
Message-Id: <7MKWf.315$Zf2.275@fe12.news.easynews.com>
"Dr.Ruud" <rvtol+news@isolution.nl> wrote in news:e0ek0d.1g0.1
@news.isolution.nl:
> Tad McClellan schreef:
>
>> Tacking a character onto the end should *look like* you are
>> tacking a character onto the end:
>>
>> $_ .= '_';
>
> Alternative: s/$/_/;
>
> (but I like your concat better)
>
thanks... eventually I'll make the variable names longer, and add
comments.
#!/usr/bin/perl
use strict;
use warnings;
use Fatal;
use File::Find;
finddepth( \&f, "." );
sub f
{
return if /^\./ or /lost\+found/;
my $o = $_;
$_ = lc $_;
y/a-z0-9._/_/c;
s/^_+//;
s/\.mpeg$/.mpg/;
s/\.ram$/.rm/;
s/\.qt$/.mov/;
s/\.jpeg$/.jpg/;
y/_//s;
y/.//s;
s/_\././g;
s/\._/_/g;
if ( $_ ne $o )
{
while ( -e $_ )
{
print "\n $File::Find::dir/$_ already exists \n";
if (/\./)
{
s/^(.*)\.(.*)$/$1_.$2/
; # insert an "_" between the filename and it's
extension
}
else
{
$_ .= '_'; # append an "_"
}
}
if ( $ARGV[0] ) # do a dry-run
{
print "\n $File::Find::name -> \n $File::Find::dir/$_\n";
}
elsif ( rename $o, $_ )
{
print "\n $File::Find::name -> \n $File::Find::dir/$_\n";
}
else
{
warn "\n failed to rename $o to $_, left as $o\n ";
}
}
}
------------------------------
Date: Thu, 30 Mar 2006 10:34:10 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: file renamer... request feedback
Message-Id: <e0gcgo.1kk.1@news.isolution.nl>
TOC schreef:
> my $o = $_;
> $_ = lc $_;
Can be combined: my $o = lc;
(see `perldoc -f lc`)
> s/^(.*)\.(.*)$/$1_.$2/
No need for the second capture group:
s/^(.*)\./$1_./
No need even for the first:
s/\.(?=[^.]*$)/_./
Test: echo 'abc.def.ghi' | perl -pe 'chomp; s/\.(?=[^.]*$)/_./'
(I haven't benchmarked them, but it feels 'just good' to avoid
capturing.)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 30 Mar 2006 08:24:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Find duplicates in a dat file
Message-Id: <491ituFmacfpU1@news.dfncis.de>
Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> axel@white-eagle.invalid.uk <axel@white-eagle.invalid.uk> wrote:
> > Tami@des.com wrote:
> >>>If you concatenated all the files into a single file, this should work
>
> > Or you could pipe the files into a perl script:
> >
> > cat *.dat | myscript.pl
> >
> > and read the data from standard input.
>
>
> Or you could put the filenames as command line arguments
> and read the data from the diamond operator.
>
> myscript.pl *.dat
>
> (well, you could if you had a sensible shell.)
The problem with concatenating all files together is that it tells
you whether there are duplicate mail addresses, but not which users
the duplicates belong to. With the files in @ARGV, the $ARGV variable
can be used to capture at least the file names the duplicates come from.
Untested:
my %seen;
push $seen->{ $1}, $ARGV if /(.*@.*)/;
while ( my ( $addr, $files) = each %seen ) {
print "$addr found in files @$files\n" if @$files > 1;
}
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: 30 Mar 2006 09:19:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: for loop is not going to all array elements
Message-Id: <491m4gFm9bpkU1@news.dfncis.de>
Brandon Hoppe <bhoppe@ti.com> wrote in comp.lang.perl.misc:
> Hi,
>
> I have a for loop that loops that an array. Inside the for loop, I push
> more elements onto the array if needed, but the loop is stopping at the
> original end of the array and not looping thru the new additions.
No surprise there. Read up on "foreach" in perlsyn. It explicitly
warns against what you are doing.
> Basicall, this is what I have:
>
> $line = "-name SSCC34234342 -views ,Datasheet,Verilog!BREAK!";
> @wow = ();
> push(@wow, $line);
>
> foreach $inline (@wow) {
> print "LINE: $inline\n";
>
> if($inline =~ /SSCC/) {
> $newline = $inline;
> $newline =~ s/SSCC/BRGS/;
> push(@wow, $newline);
> }
> }
You're running without strictures (and probably without warnings).
Switch them on. They don't make a difference here, but they make
your code easier to check.
Use a while loop instead:
while ( @wow ) {
my $inline = shift @wow;
# ...
}
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Thu, 30 Mar 2006 09:34:45 GMT
From: Michael Press <jack@abc.net>
Subject: Re: More help requested on permutation code.
Message-Id: <jack-436AE1.01344530032006@newsclstr02.news.prodigy.com>
In article <48l0h9Fkpb7mU1@news.dfncis.de>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> Michael Press <jack@abc.net> wrote in comp.lang.perl.misc:
> > In article <48igj9Fkdg2tU1@news.dfncis.de>,
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> > > What are all the single-element cycles for? They map to the unit
> > > permutation and have no effect.
> >
> > These are (redundant) generators of a real world group. As
> > you see in the next bit of code, if the singletons were
> > not present in $beta, then the result of
> > permutation_multiply $beta and
> > permutation_multiply ($alpha x 2 ...
> > would not be the same.
>
> Hmm... Well, permutation_multiply() does more than its name implies
> (printing out results on its own). Otherwise, the result of a permutation
> multiplication should be independent of (redundant) singleton cycles
> in the specification of the factors.
Yes, it should be factored out. I wrote the code as an
adjunct to some reading.
> You appear to use the singletons as some kind of marker.
No, not a marker. They are parts of the definitions of
their respective automorphisms.
> I haven't seen
> that technique before, and computationally it strikes me as cumbersome.
> I'd try to make those markers independent of the basic permutation
> operations.
I do not follow this. I want to _see_ the fixed points
when I print out the permutation. Why do you want to
delete them for me?
Cumbersome is not knowing the domain of the permutation.
> > But more importantly these are generators of
> > PSL_2 (GF_23), the group of automorphisms over the
> > projective line in GF_23. GF_23 has 23 elements:
> > {0, 1, ... 23}. The projective line has 24 elements:
> > {infinity, 0, 1, ... 23}. (I use 99 for infinity).
> >
> > Since the permutation beta is an automorphism, we must
> > define its behavior on every point.
>
> Huh? If it were only an endomorphism we wouldn't have to define
> its behavior in every point? I don't understand that argument.
I am not interested in these permutations as
endomorphisms. They are interesting as automorphisms.
An endomorphism B need not satisfy B(xy)= B(x)B(y). An
automorphism must be defined at each element of the
domain.
> > group elements are important in the analysis, so it is
> > better when reading to see the singletons explicitly,
> > rather than trying to infer them. For instance
> > (alpha delta)^3 = (0) (1) (5) (6) (18) (20) (22) (99)
> > (2 3) (4 15) (7 8) (9 11) (10 19) (12 16) (13 21) (14 17)
>
> The fixed points of a permutation are exactly the elements that
> don't appear in a cycle of length > 1. Computationally that's
> very simple (once you have the non-singleton cycles).
If I delete one-cycles, then I must carry around the
domain of the permutations in my head. I have better uses
for that space. If I know that the permutation explicitly
defines the transformation, than I know the domain. In
these investigations more than one set of elements and
their permutation groups are considered at the same time.
Computers were invented to carry out tedious calculations.
--
Michael Press
------------------------------
Date: Thu, 30 Mar 2006 12:04:45 +0200
From: Babacio <babacio@free.fr>
Subject: NetServer::Generic -- welcome message ??
Message-Id: <m2u09gqmde.fsf@baba.ba>
Hi,
I try to use NetServer::Generic. Let's look to the example of the doc.
(I copy/paste it).
my $server_cb = sub {
my ($s) = shift ;
print STDOUT "Echo server: type bye to quit, exit ",
"to kill the server.\n\n" ;
while (defined ($tmp = <STDIN>)) {
return if ($tmp =~ /^bye/i);
$s->quit() if ($tmp =~ /^exit/i);
print STDOUT "You said:>$tmp\n";
}
}
my ($foo) = new NetServer::Generic;
$foo->port(9000);
$foo->callback($server_cb);
$foo->mode("forking");
print "Starting server\n";
$foo->run();
The problem is that when connecting to the server (let's say with
telnet or Net::Telnet), the welcome message is displayed only after
the client sent something. Any hint ?
------------------------------
Date: Thu, 30 Mar 2006 16:34:13 +1000
From: Bernd Schneider <bernd_schneid@web.de>
Subject: Where to put Settings-Variables?
Message-Id: <442b6e36@dnews.tpgi.com.au>
Hello!
I am developing a small web-based application (customer-frontend).
It used to be quite small so that I keeped everything in one file
(index.pl). In the head I defined all the variables etc. and that was it.
But now the application is getting a bit more complex with some scripts
being only run from the command line and having nothing to do with the
web-interface yet still sharing some common library.
So I decided to put some stuff into modules.
The problem that I now come up with is:
Where do I put the variables?
Before I just declared them as:
my $mysql_host = 'localhost';
[...]
Now I have several packages and they in turn use these variables as well.
I now use a self-written script which reads the variables from a
textfile. And I put all this into a Module called Settings.pm.
So my call to a setting would be:
$Settings::value{'key'}
e.g.
$Settings::value{'mysql_host'}
But I am not too sure if this is the right way.
Do you have any hints to to deal with these settings properly?
Thanks in advance!
------------------------------
Date: Thu, 30 Mar 2006 09:13:37 +0000 (UTC)
From: jussi.mononen-asdf@asdf-comptel.com
Subject: Re: Where to put Settings-Variables?
Message-Id: <e0g7g0$6nr$1@phys-news4.kolumbus.fi>
Bernd Schneider <bernd_schneid@web.de> wrote:
>
> So I decided to put some stuff into modules.
>
> The problem that I now come up with is:
> Where do I put the variables?
>
> Before I just declared them as:
> my $mysql_host = 'localhost';
> [...]
>
> Now I have several packages and they in turn use these variables as well.
>
> I now use a self-written script which reads the variables from a
> textfile. And I put all this into a Module called Settings.pm.
> So my call to a setting would be:
> $Settings::value{'key'}
> e.g.
> $Settings::value{'mysql_host'}
>
> But I am not too sure if this is the right way.
It is much better than using 'our'. You have them stashed
in their own namespace and thus reduced the possibility
to access them by accident.
You could create a configuration/settings object and
access configuration through method calls.
Avoid global parameters in larger programs as they make
the maintenance task really difficult.
/jUSSi
--
remove -asdf and asdf- for email address
------------------------------
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 9105
***************************************