[19811] in Perl-Users-Digest
Perl-Users Digest, Issue: 2006 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 25 09:05:43 2001
Date: Thu, 25 Oct 2001 06:05:12 -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: <1004015111-v10-i2006@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 25 Oct 2001 Volume: 10 Number: 2006
Today's topics:
ANNOUNCE: Attribute::Handlers::Prospective 0.01 (Damian Conway)
Re: beginner: leading zerro function <BROWNHIK@Syntegra.Bt.Co.Uk>
Re: beginner: leading zerro function <mgjv@tradingpost.com.au>
beginner: length of split command... <mto@kabelfoon.nl>
Re: beginner: length of split command... <bernard.el-hagin@lido-tech.net>
Re: beginner: length of split command... (Garry Williams)
Re: beginner: length of split command... <mgjv@tradingpost.com.au>
Re: capture image <tintin@snowy.calculus>
Dumping Perl Hashes (Stephen Jayna)
Re: Dumping Perl Hashes <smap@msap.spamm.mapps.net>
Re: Dumping Perl Hashes (Garry Williams)
Re: dynamic DBD::Oracle SELECT? <goldbb2@earthlink.net>
how to call a sub from anywhere? <mto@kabelfoon.nl>
Re: how to call a sub from anywhere? <bernard.el-hagin@lido-tech.net>
Re: lookingglass.pl <mgjv@tradingpost.com.au>
Re: matching <goldbb2@earthlink.net>
Re: matching <please@no.spam>
modification times on Windows files <rtrahan@monmouth.com>
Re: modification times on Windows files <bernard.el-hagin@lido-tech.net>
Re: NEWBIE: double sort on a string <bernard.el-hagin@lido-tech.net>
Re: NEWBIE: double sort on a string <jippie@yahoo.com>
NEWBIE: multiple column sort routine <jippie@yahoo.com>
Re: one-liner solution sought <BROWNHIK@Syntegra.Bt.Co.Uk>
Re: one-liner solution sought <BROWNHIK@Syntegra.Bt.Co.Uk>
Re: Perl Vs. Java <goldbb2@earthlink.net>
Re: Regexp help needed Part 2 <dot@dot.dot>
Re: What the **** is WRONG with this!? <goldbb2@earthlink.net>
Re: What's wrong with File::Find (EED)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 25 Oct 2001 10:49:33 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: ANNOUNCE: Attribute::Handlers::Prospective 0.01
Message-Id: <9r8qnt$vud$1@towncrier.cc.monash.edu.au>
Keywords: perl, module, release
==============================================================================
Release of version 0.01 of Attribute::Handlers::Prospective
==============================================================================
NAME
Attribute::Handlers::Prospective - Enhanced definition of attribute handlers
DESCRIPTION
This module, when inherited by a package, allows that package's class to
define attribute handler subroutines for specific attributes. Variables
and subroutines subsequently defined in that package, or in packages
derived from that package may be given attributes with the same names as
the attribute handler subroutines, which will then be called at the end
of the compilation phase (i.e. in an INIT block).
It offers the following advantages over Attribute::Handlers:
* You can ascribe attributes to anonymous subroutines,
* You can ascribe attributes to a variable in an
'our' declaration,
* You can ascribe attributes to a 'local'-ised variable,
* You can ascribe attributes to 'our'-ed and
'local'-ised typeglobs,
* You can create "default" attribute handlers named
'AUTOATTR' (by analogy to 'AUTOLOAD' subroutines),
* You can create "prefix" attribute handlers named 'PREATTR'
that are executed before the first actual attribute handler of a
declaration,
* You can create "postfix" attribute handlers named 'POSTATTR'
that are executed after the last actual attribute handler of a
declaration,
* You can optionally use the Perl 6 'is attr(...)' syntax,
instead of Perl 5's ':attr(...)'
* You can set up attribute handlers that are executed at run-time.
It's disadvantage is that it does all this via source filtering, rather
than through Perl's built-in attribute mechanism. So it imposes a
significant overhead at start-up, and it may have some robustness issues.
For production code, you should probably stick with Attribute::Handlers
for the time being.
EXAMPLE
package UNIVERSAL;
use Attribute::Handlers::Prospective;
my %name;
sub name { return $name{$_[2]}||*{$_[1]}{NAME} }
sub Name :ATTR(RAWDATA) {
$name{$_[2]} = $_[4]
}
sub Purpose :ATTR(RAWDATA) {
print STDERR "Purpose of ", &name, " is $_[4]\n"
}
sub Unit :ATTR(RAWDATA) {
print STDERR &name, " measured in $_[4]\n"
}
package main;
my $capacity : Name(capacity)
: Purpose(to store max storage capacity for files)
: Unit(Gb);
package Other;
sub foo : Purpose(to foo all data before barring it) { }
AUTHOR
Damian Conway (damian@conway.org)
COPYRIGHT
Copyright (c) 2001, Damian Conway. All Rights Reserved.
This module is free software. It may be used, redistributed
and/or modified under the same terms as Perl itself.
==============================================================================
CHANGES IN VERSION 0.01
(No changes have been documented for this version)
==============================================================================
AVAILABILITY
Attribute::Handlers::Prospective has been uploaded to the CPAN
and is also available from:
http://www.csse.monash.edu.au/~damian/CPAN/Attribute-Handlers-Prospective.tar.gz
==============================================================================
------------------------------
Date: Thu, 25 Oct 2001 12:36:55 +0100
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: beginner: leading zerro function
Message-Id: <9r8tnl$pkm$1@pheidippides.axion.bt.co.uk>
$v=12
print substr('0000' . $v,0,4);
"MAGiC MANiAC^mTo" <mto@kabelfoon.nl> wrote in message
news:9r7fb7$2qv5$1@news.kabelfoon.nl...
> how can I create a function to ad leading zerros before value?...
>
> for example:
>
> $v=12
> print lz($v,4);
>
> result:
>
> 0012
>
> 4 is the total zerros to add before $v
>
> is there someone who like to help me?
>
> thanks!
>
>
>
------------------------------
Date: Thu, 25 Oct 2001 22:10:03 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: beginner: leading zerro function
Message-Id: <slrn9tg08r.23f.mgjv@martien.heliotrope.home>
[Please in the future, put your reply _after_ the suitably trimmed text
you reply to. It is the commonly accepted quoting style on this
newsgroup, and Usenet in general]
On Thu, 25 Oct 2001 12:36:55 +0100,
Kevin Brownhill <BROWNHIK@Syntegra.Bt.Co.Uk> wrote:
> "MAGiC MANiAC^mTo" <mto@kabelfoon.nl> wrote in message
> news:9r7fb7$2qv5$1@news.kabelfoon.nl...
>> how can I create a function to ad leading zerros before value?...
>>
> $v=12
> print substr('0000' . $v,0,4);
Creative. But it's probably easier to just use sprintf and/or printf for
this:
$padded_var = sprintf "%04d", $var;
Martien
--
|
Martien Verbruggen | I'm just very selective about what I
| accept as reality - Calvin
|
------------------------------
Date: Thu, 25 Oct 2001 13:45:18 +0200
From: "MAGiC MANiAC^mTo" <mto@kabelfoon.nl>
Subject: beginner: length of split command...
Message-Id: <9r8u8f$19pj$1@news.kabelfoon.nl>
@split = split(/\|/, $result);
I like to know how I can ask the length of split
(how many lines there is split by the command split(/\|/, $result);
split[0]
split[1]
split[2]
split[3] <- what is the length by split?...
------------------------------
Date: 25 Oct 2001 12:06:15 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: beginner: length of split command...
Message-Id: <slrn9tfvl9.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Thu, 25 Oct 2001 13:45:18 +0200, MAGiC MANiAC^mTo <mto@kabelfoon.nl> wrote:
>
>
> @split = split(/\|/, $result);
>
> I like to know how I can ask the length of split
> (how many lines there is split by the command split(/\|/, $result);
>
> split[0]
> split[1]
> split[2]
> split[3] <- what is the length by split?...
my $length = @split;
print $length;
Cheers,
Bernard
------------------------------
Date: Thu, 25 Oct 2001 12:16:49 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: beginner: length of split command...
Message-Id: <slrn9tg0lh.qbq.garry@zfw.zvolve.net>
On Thu, 25 Oct 2001 13:45:18 +0200, MAGiC MANiAC^mTo <mto@kabelfoon.nl> wrote:
>
>
> @split = split(/\|/, $result);
>
> I like to know how I can ask the length of split
> (how many lines there is split by the command split(/\|/, $result);
$number_of_elements = @array;
From the perldata manual page:
If you evaluate an array in scalar context, it returns the length
of the array.
--
Garry Williams
------------------------------
Date: Thu, 25 Oct 2001 22:12:29 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: beginner: length of split command...
Message-Id: <slrn9tg0dd.23f.mgjv@martien.heliotrope.home>
On Thu, 25 Oct 2001 13:45:18 +0200,
MAGiC MANiAC^mTo <mto@kabelfoon.nl> wrote:
>
>
> @split = split(/\|/, $result);
>
> I like to know how I can ask the length of split
> (how many lines there is split by the command split(/\|/, $result);
>
> split[0]
> split[1]
> split[2]
> split[3] <- what is the length by split?...
I think you are asking how you can find how many elements the array
@split has?
The answer is: use @split in a scalar context:
my $n_elements = @split;
if (@split > 3)
{
print "\@split has more than three elements\n";
}
See the perldata documentaiton for more information[1].
Martien
[1] Use man on Unix, perldoc on Unix or DOS-derived OSes, Shuck on Mac,
and/or browse HTML pages on ActiveState installations.
--
|
Martien Verbruggen | life ain't fair, but the root
| password helps. -- BOFH
|
------------------------------
Date: Thu, 25 Oct 2001 21:40:52 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: capture image
Message-Id: <iUSB7.25$2x1.488518@news.interact.net.au>
"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3BD7B34B.B76044B5@earthlink.net...
> huan wrote:
> >
> > hi,
> >
> > i want to know how to capture an image from internet using perl, i
> > have some codes below, but it seem not work:-
> >
> > #!/usr/bin/perl -w
> > use LWP::Simple;
> >
> > print "Content-Type: image/gif\n\n";
> > $content = get("http://xxx.com/xxx.jpg");
> > print $content;
> > exit;
>
> #!/usr/bin/perl -w
> use LWP::Simple;
> print "Content-type: image/jepg\n\n"; # jpeg, not gif.
> binmode STDOUT; # important.
> getprint("http://xxx.com/xxx.jpg");
> exit;
s/jepg/jpeg/;
------------------------------
Date: 25 Oct 2001 04:23:20 -0700
From: sjayna@catchword.com (Stephen Jayna)
Subject: Dumping Perl Hashes
Message-Id: <9683035a.0110250323.5e361abd@posting.google.com>
Dear All,
I currently working on a project that requires me to dump large hash's
to a file and then read them back in again and restore them to the
same structure.
I have used modules such as Data::Dumper and Data::DumpXML, though
Data::DumpXML does exactly what I want in that it dumps the whole hash
structure to XML and is capable of reading that straight back in, it
requires a load of modules.
Normally this wouldn't matter though I have to distribute this to our
40+ servers running Perl 5.005.... Data::DumpXML claims it needs Perl
5.6+
So anyway my question is how do I loop over a hash which I have no
idea of the contents. Obviously I can use ..
foreach my $key (keys %hash){
.
.
}
But how do I know how long to go on for, I know that the hash can be 5
levels deep and contains not only string but array values as well. I
could use the REF operator to work this out thats not really a
problem. I just can't get my head around an algorithm that would loop
through a hash with an arbitary number of keys at an arbitary number
of depths..
Thanks for your time,
Steve J
ps. I've read the Data::DumpXML code but have struggled to make sense
of it (not experianced enough I guess)
------------------------------
Date: Thu, 25 Oct 2001 11:55:38 GMT
From: "spamme" <smap@msap.spamm.mapps.net>
Subject: Re: Dumping Perl Hashes
Message-Id: <_4TB7.226055$bY5.979882@news-server.bigpond.net.au>
> I just can't get my head around an algorithm that would loop
> through a hash with an arbitary number of keys at an arbitary number
> of depths..
Get recursion into your head :-)
Here's the gist...
sub rec($) {
my $h = $_[0];
while(my($k, $v) = each %$h) {
if (ref($v) eq 'HASH') {
print "recursing into $k\n";
rec($v); # Depth first recursion...
} else {
# Scalar... do something...
print "$k=$v\n";
}
}
}
rec({ a => 'b', c => {d => 'f', g => 23}});
With a little elaboration, you should be able to recurse indefinitely into
any hashes or arrays...
t.
------------------------------
Date: Thu, 25 Oct 2001 12:18:51 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Dumping Perl Hashes
Message-Id: <slrn9tg0pb.qbq.garry@zfw.zvolve.net>
On 25 Oct 2001 04:23:20 -0700, Stephen Jayna <sjayna@catchword.com> wrote:
> I currently working on a project that requires me to dump large hash's
> to a file and then read them back in again and restore them to the
> same structure.
You should look at Storable.
--
Garry Williams
------------------------------
Date: Thu, 25 Oct 2001 07:32:00 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: dynamic DBD::Oracle SELECT?
Message-Id: <3BD7F830.2383FB9E@earthlink.net>
Bing Du wrote:
>
> Hi,
>
> I'm using DBI/DBD::Oralce.
>
> Is it possible that part of the WHERE clause is a variable? What
> should be the correct syntax? The following SELECT I made up does not
> return anything.
If it doesn't return anything, you should be printing out $dbh->errstr
to find out why not. Or more likely, you should have RaiseError set, so
you don't have to think about testing the results of each operation.
> (Note: depending on user's input, $where is
> constructed before $sth=$dbh->prepare())
>
> $sth = $dbh->prepare(
> "SELECT
> STU_COURSE.student_id,stu_email.email,stu_course.student_name,
> student_view.major,student_view.class,student_view.lphone
> FROM STU_COURSE,student_view, stu_email where $where and
> stu_course.student_id=stu_email.student_id and
> stu_course.student_id=student_view.sid(+)"
> );
>
> Any ideas?
Well, with a query like the one above, $where does need to be valid SQL
syntax...
For example, $where might be "student_email.email = 'foo@bar.com'"
Also, I would suggest use of spacing, aliases, and capitalization to
make the query more legible:
$sth = $dbh->prepare( qq[
SELECT c.student_id, m.email, c.student_name,
v.major, v.class, v.lphone
FROM stu_course c, student_view v, stu_email m
WHERE $where AND
c.student_id = m.student_id AND
c.student_id = v.sid(+)
] ) or die $dbh->errstr;
See how much easier that is to read?
--
Klein bottle for rent - inquire within.
------------------------------
Date: Thu, 25 Oct 2001 14:27:01 +0200
From: "MAGiC MANiAC^mTo" <mto@kabelfoon.nl>
Subject: how to call a sub from anywhere?
Message-Id: <9r90mo$1ckc$1@news.kabelfoon.nl>
how can I create a sub, that I can call from anywhere?
example :
sub mysub($var){
print $var;
}
mysub "ITS MAGiC";
------------------------------
Date: 25 Oct 2001 12:37:54 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: how to call a sub from anywhere?
Message-Id: <slrn9tg1gl.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Thu, 25 Oct 2001 14:27:01 +0200, MAGiC MANiAC^mTo <mto@kabelfoon.nl> wrote:
> how can I create a sub, that I can call from anywhere?
>
>
> example :
>
> sub mysub($var){
> print $var;
> }
> mysub "ITS MAGiC";
I don't know what you mean "call from anywhere", but the above
code doesn't compile. It should look more like this:
sub mysub{
my $var = shift;
print $var;
}
or if you want the prototype:
sub mysub($){
my $var = shift;
print $var;
}
mysub 'ITS MAGIC';
Now if you can explain what you mean by "call from anywhere" perhaps
we'll be able to help you more.
Cheers,
Bernard
------------------------------
Date: Thu, 25 Oct 2001 21:06:30 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: lookingglass.pl
Message-Id: <slrn9tfshm.23f.mgjv@martien.heliotrope.home>
On Thu, 25 Oct 2001 08:09:58 GMT,
Bart Lateur <bart.lateur@skynet.be> wrote:
> Martien Verbruggen wrote:
>
>
>>for (0 .. $#array) { # Need the index here. }
>>
>>for (0 .. @array - 1) { }
>
>>I really think that there are valid uses of $#array. They are
>>semantically different, as you explain later on. scalar @array gives
>>you the number of elements, $#array gives you the last index. Use them
>>in your code when you mean either of these.
>
> But the above code examples both use 0 where you mean "the first item of
> the array"!
Yes. But since $[ is severely deprecated, I don't see any use in ever
using it.
$#array and @array, even if $[ didn't exist, still have different
semantics.
Martien
--
|
Martien Verbruggen | Think of the average person. Half of
| the people out there are dumber.
|
------------------------------
Date: Thu, 25 Oct 2001 06:59:56 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: matching
Message-Id: <3BD7F0AC.9E5C5AA6@earthlink.net>
Lex Thoonen wrote:
>
> Hi,
>
> I've got the following code:
[snip]
> opendir(DIR, $dir) || &err("can't open : $!");
> @files = grep { /$key\.*/i } readdir(DIR);
> closedir(DIR);
[snip]
> $key can be a number, an id from my database.
> Any of these numbers can have images in a folder:
>
> for example: 19a.jpg 19b.gif 19c.JpeG
>
> The problem is the a, b and the c
>
> What I would like this script to do is:
>
> check for all records that are 19 ($key) followed directly with a
> letter. (so, don't take 191a.jpg for example)
Change the line:
@files = grep { /$key\.*/i } readdir(DIR);
To:
@files = grep { /^$key[a-z]\.*/i } readdir(DIR);
--
Klein bottle for rent - inquire within.
------------------------------
Date: Thu, 25 Oct 2001 11:07:23 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: matching
Message-Id: <87k7xk0yll.fsf@homer.cghm>
Benjamin Goldberg <goldbb2@earthlink.net> writes:
> Change the line:
> @files = grep { /$key\.*/i } readdir(DIR);
> To:
> @files = grep { /^$key[a-z]\.*/i } readdir(DIR);
The match on zero or more periods is spurious. That is equivalent to:
@files = grep { /^$key[a-z]/i } readdir(DIR);
I.e. strings like "${key}Z-bla!" will match. This is likely what is
intended:
@files = grep { /^$key[a-z]\./i } readdir(DIR);
------------------------------
Date: Thu, 25 Oct 2001 07:03:13 -0700
From: Richard Trahan <rtrahan@monmouth.com>
Subject: modification times on Windows files
Message-Id: <3BD81BA1.6094F9B1@monmouth.com>
I'm running ActivePerl 5.6.1. How can I change the modification
time on files? I've looked through all the Windows modules on CPAN
and in the standard distribution, and can't find anything like this.
I know it can be done from Visual C++, but I want to avoid XS if
possible. What I really want to do is emulate "touch" in makefiles,
but I don't think anything other than modification times will
suffice.
------------------------------
Date: 25 Oct 2001 11:10:50 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: modification times on Windows files
Message-Id: <slrn9tfsdf.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Thu, 25 Oct 2001 07:03:13 -0700, Richard Trahan <rtrahan@monmouth.com>
wrote:
> I'm running ActivePerl 5.6.1. How can I change the modification
> time on files? I've looked through all the Windows modules on CPAN
> and in the standard distribution, and can't find anything like this.
> I know it can be done from Visual C++, but I want to avoid XS if
> possible. What I really want to do is emulate "touch" in makefiles,
> but I don't think anything other than modification times will
> suffice.
perldoc -f utime
Cheers,
Bernard
------------------------------
Date: 25 Oct 2001 10:13:57 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: NEWBIE: double sort on a string
Message-Id: <slrn9tfp2p.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Thu, 25 Oct 2001 09:53:11 GMT, Jippie@yahoo.com <jippie@yahoo.com> wrote:
>
> Hi,
>
> What I'm trying to do is to sort of on two columns.
> The the first column is an argument and the second in always column 1.
>
> This is what I have done but my logic is wrong.
> I thought it would be just an extra check if both are the same then check if
> column 1 are the same.
>
> Jippie
>
> sub by_string
> {
> @parts_a=split(/[|]/,$a);
> @parts_b=split(/[|]/,$b);
>
> $retval = (lc($parts_a[$sortfield])) cmp (lc($parts_b[$sortfield]));
> if( $retval == 0 && $sortfield !=1 ) # they are the same
> {
> # then sort by title next. Always nice to have the title in order
> $retval = (lc($parts_a[1])) cmp (lc($parts_b[1]));
> }
> }
Here's an example that will help you modify your code:
@sorted = sort{ $a[0] cmp $b[0]
||
$a[1] cmp $b[1] } @unsorted;
The || operator returns the value of the first expression, unless that's
false in which case it returns the value of the second expression.
Cheers,
Bernard
------------------------------
Date: Thu, 25 Oct 2001 10:59:42 GMT
From: "Jippie@yahoo.com" <jippie@yahoo.com>
Subject: Re: NEWBIE: double sort on a string
Message-Id: <ygSB7.136273$2n1.5368900@Flipper>
Hi,
sorry but this didn't help, maybe I didn't explain well enough
I have a five column table.
index, title, owner, type & size.
Each column can be sorted on, this I can do.
It's just after I sorted on the column I then want a second sort after that
to put the title in order.
can you help??
jippie
"Jippie@yahoo.com" <jippie@yahoo.com> wrote in message
news:biRB7.134495$2n1.5282969@Flipper...
>
> Hi,
>
> What I'm trying to do is to sort of on two columns.
> The the first column is an argument and the second in always column 1.
>
> This is what I have done but my logic is wrong.
> I thought it would be just an extra check if both are the same then check
if
> column 1 are the same.
>
> Jippie
>
> sub by_string
> {
> @parts_a=split(/[|]/,$a);
> @parts_b=split(/[|]/,$b);
>
> $retval = (lc($parts_a[$sortfield])) cmp (lc($parts_b[$sortfield]));
> if( $retval == 0 && $sortfield !=1 ) # they are the same
> {
> # then sort by title next. Always nice to have the title in order
> $retval = (lc($parts_a[1])) cmp (lc($parts_b[1]));
> }
> }
>
>
>
------------------------------
Date: Thu, 25 Oct 2001 11:26:28 GMT
From: "Jippie@yahoo.com" <jippie@yahoo.com>
Subject: NEWBIE: multiple column sort routine
Message-Id: <EFSB7.137323$2n1.5394494@Flipper>
Hi,
sorry but this didn't help, maybe I didn't explain well enough
I have a five column table.
index, title, owner, type & size.
Each column can be sorted on, this I can do.
It's just after I sorted on the column I then want a second sort after that
to put the title in order.
can you help??
This is what I have done but my logic is wrong.
I thought it would be just an extra check if both are the same then check if
title are the same.
sortfield is the argument given.
sub by_string
{
@parts_a=split(/[|]/,$a);
@parts_b=split(/[|]/,$b);
$retval = (lc($parts_a[$sortfield])) cmp (lc($parts_b[$sortfield]));
if( $retval == 0 && $sortfield !=1 ) # they are the same
{
# then sort by title next. Always nice to have the title in order
$retval = (lc($parts_a[1])) cmp (lc($parts_b[1]));
}
}
jippie
------------------------------
Date: Thu, 25 Oct 2001 12:26:18 +0100
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: one-liner solution sought
Message-Id: <9r8t3r$p7b$1@pheidippides.axion.bt.co.uk>
$word = "abcd";
$word .= 'xxxxxxxxxx';
$word = substr($word,0,10);
print "word = $word\n";
<kmead@socrates.Berkeley.EDU> wrote in message
news:9r6pen$l3r$1@agate.berkeley.edu...
> Can someone come up with a one-line perl script which will pad out
> the value part of a name="value" to be exactly 10 characters long?
>
> For example, change
> name="value" ==> name="valuexxxxx"
> name="" ==> name="xxxxxxxxxx"
> name="1234567890123" ==> name="1234567890123"
>
> Thanks
>
> Keith
------------------------------
Date: Thu, 25 Oct 2001 12:29:39 +0100
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: one-liner solution sought
Message-Id: <9r8ta2$pb5$1@pheidippides.axion.bt.co.uk>
and in one line that is:
$word = substr($word . 'xxxxxxxxxx',0,10);
<kmead@socrates.Berkeley.EDU> wrote in message
news:9r6pen$l3r$1@agate.berkeley.edu...
> Can someone come up with a one-line perl script which will pad out
> the value part of a name="value" to be exactly 10 characters long?
>
> For example, change
> name="value" ==> name="valuexxxxx"
> name="" ==> name="xxxxxxxxxx"
> name="1234567890123" ==> name="1234567890123"
>
> Thanks
>
> Keith
------------------------------
Date: Thu, 25 Oct 2001 06:40:47 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl Vs. Java
Message-Id: <3BD7EC2F.9D7C8037@earthlink.net>
Logan Shaw wrote:
>
[snip]
> >Secondly, you neglected memory consumption. Java is known to consume
> >a lot of that.
>
> I added sleep(10) or moral equivalent to the very end of those same
> programs, and ran the same test again, this time running "top" to
> examine memory usage. Here's what I found:
>
> Java: 26MB total process size, 7540K of that resident
> Perl: 42MB total process size, 41M of that resident
> C++: 2828K total process size, 2556K of that resident
>
> Granted, this is something of a worst case for Perl -- an array of
> elements that are only used to store true/false values. Java and C++
> both store the booleans as bytes[1], so if you consider only resident
> size[2], it would appear that Java isn't too terribly wasteful in this
> case.
If all you are storing are a bunch of true/false values, then in perl,
you would do that as ONE scalar, a string of bytes, and use vec to test
and set bits in that string.
[snip]
> [1] Actually, I think Java stores booleans as bytes if they're
> in an array and 32-bit quantities otherwise. A little bit
> strange, but it makes sense in a weird way too.
With perl, you would store booleans in a string, with 8 of them per
byte. Actually, you would likely do this with java or C/C++, too, if
you were that concerned with memory.
In perl:
#!/usr/local/bin/perl -w
use strict;
my $max = $ARGV[0];
my $prime = "\xFC" . "\xFF" x ($max/8);
my ($i, $j);
for( $i = $max+1; vec($prime, $i, 1); ++$i ) {
vec( $prime, $i, 1 ) = 0;
}
for $i ( 2 .. sqrt($max) ) {
next if !vec( $prime, $i, 1 );
for( $j = 2 * $i; $j <= $max; $j += $i ) {
vec( $prime, $j, 1 ) = 0;
}
}
my $count = ($prime=unpack("B*", $prime)) =~ tr/1//;
print "There are $count primes in the interval [2,$max].\n";
__END__
$ time perl x.pl 2000000
There are 148933 primes in the interval [2,2000000].
real 12.58
user 13.67
sys 0.05
This is on an i686, running linux.
Of course, if you added similar optomizations to your perl and C++
programs, it would likewise speed things up.
--
Klein bottle for rent - inquire within.
------------------------------
Date: Thu, 25 Oct 2001 19:00:24 +0800
From: "DIAMOND Mark R." <dot@dot.dot>
Subject: Re: Regexp help needed Part 2
Message-Id: <9r8rcb$mm1$1@enyo.uwa.edu.au>
Thank you.
------------------------------
Date: Thu, 25 Oct 2001 06:54:32 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: What the **** is WRONG with this!?
Message-Id: <3BD7EF68.3A502CB2@earthlink.net>
Tim Hammerquist wrote:
[snip]
> Good think Windows doesn't have symlinks.
Windows NT does, though only if you are using an NTFS filesystem.
--
Klein bottle for rent - inquire within.
------------------------------
Date: Thu, 25 Oct 2001 14:53:35 +0200
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: What's wrong with File::Find
Message-Id: <3BD80B4F.3F7E115E@eed.ericsson.se>
Hi,
Dave Tweed wrote:
>
> Now, was the OP objecting to "closures" as defined in the docs, or
> to anonymous subs in general?
just anon subs are okay to me, but the closures are not - because
I believe that closures (the anon subs referencing outer lexical vars)
aren't very effective and waste memory - please see the example at
http://perl.apache.org/guide/perl.html#Understanding_Closures_the_Ea
That's why I think, it's pity that File::Find doesn't support passing
arguments to the wanted sub - it would be so easy to implement.
Regards
Alex
------------------------------
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 2006
***************************************