[19191] in Perl-Users-Digest
Perl-Users Digest, Issue: 1386 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 26 14:10:39 2001
Date: Thu, 26 Jul 2001 11:10:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <996171011-v10-i1386@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 26 Jul 2001 Volume: 10 Number: 1386
Today's topics:
Re: sortlen -- filter to sort text by line length (Yves Orton)
Re: THIS GUY NEEDS A BULLET <bardley90@hotmail.com>
Transporting .db files? (Phil Kerpen)
Re: What am I doing wrong with this command line ? <holland@origo.ifa.au.dk>
Re: What am I doing wrong with this command line ? test@localhost.localdomain
What's the idiomatic way for this? (Alex)
What's the idiomatic way for this? (Alex)
Re: What's the idiomatic way for this? <ilya@martynov.org>
Re: What's the idiomatic way for this? <Thomas@Baetzler.de>
Re: What's the idiomatic way for this? <wolfram.pfeiffer@bigfoot.com>
Re: Where are the values stored? (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Jul 2001 08:35:46 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: sortlen -- filter to sort text by line length
Message-Id: <74f348f7.0107260735.20ec735d@posting.google.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3B54F150.7408211B@earthlink.net>...
> How does ST compare with GRT or with basic/custom sort?
>
> Here's a possibility for a way to speed up ST... Modern perls are able
> to replace function of the forms:
> { $a cmp $b }, { $b cmp $a }, { $a <=> $b }, { $b <=> $a }
> With calls to builtin sort functions, so they can be just as fast as the
> default sort. If perl could be made to recognize when it is doing a
> simple (cmp or <=>) comparison of $a->[0] to $b->[0], then we could make
> the sort part of ST almost as fast as the default sort. Possibly, perl
> could also recognize when map is being called with { $_->[1] } as it's
> sub, and replace that, too, with a special map.
After reading the thread I did a bunch of benchmarks. It looks like
ST is actually pretty bad. I even tried using super long strings to
try to cause trouble for the GRT types substr() operation, but that
seemed to have a more profound effect on the ST than on the GRT, which
quite frankly suprised me.
I dont really understand why combining the use of a substr and a pack
foreach element is faster than sticking them in an array and pulling
them out?? Frankly these results to me are suprising, unless your
comments above about the optimizations that perl does are the
explanation. If so then your ideas about extending such optimizations
to cover ST seem like a good idea. (If not then Id really like to know
why the ST gets hit so much more than the others.) Especially when you
consider that many sorting tasks are on datasets where it is not
possible to use the techniques of embedding the key in the data in the
way we have been discussing (such as objects, or lists of lists
or....)
A minor question: What does GRT stand for?
Yves
------------------------------
Date: Thu, 26 Jul 2001 12:19:29 -0500
From: "Brad G" <bardley90@hotmail.com>
Subject: Re: THIS GUY NEEDS A BULLET
Message-Id: <BiY77.7$Xi1.12862@nnrp3.sbc.net>
I know this post was off topic and has no place in our Perl forum, but since
it's here and people will undoubtedly read it (and I can't stand those who
insult our intelligence), I'd like to point out that Hal Turner is a true
American, and the bonehead who posted this message is not.
Freedom of Speech means being able to express your opinions without fear of
government intervention. What Hal Turner writes is no different than any
newspaper editorial column, but slightly more outspoken because it's on a
website and therefore exempt from any kind of standards. However, this
right, last time I checked, has been established and upheld for the last 225
years or so. To say that Mr. Turner needs a bullet for expressing his
opinion is much more reprehensible than the petty opinions expressed on this
website.
Hal Turner disgusts me. I find his views vile and immature, and exactly the
kind of tripe you'd expect from a small mind, but I made the choice to go to
his website and read what he had to say and reject it, without making a
feeble plea to others to oppress him. Any rational person would do the
same.
------------------------------
Date: 26 Jul 2001 09:31:39 -0700
From: usenet@hsdebate.com (Phil Kerpen)
Subject: Transporting .db files?
Message-Id: <28a0599.0107260831.596069df@posting.google.com>
I recently moved my web site from addr.com (FreeBSD) to
phpwebhosting.com (Redhat Linux).
Some of the perl scripts I use store data in .db hash files. The new
server is unable to access these files. What is the best way to
transport these files? (Unbuild them and rebuild them? How?)
Thanks.
------------------------------
Date: 26 Jul 2001 17:18:44 +0200
From: Steve Holland <holland@origo.ifa.au.dk>
Subject: Re: What am I doing wrong with this command line ?
Message-Id: <w47elr3hg6j.fsf@origo.ifa.au.dk>
Michael Budash <mbudash@sonic.net> writes:
> In article <Y4i2TTP3B2X7EwtR@gratiano.zephyr.org.uk>, James Coupe
> <james@zephyr.org.uk> wrote:
> > In message <vbG77.111898$E4.3052502@amsnews02.chello.com>, Ken Laird
> > <kenlaird@yahoo.com> writes
> > >So I'm trying something like this
> > >perl -e 'for (`ls -la`) {next if /file2/;print}'
> > >but it doesn't work.
> > Irrespective of whether this would do what you want anyway, you might
> > want to put a semi-colon in after your print statement.
> he might, but he doesn't need to (either way compiles)... it'd just
> be good form, kinda like using your turn signal even when there's
> noone around: then you won't forget when people *are* around...
Or, mor importantly, you always use your turn signal in case
there is someone around that you did not see. The same is true with
semi-colons after the last statement: they protect you against
something unforeseen that might happen. For example, what if someone
adds more statements at a later date and forgets to check the earlier
code for semi-colons? Or, what if that segment of code gets imported
into another routine? Another reason to include the final semi-colon
is that it makes each statement the same. By that I mean that each
statement can be recognised as a complete statement with-out having to
worry about where the statement is in the routine.
=====================================================================
To find out who and where I am look at:
http://www.nd.edu/~sholland/index.html
=====================================================================
------------------------------
Date: Fri, 27 Jul 2001 01:54:48 +1000
From: test@localhost.localdomain
Subject: Re: What am I doing wrong with this command line ?
Message-Id: <3B603D48.B2622B49@localhost.localdomain>
Ken Laird wrote:
> ls -la
>
> file1
> file2
> file3
> file4
>
> I'd like to get the next line if /file2/ matches.
>
> So I'm trying something like this
>
> perl -e 'for (`ls -la`) {next if /file2/;print}'
>
> but it doesn't work.
>
> I tried with shift instead of next , but doesn't work either.
>
> What am I doing wrong?
>
> Thanks in advance for any suggestions.
>
> Ken Laird
You're not doing anything wrong:
[test@localhost /tmp]% mkdir z
[test@localhost /tmp]% cd z
[test@localhost /tmp/z]% touch file1 file2 file3
[test@localhost /tmp/z]% ls -la
total 8
drwxr-xr-x 2 test users 4096 Jul 27 01:52 .
drwxrwxrwt 6 root root 4096 Jul 27 01:51 ..
-rw-r--r-- 1 test users 0 Jul 27 01:52 file1
-rw-r--r-- 1 test users 0 Jul 27 01:52 file2
-rw-r--r-- 1 test users 0 Jul 27 01:52 file3
[test@localhost /tmp/z]% perl -e 'for (`ls -la`) {next if
/file2/;print}'
total 8
drwxr-xr-x 2 test users 4096 Jul 27 01:52 .
drwxrwxrwt 6 root root 4096 Jul 27 01:51 ..
-rw-r--r-- 1 test users 0 Jul 27 01:52 file1
-rw-r--r-- 1 test users 0 Jul 27 01:52 file3
[test@localhost /tmp/z]%
cheerz
------------------------------
Date: 26 Jul 2001 08:29:10 -0700
From: samara_biz@hotmail.com (Alex)
Subject: What's the idiomatic way for this?
Message-Id: <c7d9d63c.0107260729.2288d71a@posting.google.com>
Hi,
I wrote this code for printing days in a calendar. The way it works is
I have @grid array, which always has 42 elements. (Since maximum
number of weeks is 6, 6*7 = 42). What I do I just print it 7 elements
in a row.
Here's the code:
for( my $i = 1; $i < 7; $i++ ){
print("<tr align=\"right\">\n");
my $s_ind = ($i - 1) * 7;
my $e_ind = $s_ind + 6;
foreach (@grid[$s_ind..$e_ind]){
print("<td>" . ($_ == 0 ? ' ' : $_ ) . "</td>\n");
} #foreach
print("<td width=\"20%\" align=\"right\">\<$i</td>\n");
print("</tr>\n");
} #for
I was wondering if there's a way to rewrite this in a more idiomatic
way. I have a feeling that I don't really need to use for() loop or
compute slice indexes on two separate lines, but I can't think of a
better way to write this.
Can anyone show me a better way?
Thanks a lot!
Alex
------------------------------
Date: 26 Jul 2001 08:29:10 -0700
From: samara_biz@hotmail.com (Alex)
Subject: What's the idiomatic way for this?
Message-Id: <c7d9d63c.0107260729.26b8316b@posting.google.com>
Hi,
I wrote this code for printing days in a calendar. The way it works is
I have @grid array, which always has 42 elements. (Since maximum
number of weeks is 6, 6*7 = 42). What I do I just print it 7 elements
in a row.
Here's the code:
for( my $i = 1; $i < 7; $i++ ){
print("<tr align=\"right\">\n");
my $s_ind = ($i - 1) * 7;
my $e_ind = $s_ind + 6;
foreach (@grid[$s_ind..$e_ind]){
print("<td>" . ($_ == 0 ? ' ' : $_ ) . "</td>\n");
} #foreach
print("<td width=\"20%\" align=\"right\">\<$i</td>\n");
print("</tr>\n");
} #for
I was wondering if there's a way to rewrite this in a more idiomatic
way. I have a feeling that I don't really need to use for() loop or
compute slice indexes on two separate lines, but I can't think of a
better way to write this.
Can anyone show me a better way?
Thanks a lot!
Alex
------------------------------
Date: 26 Jul 2001 19:53:45 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: What's the idiomatic way for this?
Message-Id: <87puanhek6.fsf@abra.ru>
A> Hi,
A> I wrote this code for printing days in a calendar. The way it works is
A> I have @grid array, which always has 42 elements. (Since maximum
A> number of weeks is 6, 6*7 = 42). What I do I just print it 7 elements
A> in a row.
A> Here's the code:
A> for( my $i = 1; $i < 7; $i++ ){
A> print("<tr align=\"right\">\n");
A> my $s_ind = ($i - 1) * 7;
A> my $e_ind = $s_ind + 6;
A> foreach (@grid[$s_ind..$e_ind]){
A> print("<td>" . ($_ == 0 ? ' ' : $_ ) . "</td>\n");
A> } #foreach
A> print("<td width=\"20%\" align=\"right\">\<$i</td>\n");
A> print("</tr>\n");
A> } #for
A> I was wondering if there's a way to rewrite this in a more idiomatic
A> way. I have a feeling that I don't really need to use for() loop or
A> compute slice indexes on two separate lines, but I can't think of a
A> better way to write this.
A> Can anyone show me a better way?
A> Thanks a lot!
Your code can rewriten in many ways but IMHO there is no too much
sense to do it.
You need to make some output for each week (<tr> and </tr>). So it is
natural to have a loop for it.
Any you have to make some output for each day in a week
(<td>...</td>). Thus it is natural to have second loop or use map.
IMHO unless another variant is slight modification of yours code it
will not be natural and thus it will have algorithm which is hard to
read.
If you are interested here my variant with cosmetic changes:
for my $i (1 .. 6) {
print("<tr align=\"right\">\n");
my $s_ind = ($i - 1) * 7;
my $e_ind = $s_ind + 6;
print map "<td>" . ($_ == 0 ? ' ' : $_ ) . "</td>\n",
@grid[$s_ind .. $e_ind];
print("<td width=\"20%\" align=\"right\">\<$i</td>\n");
print("</tr>\n");
} #for
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Thu, 26 Jul 2001 18:39:06 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: What's the idiomatic way for this?
Message-Id: <vph0mts12m0q6l58v1r9erago8p53ppn30@4ax.com>
Hi,
On 26 Jul 2001, samara_biz@hotmail.com (Alex) wrote:
>I wrote this code for printing days in a calendar. The way it works is
>I have @grid array, which always has 42 elements. (Since maximum
>number of weeks is 6, 6*7 = 42). What I do I just print it 7 elements
>in a row.
[...]
How'bout this?
--------8<----( cut here )----8<--------
#!/usr/bin/perl -w
use strict;
my @data;
# just some dummy data to print each day
for( my $i = 1; $i <= 31; $i++ ){ push @data, $i; }
# what are my days called?
my @days = qw( Mon Tue Wed Thu Fri Sat Sun );
sub print_calendar {
my( $start, $refdata ) = @_;
if( 0 <= $start && $start <= 6 ){
# print day headings
print "<table>\n<tr>", map( { "<th>$_</th>" } @days), "</tr>\n";
# pad the first days if month doesn't start on a Monday
if( $start ){
print "<tr>", "<td> </td>"x$start;
}
my $dayidx = $start;
# for each day: print data
# insert <tr> and </tr> as necessary
foreach my $day ( @$refdata ){
if( $dayidx == 0 ){
print "<tr>";
}
print "<td>$day</td>";
if( ++$dayidx == 7 ){
print "</tr>\n";
$dayidx = 0;
}
}
# print the last line(s)
if( $dayidx ){
print "<td> </td>"x(7-$dayidx), "</tr>\n</table>\n";
} else {
print "</table>\n";
}
} else {
die "Illegal day - must be 0..6\n";
}
}
# 1st parameter: wkday (0..6) ~ (Mon..Sun) that the month starts
# 2nd parameter: ref to array with data to print for each day
#
print_calendar( 6, \@data );
exit;
--------8<----( cut here )----8<--------
HTH,
--
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.
------------------------------
Date: 26 Jul 2001 17:42:46 GMT
From: Wolfram Pfeiffer <wolfram.pfeiffer@bigfoot.com>
Subject: Re: What's the idiomatic way for this?
Message-Id: <9jpkqm$l88$1@news.rz.uni-karlsruhe.de>
Thomas Bätzler <Thomas@baetzler.de> wrote:
[snip]
> my @data;
> # just some dummy data to print each day
> for( my $i = 1; $i <= 31; $i++ ){ push @data, $i; }
Why not:
my @data = (1..31);
[snip]
> sub print_calendar {
> my( $start, $refdata ) = @_;
> if( 0 <= $start && $start <= 6 ){
[snip]
Instead of:
if (everything_ok) {
code;
code;
code;
...
} else {
die "error";
}
I suggest:
everything_ok
or die "error";
code;
code;
code;
...
-Wolfram
------------------------------
Date: 26 Jul 2001 15:55:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Where are the values stored?
Message-Id: <9jpegk$2u1$1@mamenchi.zrz.TU-Berlin.DE>
According to Yves Orton <demerphq@hotmail.com>:
> ebohlman@omsdev.com (Eric Bohlman) wrote in message
> news:<9jn4eh$3qj$1@bob.news.rcn.net>...
> > Jonas Nilsson <nospam.jonni@ifm.liu.se> wrote:
> > > Try this:
>
> <SNIP>
>
> > > I know that use strict; tells you something like: Can't use string ("First
> > > value") as a HASH ref while "strict refs" in use at D:\Slask\clpm002.pl line
> > > 6.
> >
> > It's as the message says. $hash{A} contains the literal string "First
> > value" which is used as a symbolic reference to a hash whose name is what
> > the symbol table would contain if you could actually use a variable name
> > called "%First value". That hash has one key, B, whose value is "Second
> > value". If you had written "Firstvalue" without a space, you'd have
> > created a hash variable whose name you could actually use, and you'd find
> > that $Firstvalue{B} was "Second value".
>
> Hmm, very intetresting. So because its not running under strict a new
> hash with a space in its name is created? But this is not accessable
> except through something like %{'First value'}? Is that right?
Quite. Those are the dreaded symrefs. Besides randomly accessing
variables you may use in your program, they also create variables
you *can't* access from your program (except by more symrefs).
> Seems like a damn good argument to always 'use strict'. Not like we
> need more reasons but.... :-)
Well, avoiding inadvertent symrefs *is* among the chief reasons why
strict programming is recommended. The combination of (normal) auto-
vivification and an (unintended) symref when a place meant for a
reference happens to hold a scalar is particularly confusing, because
everything seems to work normally... up to a point. Just a few days
ago we had a thread where it was autivivification of a filehandle
vs. a symbolic indirect filehandle when the filehandle variable happened
to be defined. Here we had the same thing with a hash of hashes.
Always use strict.
Anno
------------------------------
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 1386
***************************************