[7510] in Perl-Users-Digest
Perl-Users Digest, Issue: 1136 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 7 08:07:18 1997
Date: Tue, 7 Oct 97 05:00:37 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 7 Oct 1997 Volume: 8 Number: 1136
Today's topics:
Re: $x = $y || $z - dangerous assumption? (Bart Lateur)
Determining if function exists in class <splichta@endeavortech.com>
Re: Getting the date on NT <thomas@fahle.de>
Re: Getting the date on NT <jon.tracey@earthling.net>
how to do fractional second alarm() timeouts? <jwa@jammed.com>
Re: How to make Perl script into an NT 4.0 Service <david_mitchell@hp.com>
Re: IPC question on listen() (robert)
Re: Newbie ques: How to concatenate two strings? <flavell@mail.cern.ch>
Odd behavior. plambert$1@plambert.org
perl for vme mike_reeves@candle.com
PERL ioctl.ph for NeXT mach (3.x or 4.x) penrose@w09.sfc.keio.ac.jp
Re: Perl vs. Java <pcunnell@csfp.co.uk>
Re: Perl vs. Java <seay@absyss.fr>
Perl5.004 with QNX 4.24, Watcom 10.6 <jerry_hicks@bigfoot.com>
Sorting in a file <pdenman@ims.ltd.uk>
Re: Sorting in a file <seay@absyss.fr>
Re: Sorting values such as 1.1, 1.1.1, 2.1 into order (Tushar Samant)
Re: Sorting values such as 1.1, 1.1.1, 2.1 into order (Dean Inada)
Re: Text::Wrap bombs on lines with no white space! <Jacqui.Caren@ig.co.uk>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Oct 1997 09:31:10 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: $x = $y || $z - dangerous assumption?
Message-Id: <3440fa9b.5755316@news.tornado.be>
pjscott-remove-to-email@euclid.jpl.nasa.gov (Peter Scott) wrote:
> my $x = shift || $default;
>
>(to use one concrete example of it), the intention being that if there
>was no argument, shift returns undef, which is false, and so $x gets
>the default.
>
>The thing that bothers me about this - and maybe I'm overreacting - is
>that if there *was* an argument, but it was 0, $x will still get $default.
>Of course, I can handle this case, assuming I really want a different
>action if the argument is 0 (or ""):
>
> $x = $default unless defined (my $x = shift);
The description you give here is what I hate the most about Perl: you
can make something simple work almost perfectly, but you can't get it
right without abandoning what you have, and using an entirely different
approach instead.
Anyway, this will probably do what you want:
{ local($_);
$x=defined($_=shift)?$_:$default;
}
The "?:" can be nested, and do have the desired shortcut capability, but
I can't seem to merge the declaration of the local variable into the
expression.
Bart.
------------------------------
Date: 7 Oct 97 07:04:33 GMT
From: "Scott Plichta" <splichta@endeavortech.com>
Subject: Determining if function exists in class
Message-Id: <01bcd2ef$6d32e540$df55f5cf@splichta>
I know that I can check for the existence of a functon as
$func = "foo";
&$foo() if (defined(&$foo)) ;
What about when the method is part of a class/package?
Can I say:
$foo = 'method1';
&{$self}->$foo() if (defined(&{$self->$foo}));
I can't seem to find the syntax.
Would this check the inheritence heirarchy?
Scott Plichta
Endeavor Technologies, Inc
------------------------------
Date: Tue, 07 Oct 1997 09:25:18 -0700
From: Thomas Fahle <thomas@fahle.de>
To: mikefelix@byu.edu
Subject: Re: Getting the date on NT
Message-Id: <343A626E.3A69@fahle.de>
Hi
there are several routines to get the date using localtime().
One is below from a formprocessing script found
at www.cgi-resources.com.
Mike Felix wrote:
>
> I want to extract the current date from the 'date' command. I'm running
> perl 5 on NT. The problem is that the DOS date command asks for a new
> date, so if I say:
> $date = `date`;
> the script gets hung while the process waits for input. I could open a
> process but I don't know how to open for both write and read, i.e.:
> open(DATE, "|date");
> or
> open(DATE, "date|");
############################################################
#
# subroutine: GetDateAndTime
# Usage:
# &GetDateAndTime(;
#
# Parameters:
# None.
#
# Output:
# Returns a string of the current date and time.
#
############################################################
sub GetDateAndTime
{
local ($sec, $min, $hour, $mday, $mon);
local($year, $wday, $yday, $isdst);
local ($ampm, $currentdatetime);
($sec, $min, $hour, $mday, $mon,
$year, $wday, $yday, $isdst) =
localtime(time);
$mon++;
$ampm = "AM";
$ampm = "PM" if ($hour > 11);
$hour = $hour - 12 if ($hour > 12);
if (length($min) == 1)
{
$min = "0" . $min;
}
"$mon/$mday/$year $hour:$min $ampm";
} # End of GetDateAndTime
#########################################
Thomas Fahle
------------------------------
Date: Tue, 7 Oct 1997 10:55:19 +0100
From: "Jonathan Tracey" <jon.tracey@earthling.net>
Subject: Re: Getting the date on NT
Message-Id: <61d0uj$su3$1@soap.uunet.pipex.com>
if you do $date = `date /t` this iwll solve your problem the /t switch just
displays the date without asking for a new one.
Hope this helps
Jon
Jonathan Tracey Tel. 01223 250739
NT Systems Administrator Fax. 01223 250101
UUNET E-mail: jont@uk.uu.net
Internet House www: http://www.uk.uu.net
332 Science Park
Cambridge
United Kingdom
CB4 4BZ
"I am homer of Borg you will be assim Ooohhhhh Donuts".
Mike Felix wrote in message <34399030.1519@byu.edu>...
>I want to extract the current date from the 'date' command. I'm running
>perl 5 on NT. The problem is that the DOS date command asks for a new
>date, so if I say:
>
>$date = `date`;
>
>the script gets hung while the process waits for input. I could open a
>process but I don't know how to open for both write and read, i.e.:
>
------------------------------
Date: Tue, 7 Oct 1997 00:43:15 -0700
From: "James W. Abendschan" <jwa@jammed.com>
Subject: how to do fractional second alarm() timeouts?
Message-Id: <Pine.LNX.3.95.971007003747.719F-100000@nimue.jammed.com>
How can I get alarm() to have finer than 1 second resolution?
Can I somehow write my own alarm() function using the "fractional sleep"
trick using select()? Or is using syscall (shudder) my only option?
This is under Linux 2.0, if it matters (but it shouldn't, because
ideally I'd like the code to be portable.. but..)
James
--
James W. Abendschan jwa@jammed.com http://www.jammed.com/
any significantly advanced technology is indistiguishable from a perl script
------------------------------
Date: Tue, 7 Oct 1997 16:57:38 +1000
From: "Dave Mitchell" <david_mitchell@hp.com>
Subject: Re: How to make Perl script into an NT 4.0 Service
Message-Id: <61cmr9$ofo5@hpcc883.corp.hp.com>
I do this using the SRVANY tool from the NT Resource Kit. It works fine;
I've got "Perl services" installed on ~150 systems spread across a large
geographical area (i.e. all over Australia and New Zealand) and things work
fine.
Re the DOS window issue: you can go into Control Panel->Services, highlight
your service and configure it so that it can't interact with the desktop. I
do this to achieve the result you're after, and it works fine.
Dave Mitchell
------------------------------
Date: 7 Oct 1997 12:21:54 +0200
From: robert@il.fontys.nl (robert)
Subject: Re: IPC question on listen()
Message-Id: <61d2g2$4b3@bsd1.hqehv-internal.ilse.net>
Gerben_Wierda@RnA.nl:
>When I write a server and I let that server listen wit a call like
> listen( S, 2);
>I do expect that maximum three process may connect to that server process
>simultaneously, one being handled and two waiting.
>But when I do that, and I try to connect to that server process with telnet,
>I can get 5 processes to connect. One actively handled, 4 waiting but able to
>provide input.
What do you mean with 'able to provide input'? Did you do a connect() on
those 4 waiting connections?
robert
------------------------------
Date: Tue, 7 Oct 1997 11:23:15 GMT
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Newbie ques: How to concatenate two strings?
Message-Id: <Pine.A41.3.95a.971007132156.126140D-100000@sp051>
On Tue, 7 Oct 1997, Joseph wrote:
> On 6 Oct 1997 04:57:56 GMT, mheins@prairienet.org (Mike Heins) wrote:
>
> >I know you are not currently a programmer, because no real programmer
> >could miss the concatenation operator in the docs.
>
> What you "know" is wrong.
Then it's high time you stopped making such a fool of yourself.
Get a grip, for pity's sake.
------------------------------
Date: 7 Oct 1997 06:30:29 GMT
From: plambert$1@plambert.org
Subject: Odd behavior.
Message-Id: <61cku5$ev8$2@nntp1.ba.best.com>
I'm seeing odd behavior. The script I've included works fine, but if I give
incorrect input, it gives an incorrect line number in the generated
warning.
I've fixed the script (put "defined($ARGV[0]) and" in the first while loop)
but it's odd that it reports the wrong line for the error:
% perl -v
This is perl, version 5.004_01
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
% ./cronwrap -H
Use of uninitialized value at ./cronwrap line 85.
usage: cronwrap [-option argument ...] commands
The error actually occurs in line 69. The friendly Best Internet co-customers
who tracked this beast down for me tried similar scripts and saw the same
erroneous line number.
Again, this doesn't really affect anything important, just debugging. If
it isn't fixed, it doesn't hurt me. But it confused me for a few hours,
resulting in a lot of headache for no good reason. (I'm not a very
experienced perl programmer, or programmer in general, so it really did
take me a long time to find the real problem, and only with the help of
others.)
Thanks for any input/suggestions anyone might have.
--Paul Lambert
----------script follows---------
#!/usr/bin/perl5 -w
# this is a wrapper for cron jobs, which executes its arguments, and if
# there is any output, gives more information along with the output.
#
# available options are:
# -u takes an email address as an argument; sends output to that
# address instead of the owner.
# -s takes a single argument to be used as the subject of the
# email.
# -q sends no output no matter what happens. bad idea to use
# this. included for completeness only. ;-)
# -H turns off the header entirely. overrides -t, -n, and
# -e.
# -t shows the cpu time used by the process, both user and system.
# -e disables showing the exit status of the process.
# -n shows the exit status of the process even if "normal".
# this is overridden by the -e option.
# -c turns off the display of the command in the header.
# -h help.
#
$tmpfile = "/tmp/cronwrap.tmp.$$";
$quiet = 0;
$header = 1;
$command = 1;
$showtimes = 0;
$showexit = 1;
$normalexit = 0;
sub usage {
die "usage: cronwrap [-option argument ...] commands\n";
}
sub help {
print <<HELP;
available options are:
-u takes an email address as an argument; sends output to that
address instead of the owner.
-s takes a single argument to be used as the subject of the
email.
-q sends no output no matter what happens. bad idea to use
this. included for completeness only. ;-)
-H turns off the header entirely. overrides -t, -n, and
-e.
-t shows the cpu time used by the process, both user and system.
-e disables showing the exit status of the process.
-n shows the exit status of the process even if "normal".
this is overridden by the -e option.
-c turns off the display of the command in the header.
-h help.
HELP
}
# first, redirect stderr to stdout:
$subject="cron output";
$uname = (getpwuid($>))[0];
$recipient = $uname;
$hostname=`hostname`;
chomp($hostname);
# parse arguments
while ($ARGV[0] =~ /^-/) {
$opt = shift;
if ($opt =~ /^-s$/) {
$subject = shift;
} elsif ($opt =~ /^-q$/) {
$quiet = 1;
} elsif ($opt =~ /^-u$/) {
$recipient = shift;
} elsif ($opt =~ /^-H$/) {
$header = !$header;
} elsif ($opt =~ /^-c$/) {
$command = !$command;
} elsif ($opt =~ /^-t$/) {
$showtimes = !$showtimes;
} elsif ($opt =~ /^-e$/) {
$showexit = !$showexit;
} elsif ($opt =~ /^-n$/) {
$normalexit = !$normalexit;
} elsif ($opt =~ /^-h$/) {
&help;
exit;
} else {
&usage;
}
}
&usage if (0 == @ARGV);
open(STDERR, ">&STDOUT");
# now, set a safe umask for the output file...
$mask = umask 077;
# ok, now make output go somewhere useful.
open(OLDOUT, ">&STDOUT");
open(STDOUT, ">$tmpfile") || warn "cronwrap: failed to open $tmpfile for output:$!";
$|=1;
# ok, restore our umask
umask $mask;
# what time is it?
($sec,$min,$hour,$day,$mon,$year)=localtime;
# ok, now, run the arguments.
$rc = 0xffff & system @ARGV;
$fail=$! if ($rc == 0xff00);
# ok, close the file...
close(STDOUT);
$output = (-s $tmpfile);
if (($rc == 0) and (($quiet) or (!$output))) {
unlink $tmpfile || warn "unable to unlink temp file $tmpfile:$!";
exit;
}
open(STDOUT, "|/usr/lib/sendmail -t") || do {
warn "couldn't open /usr/lib/sendmail for output: $!";
open(STDOUT, ">&OLDOUT");
};
close(OLDOUT);
# get times
($usertime,$system,$cuser,$csystem) = times;
print "To: $recipient\n";
print "From: $uname\n";
print "Subject: $subject\n";
print "\n";
if ($header) {
print "************************************************************************\n";
printf "%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d ", $mon, $day, $year, $hour, $min, $sec;
print ((getpwuid($>))[0], "\@$hostname\n");
print "command: ", join(' ',@ARGV), "\n" if $command;
print "times: ", $usertime+$cuser, " user, ", $system+$csystem, " system\n" if $showtimes;
if (($rc == 0) and $showexit) {
print "ran with normal exit\n" if $normalexit;
} elsif ($rc == 0xff00) {
print "command failed: $fail\n";
} elsif ($rc > 0x80) {
$rc >>= 8;
print "ran with non-zero exit status $rc\n";
} else {
print "ran with ";
if ($rc & 0x80) {
$rc &= ~0x80;
print "coredump from ";
}
print "signal $rc\n"
}
print "************************************************************************\n\n";
}
system("/bin/cat",$tmpfile);
unlink($tmpfile) || warn "cronwrap: unable to unlink $tmpfile:$!";
exit $rc;
------------------------------
Date: Tue, 07 Oct 1997 05:41:20 -0600
From: mike_reeves@candle.com
Subject: perl for vme
Message-Id: <876220594.16056@dejanews.com>
I have some code written in Perl that I wish to move to ICL's VME
operating system for a client project that I am working on. All my
web/discussion group searches have drawn a blank. Does anyone know if
there is a port available or how feasible it would be to do the port?
Thanks in advance,
Mike
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 07 Oct 1997 19:22:25 +0900
From: penrose@w09.sfc.keio.ac.jp
Subject: PERL ioctl.ph for NeXT mach (3.x or 4.x)
Message-Id: <wzbu11vpni.fsf@w09.sfc.keio.ac.jp>
Hello folks!
I am running Openstep 4.1 and I have some need to access ioctl
from Perl. I have made my own ioctl.ph using h2ph, but the
simple calls I make:
#!/usr/bin/perl -- # -*-Perl-*-
require '/tmp/ioctl.ph';
$magicput = TIOCSTI || die "can't get the magic function!";
system('stty raw -echo');
$char = pack "c", "!";
(ioctl STDOUT, $magicput, $char) || die "Sorry charlie";
Always fail. Do I need to dereference $magicput in some way,
or is my ioctl.ph broken. Here is a relevent excerpt:
eval 'sub TIOCSTI { &_IOW(ord(\'t\'), 114, char);}';
Thanks for any advice!
Chris Penrose
penrose@sfc.keio.ac.jp
------------------------------
Date: Tue, 07 Oct 1997 10:10:08 +0100
From: Paul Cunnell <pcunnell@csfp.co.uk>
To: Chan <hc@toraix1.torolab.ibm.com>
Subject: Re: Perl vs. Java
Message-Id: <3439FC70.2F1CF0FB@csfp.co.uk>
[ mailed & posted ]
Chan wrote:
>
> Hi,
>
> I was wondering if Perl5 supports multiple inheritance.
> How about polymorphism and overloading?
Yes to MI & polymorphism. You can do some overloading too,
but it's somewhat different to what you get with C++ & Java.
(a good thing too, IMHO :) For example you don't overload
member functions based on their argument signatures (though
you could always achieve much the same effect by looking at
the argument list in the member function).
You can also do some really bizarre things like manipulating
the inheritance hierarchy at runtime (useful if you're
optimising for obscurity, perhaps).
>
> I'm doing some minor research on the comparison of
> OO languages and I was wondering how Perl5 compares
> to Java
If I were researching something, I'd be inclined to
_read_the_documentation_, available at http://www.perl.com -
particularly look for the 'perltoot' section in the main
documents.
>
> thx for any info,
>
> Regards,
> Henry
> hc@ca.ibm.com
--
Paul Cunnell CSFB RDG (pcunnell@csfp.co.uk) +44 171 888 2946
Spam bait: domreg@cyberpromo.com postmaster@netvigator.com
postmaster@onlinebiz.net pmdatropos@aol.com admin@submitking.com
cte@llv.com walt@pwrnet.com
------------------------------
Date: Tue, 07 Oct 1997 12:58:28 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: Perl vs. Java
Message-Id: <343A15D4.70520C6B@absyss.fr>
Paul Cunnell wrote:
out of context quote
> useful if you're optimising for obscurity, perhaps
"optimising for obsucurity", what a concept. It is something I'd like
to have on my resume. It'd be a lot more interesting to talk about in
an interview than sockets.
- doug
------------------------------
Date: Tue, 07 Oct 1997 01:21:32 +0000
From: Jerry Hicks <jerry_hicks@bigfoot.com>
To: allen@huarp.harvard.edu
Subject: Perl5.004 with QNX 4.24, Watcom 10.6
Message-Id: <34398E9C.9D52E54B@bigfoot.com>
Hello All,
Has anyone been successful in building and using Perl 5.004xx
for QNX 4.24 with Watcom 10.6 and TCP/IP 4.24?
The hints in the distribution seem to be a little old. Also,
if I use the CPP module found in the QNX directory of the
distribution, configuration fails horribly, neglecting to
pick up the SIGxxx declarations in <signal.h>. This causes
massive failures during the tests, in many areas.
----
I have a client who is open minded enough to deploy Perl in
a production application, but only if it can Configure and
test 100%. Pretty saavy for management types, huh?
---
Some notes and the !ok lines from the regression tests follow.
This was Perl 5.00403. 5.00401 has a memory leak we can't
tolerate in our long-running, embedded-perl application. (Right?)
TIA,
Jerry Hicks
jerry_hicks@bigfoot.com (please reply by email too)
--------------------------------------------------------------
Configure errors:
--------------------------------------------------------------
If the CPP module included in the QNX directory is used, then
Configure will not extract any signal names from the signal.h
file. This causes *many-many-many* errors during testing.
I decided against using it after building and testing both
ways.
compilation errors:
--------------------------------------------------------------
regexec.c(975): Error! E1151: Parameter count does not
agree with previous definition
regexec.c(991): Error! E1151: Parameter count does not
agree with previous definition
regexec.c(1006): Error! E1151: Parameter count does not agree
with previous definition
( these were quieted by removing the parameter "cp"
from the regcppartblow() function calls. I'm not
sure though, is this an indicator of another problem? )
***************************************************
The !ok lines from the regression test follow
!--!!!HELP QNX!!! !!!HELP QNX!!! !!!HELP QNX!!!----
! Seems to be caused because we are not using
! the Dynaloader. Can someone at QNX *please*
! recommend a strategy for Dynaloading Perl
! modules under QNX?
lib/posix...........FAILED test 17
Failed 1/17 tests, 94.12% okay
:--------------------------------------------------
: Guess we don't have cpp (see notes)
comp/cpp............skipping test on this platform
:--------------------------------------------------
: We don't have groups???
op/groups...........skipping test on this platform
:--------------------------------------------------
: This was caused by QNX's leading //node#/ before
: the path, shouldn't cause any problems at runtime
op/magic............FAILED test 23
Failed 1/30 tests, 96.67% okay
:--------------------------------------------------
: This one is *especially* troubling to me. I don't
: have/know enough 'perlguts' to fix it ;)
op/runlevel.........PROG:
sub foo {
goto bar if $a == 0;
$a <=> $b;
}
@a = (3, 2, 0, 1);
@a = sort foo @a;
print join(', ', @a)."\n";
exit;
bar:
print "bar reached\n";
EXPECTED:
Can't "goto" outside a block at - line 2.
GOT:
0, 1, 2, 3
FAILED test 8
Failed 1/8 tests, 87.50% okay
:--------------------------------------------------
: This one bugs me pretty badly too,
: from the link map listing, it appears
: to be bombing in the "Perl_peep" routine
lib/complex.........Stack Overflow at 0007:0001D75B
dubious
Test returned status 1 (wstat 256)
DIED. FAILED tests 1-990
Failed 990/990 tests, 0.00% okay
:--------------------------------------------------
: Understood, this isn't *BSD
lib/db-btree........skipping test on this platform
lib/db-hash.........skipping test on this platform
lib/db-recno........skipping test on this platform
:--------------------------------------------------
: I *think* I've built this OK on QNX, but we'll
: skip it for now
lib/gdbm............skipping test on this platform
:--------------------------------------------------
: don't have it, can't get it
lib/ndbm............skipping test on this platform
lib/odbm............skipping test on this platform
Failed Test Status Wstat Total Fail Failed List of failed
------------------------------------------------------------------------------
lib/complex.t 1 256 990 990 100.00% 1-990
lib/posix.t 17 1 5.88% 17
op/magic.t 30 1 3.33% 23
op/runlevel.t 8 1 12.50% 8
Failed 4/152 test scripts, 97.37% okay. 993/4526 subtests failed, 78.06%
okay.
------------------------------
Date: Tue, 7 Oct 1997 09:56:05 +0100
From: "Paul Denman" <pdenman@ims.ltd.uk>
Subject: Sorting in a file
Message-Id: <0gtc16.srl.ln@gate.imsport.co.uk>
Hello,
I have a large file to work with, which is a comma-seperated ASCII text
file.
The first field of which contains a user-id number (6 digit), which is then
followed by some 20-odd fields.
Is it possible to sort this file by the first field without reading the
entire
content into an array?
I am running Perl Win32, version 5.003_07.
Kind regards,
Paul Denman
------------------------------
Date: Tue, 07 Oct 1997 13:21:48 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: Sorting in a file
Message-Id: <343A1B4C.74EBBCEC@absyss.fr>
Paul Denman wrote:
>
> Hello,
>
> I have a large file to work with, which is a comma-seperated ASCII text
> file.
> The first field of which contains a user-id number (6 digit), which is then
> followed by some 20-odd fields.
>
> Is it possible to sort this file by the first field without reading the
> entire
> content into an array?
I'm not sure what you are asking here. Do you want to be able to sort
without bothering to use a temp array? Sure, you could use a sorting
function that that takes the whole line as the arguements, uses a RE to
grab what you want and sort by that.
my @sorted = sort &sortfunc <INPUT>;
This would be real slow as you'll do a lot of needless parsing. I don't
think I'd ever recomend this solution.
If you mean to not have an array for your split, sure, that is even
easier
my $key = (split(',', $line))[0];
$key now has everything upto the first comma. You can happily sort by
this value. You could easily mix this with the first idea (get directly
from the input file) by using a Schwartzian Transform.
my @sorted = map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [ $_, (split(',', $line))[0] ] }
<INPUT>;
If this doesn't come close to doing what you want, please post again.
- doug
------------------------------
Date: 7 Oct 1997 02:37:27 -0500
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: Sorting values such as 1.1, 1.1.1, 2.1 into order
Message-Id: <61corn$c85@shoga.wwa.com>
tony.mcdonald@ncl.ac.uk writes:
>What I want is the following
>filename - 1.html
>filename - 1.1.html
>filename - 1.1.1.html
>filename - 1.2.html
>filename - 2.html
>filename - 4.html
>filename - 4.1.html
>filename - 5.html
>filename - 10.html
>filename - 10.1.html
>filename - 10.1.1.html
Sometimes the skankiest, most hideous tricks will do the best job...
I mean this is a one-off thing, right? You don't have more than 250
sections in any chapter do you? And the names all look like these
above, don't they. Then just do this:
@files =
map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { $old = $_; s/html$//; s/(\d+\.)/chr $1/ge; [$old, $_] }
@files;
I believe there is a module which sorts "version numbers", which
might be useful too.
------------------------------
Date: 7 Oct 1997 08:16:33 GMT
From: dmi@delta1.deltanet.com (Dean Inada)
Subject: Re: Sorting values such as 1.1, 1.1.1, 2.1 into order
Message-Id: <61cr51$lv2$1@news01.deltanet.com>
In article <tony.mcdonald-ya023080000610971901170001@news.ncl.ac.uk>,
Tony McDonald <tony.mcdonald@ncl.ac.uk> wrote:
>I really hope someone can help, I'm slowly losing it here.
Schwartzian Transform is your friend
>
>$files[0] = "10.html";
>$files[1] = "1.html";
>$files[2] = "1.1.html";
>$files[3] = "1.2.html";
>$files[4] = "5.html";
>$files[5] = "4.1.html";
>$files[6] = "4.html";
>$files[7] = "10.1.html";
>$files[8] = "10.1.1.html";
>$files[9] = "1.1.1.html";
>$files[10] = "2.html";
>
sub ST(&@){
my $metric=shift;
map {$_->[0]}
sort {$a->[1] cmp $b->[1]}
map {[$_,&{$metric}]} @_
}
foreach( ST {local $_=$_;s/(\d+)/sprintf("~%09d",$1)/eg;$_} @files ){
print "filename - $_\n";
}
>
>What I want is the following
>filename - 1.html
>filename - 1.1.html
>filename - 1.1.1.html
>filename - 1.2.html
>filename - 2.html
>filename - 4.html
>filename - 4.1.html
>filename - 5.html
>filename - 10.html
>filename - 10.1.html
>filename - 10.1.1.html
------------------------------
Date: Mon, 6 Oct 1997 17:50:02 GMT
From: Jacqui Caren <Jacqui.Caren@ig.co.uk>
Subject: Re: Text::Wrap bombs on lines with no white space!
Message-Id: <EHn5JF.5v1@ig.co.uk>
Posted and emailed to jase@cadence.com
In article <Pine.GSO.3.96.970918093723.8611N-100000@julie.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
>On Wed, 17 Sep 1997 jase@cadence.com wrote:
>
>> I have a Perl script that reads in a file of text, and then displays that
>> text wrapped to 80 columns. Text::Wrap works most of the time, except when
>> there's a line that contains 80 non-white-space characters all in a row.
>> In that special case, the call to wrap() causes the script to exit with
>> the error:
>>
>> couldn't wrap 'blablabla...' /usr/local/lib/perl5/Text/Wrap.pm line 87.
>>
>> What I need is something that will insert a newline at the last whitespace
>> character on a line before the wrap column, *or* if no such character is
>> found the newline should simply be placed at the wrap column position. Is
>> there such a function?
>
>Why don't you patch Text::Wrap to offer such a function? Contact its
>author and work with him or her to make the next version do what you want.
>Good luck!
>
>--
>Tom Phoenix http://www.teleport.com/~rootbeer/
>rootbeer@teleport.com PGP Skribu al mi per Esperanto!
>Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
> Ask me about Perl trainings!
Already done and posted (to author and p5p (at Timbo's request)...
No one has replied (including author) yet though...
I would appreciate feedback to the revised functionality
and comments on the changes.
BUG#1
The death at long line folds is because of a bounds condition
that only occcurs then the pattern never matches.
i.e.
perl wrap.pl <<END
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
END
calls the die()...
I consider this a bug and have restructured the logic as required.
For this reason I shipped the pm rather than a patch.
BUG#2
There is also a second bug that due to the program logic
converts
a a a a a a a a aa
bbbbbbbbbbbbbbbbbbbbbbbbbbb
c c c c c cc c c cc
into (roughly)
a a a a a a a a aa c c c
c c c c c cc
bbbbbbbbbbbbbbbbbbbbbbbb
bbb
i.e. long lines are process AFTER all lines matching the
wordspace fold pattern, I wonder how many people have
been hit by this nasty bug...
The below program shows the problems...
jacqui@oink: cat wrap.pl
use lib ('.');
use Text::Wrap qw(wrap $columns);
$columns = 23;
print "\nTEST CASE A\n";
print wrap('[indent1]','[indent2]', <<END);
a a a a a a a a
LONGTEXTLONGTEXT ALSO
d d d d d d d d
END
print "\nTEST CASE B\n";
print wrap('[indent1]','[indent2]', <<END);
LONGTEXTLONGTEXT ALSO
END
jacqui@oink:
Note that in my changes I have aimed at making at as few changes
to the current output style as possible. The fact that the
longlines still fold onto a new line is because this is current
behaviour. I do know if this was considered broken and so did
not attempt to fix it :-)
Jacqui
revised Text/Wrap.pm below.
begin 664 Text/Wrap.pm
M<&%C:V%G92!497AT.CI7<F%P.PH*<F5Q=6ER92!%>'!O<G1E<CL*"D!)4T$@
M/2 H17AP;W)T97(I.PI 15A03U)4(#T@<7<H=W)A<"D["D!%6%!/4E1?3TL@
M/2!Q=R@D8V]L=6UN<R D=&%B<W1O<"D["@HD5D524TE/3B ]("(Y-RXP,B([
M"2,@;F]T(&$@9&%T90H*=7-E('9A<G,@<7<H)%9%4E-)3TX@)&-O;'5M;G,@
M)&1E8G5G*3L*=7-E('-T<FEC=#L*"D)%1TE."7L*(" @("1C;VQU;6YS(#T@
M-S8[(" C(#P]('-C<F5E;B!W:61T: H@(" @)&1E8G5G(#T@,#L*?0H*=7-E
M(%1E>'0Z.E1A8G,@<7<H97AP86YD('5N97AP86YD("1T86)S=&]P*3L*"G-U
M8B!W<F%P"GL*(" @(&UY("@D:7 L("1X<"P@0'0I(#T@0%\["@H@(" @;7D@
M0')V.PH@(" @;7D@)'0@/2!E>'!A;F0H:F]I;B@B("(L0'0I*3L*"B @("!M
M>2 D;&5A9" ]("1I<#L*(" @(&UY("1L;" ]("1C;VQU;6YS("T@;&5N9W1H
M*&5X<&%N9"@D;&5A9"DI("T@,3L*(" @(&UY("1N;" ]("(B.PH*(" @("1T
M(#U^(',O7EQS*R\O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!P87)A*3L*
#?0H*
end
--
Jacqui Caren Email: Jacqui.Caren@ig.co.uk
Paul Ingram Group Fax: +44 1483 419 419
140A High Street Phone: +44 1483 424 424
Godalming GU7 1AB United Kingdom
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 1136
**************************************