[6617] in Perl-Users-Digest
Perl-Users Digest, Issue: 242 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 6 11:07:16 1997
Date: Sun, 6 Apr 97 08:00:22 -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 Sun, 6 Apr 1997 Volume: 8 Number: 242
Today's topics:
Re: @array as input symbol in <@array> (Brendan O'Dea)
Re: A beginer's Regular Expression problem (Gene Johannsen)
Re: conversion windows to unix <pucko@lysator.liu.se>
HEELLPP!!!!!! <o@o.com>
Re: HEELLPP!!!!!! (James A. Robinson)
Re: HEELLPP!!!!!! <pucko@lysator.liu.se>
Loop-Problem.... <pucko@lysator.liu.se>
Re: Loop-Problem.... (Clay Irving)
Multiple mail! <sbo@unix.okg.se>
Re: Ousterhout and Tcl lost the plot with latest paper (Michael Sperber [Mr. Preprocessor])
Re: Ousterhout and Tcl lost the plot with latest paper (Jack Jansen)
Re: Ousterhout and Tcl lost the plot with latest paper <graham.hughes@resnet.ucsb.edu>
Re: Ousterhout and Tcl lost the plot with latest paper <jlee@math.purdue.edu>
Perl and NT <matt@geenite.demon.co.uk>
Re: Question: Using perl to execute shell commands (Tad McClellan)
Re: Simple array question by newbie... (Clay Irving)
Re: Sorting a text file? <ajs@ajs.com>
Re: string comparision <vladimir@cs.ualberta.ca>
Re: Unix and ease of use (WAS: Who makes more ...) (Tom Wheeley)
Re: Unix and ease of use (WAS: Who makes more ...) (Martin Sohnius x24031)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Apr 1997 06:28:45 GMT
From: bod@compusol.com.au (Brendan O'Dea)
Subject: Re: @array as input symbol in <@array>
Message-Id: <5i7fqt$1u0$1@diablo.compusol.com.au>
[mailed & posted]
In article <5i6mhh$608@picasso.op.net>,
Mark-Jason Dominus <mjd@plover.com> wrote:
>You see that the <angle brackets' are really doing soemthing here,
>since
>
> while (<@array>)
>
>is different from
>
> while (@array)
>
>However, I could not find any docmuentation about this use of angle
>brackets. The only uses of <...> that I could find in the camel book
>or the man pages were
>
> <FILEHANDLE>
>and
> <filename glob pattern>
>
>and this is neither of those.
>
>The question: Is this documented? And if so, where?
No magic, no mystery ... ``while (<@array>)'' is an expensive variant
of ``for (@array)'' with the side effect that any elements of @array
containing shell metacharacters will be expanded.
Consider:
@array = qw(one two three);
while (<@array>)
{
...
}
The perlop man page says:
... If the string inside angle brackets is not a filehandle or a
scalar variable containing a filehandle name or reference, then it
is interpreted as a filename pattern to be globbed, and either a
list of filenames or the next filename in the list is returned,
depending on context. One level of $ interpretation is done first
...
Note particularly the last sentence, which I assume means that the <>
contents get interpretation like m// or the LHS of s/// (what Jeffrey
call ``doublequotish'' processing in Hip Owls).
This means that the loop is equivalent to
while (glob "@array")
{
...
}
and as an interpolated array yields a space ($") separated list of
words, this calls csh to glob them. Which is why I said expensive; on
my machine this triggers:
/bin/sh -c "/usr/bin/csh -cf
'set nonomatch; glob one two three' 2>/dev/null"
Bleeaah. Although if @array actually contained metacharacters this
may be useful, using glob rather than <> would be clearer:
@file_pats = qw(*.c);
push @file_pats, '*.c++' if $show_cplusplus;
push @file_pats, '*.h' if $show_includes;
while (glob "@file_pats") { ... }
Regards,
--
Brendan O'Dea bod@compusol.com.au
Compusol Pty. Limited (NSW, Australia) +61 2 9809 0133
------------------------------
Date: 6 Apr 1997 07:42:23 GMT
From: gej@spamalot.mfg.sgi.com (Gene Johannsen)
Subject: Re: A beginer's Regular Expression problem
Message-Id: <5i7k4v$ia3@murrow.corp.sgi.com>
ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
| [A complimentary Cc of this posting was sent to l wang; ENME
| <lwang2@gl.umbc.edu>],
| who wrote in article <33471029.5AD8@gl.umbc.edu>:
| > Hi experts:
| >
| > The following code is expected to output nothing, but strange enough it
| > outputed as
| >
| > >matchedAA
|
| No it does not.
|
| Hope this helps,
| Ilya
I concur. Printed nothing for me, either.
gene
------------------------------
Date: Sun, 06 Apr 1997 11:00:53 +0200
From: Magnus Holmberg <pucko@lysator.liu.se>
Subject: Re: conversion windows to unix
Message-Id: <33476645.6CC2@lysator.liu.se>
A magic Store wrote:
>
> Does anybody know where can I find a program to convert windows text
> into unix text (basically without the new-line caracter \n).
> I'm having problem uploading my cgi script to my unix server.
>
> Any help will be appreciated !
>
> Max
> max@amagicstore.com
#!/usr/local/bin/perl
# Remove Control M's ^M
# Matt Wright (mattw@worldwidemart.com)
# Version 1.0 (http://worldwidemart.com/scripts/)
# Created on: 10/95 Last Modified on: 12/7/95
while (<>) {
$_ =~ s/\cM\n/\n/g;
print $_;
}
# To use this script, type:
# rm_cont_m.pl infile > outfile
# This script will remove those pesky control M's off of the end of your
# scripts after you have edited them in DOS or Windows.
# The infile should be the name of the file you want to remove control
# m's from and the outfile should be a different file where you want to
# redirect the output to. Don't use the infile as the outfile or it
will
# remove your original file. :-(
# If you do not specify an outfile, then the script will print the
contents
# to the screen.
# Ths script has no error checking, and is very simple.
\\\|///
\ ~ ~ /
(\ , , /)
----------o000--(_)--000o---------------------------------------------
| |
| Magnus Holmberg E-Mail : pucko@lysator.liu.se |
| Bjvrnkdrrsgatan 4b.35 n94magho@midgard.liu.se |
| 584 36 Linkvping n94magho@isy.liu.se |
| tel: 013-4730119 gud@internetaddress.com |
| HomePage: http://www.lysator.liu.se/~pucko/ |
______________________________________________________________________
------------------------------
Date: 6 Apr 97 09:57:27 GMT
From: "o" <o@o.com>
Subject: HEELLPP!!!!!!
Message-Id: <01bc4257$6a56e980$1f05d5cf@mangum>
Im really new to perl how would i make a cgi script that when you type a
web address into a textbox and press submit it will take you to the address
if you can make this simple script or you can tell me how
THANK YOU
mangum@westworld.com
------------------------------
Date: 6 Apr 1997 04:03:50 -0700
From: jimr@aubrey.stanford.edu (James A. Robinson)
Subject: Re: HEELLPP!!!!!!
Message-Id: <5i7vum$uko@aubrey.stanford.edu>
In article <01bc4257$6a56e980$1f05d5cf@mangum>, o <o@o.com> wrote:
> Im really new to perl how would i make a cgi script that when you type a
> web address into a textbox and press submit it will take you to the address
> if you can make this simple script or you can tell me how
I'm sending you a private note to explain what you need to do, but for
others who have similer questions you really should ask them in
comp.infosystems.www.authoring.cgi
comp.infosystems.www.authoring.html
Hint: CGI.pm available at http://www.perl.com/CPAN/ will help.
Jim
--
Jim Robinson <jim.robinson@stanford.edu> - http://highwire.stanford.edu/~jimr/
HighWire Press -- Stanford University
------------------------------
Date: Sun, 06 Apr 1997 13:25:14 +0200
From: "Magnus Holmberg." <pucko@lysator.liu.se>
Subject: Re: HEELLPP!!!!!!
Message-Id: <3347881A.6B3E@lysator.liu.se>
o wrote:
>
> Im really new to perl how would i make a cgi script that when you type a
> web address into a textbox and press submit it will take you to the address
> if you can make this simple script or you can tell me how
> THANK YOU
> mangum@westworld.com
I did something like this an it works. But this is just my second try to
make a perlscript so mabe it is a very stupid vay to do.
/ Pucko - The Water Of Life!
--
The script!
#!/usr/local/bin/perl
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$FORM{$name} = $value;
}
print "location: $FORM{'url'}\n\n";
The Html-code yoy need.
<HTML>
<HEAD>
<TITLE>I LIKE BEER!</TITLE>
</HEAD>
<FORM METHOD="POST"
ACTION="http://www.host.topdomain/cgi-bin/script.cgi">
Go to url:
<br><INPUT NAME="url"><p><BR>
<INPUT type=submit value="DO IT!">
<INPUT type=reset value="CLEAR!">
</CENTER>
</FORM>
</BODY>
</HTML>
------------------------------
Date: Sun, 06 Apr 1997 12:29:49 +0200
From: "Magnus Holmberg." <pucko@lysator.liu.se>
Subject: Loop-Problem....
Message-Id: <33477B1D.43F2@lysator.liu.se>
Hi Experts!
Hope you understand my very bad english.
I've just tried to write my first perlscript byt it doesn't work in that
way I want. The meaning is that it should send a e-mail to every adress
that I've stored in the file mailfile, but it loops one time to much and
write to dead.letter. Can someone tell me what to change?
THANKS!
/ Pucko - The Water Of Life!
#!/usr/local/bin/perl
$mailprog = '/usr/lib/sendmail';
$file= '/home/pucko/mailfile';
open(ADDRESS, "/home/pucko/address_file") || die "could not open file
($!)";
while(<ADDRESS>) {
chop;
$address=$_;
&SendEmail;
}
sub SendEmail
{
open(INFO, $file);
@lines = <INFO>;
close(INFO);
open(MAIL, "|$mailprog -t") || die &NiceQuit("Can't open
$mailprog!");
print MAIL "To: $address\n";
print MAIL "From: pucko\@lysator.liu.se\n";
print MAIL "Subject: A test\n\n";
print MAIL "\n";
print MAIL "\n\n";
print MAIL
"---------------------------------------------------------\n";
print MAIL "\n";
print MAIL "@lines\n";
print MAIL " \n";
print MAIL
"---------------------------------------------------------\n";
close (MAIL);
}
------------------------------
Date: 6 Apr 1997 10:41:04 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Loop-Problem....
Message-Id: <5i8cm0$rlc@panix.com>
In <33477B1D.43F2@lysator.liu.se> "Magnus Holmberg." <pucko@lysator.liu.se> writes:
>Hope you understand my very bad english.
Your English is better than my Swedish.
>I've just tried to write my first perlscript byt it doesn't work in that
>way I want. The meaning is that it should send a e-mail to every adress
>that I've stored in the file mailfile, but it loops one time to much and
>write to dead.letter. Can someone tell me what to change?
Who is the Email message addressed to in the dead.letter file?
>#!/usr/local/bin/perl
>$mailprog = '/usr/lib/sendmail';
>$file= '/home/pucko/mailfile';
>open(ADDRESS, "/home/pucko/address_file") || die "could not open file
>($!)";
>while(<ADDRESS>) {
> chop;
> $address=$_;
>
>&SendEmail;
Maybe you want to pass the address as a parameter for the SendEmail
subroutine:
&SendEmail("$address");
>}
>sub SendEmail
>{
>
> open(INFO, $file);
Why don't you test this open?
> @lines = <INFO>;
> close(INFO);
> open(MAIL, "|$mailprog -t") || die &NiceQuit("Can't open
>$mailprog!");
I assume the NiceQuit subroutine is somewhere.
> print MAIL "To: $address\n";
> print MAIL "From: pucko\@lysator.liu.se\n";
> print MAIL "Subject: A test\n\n";
>
> print MAIL "\n";
> print MAIL "\n\n";
> print MAIL
>"---------------------------------------------------------\n";
> print MAIL "\n";
> print MAIL "@lines\n";
> print MAIL " \n";
> print MAIL
>"---------------------------------------------------------\n";
>
> close (MAIL);
>}
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: Sun, 06 Apr 1997 10:44:46 +0200
From: Bo Svderquist <sbo@unix.okg.se>
Subject: Multiple mail!
Message-Id: <3347627E.6EC4@unix.okg.se>
I like to send a mail to a nuber of adresses that I have in a file calld
adressfile. How can I do to get it to work?
I also wunder hov to do to cut only the head from a message and save it
in a file.
--
\\\|///
\ ~ ~ /
(\ , , /)
----------o000--(_)--000o---------------------------------------------
| |
| Magnus Holmberg E-Mail : pucko@lysator.liu.se |
| Bjvrnkdrrsgatan 4b.35 n94magho@midgard.liu.se |
| 584 36 Linkvping n94magho@isy.liu.se |
| tel: 013-4730119 gud@internetaddress.com |
| HomePage: http://www.lysator.liu.se/~pucko/ |
______________________________________________________________________
------------------------------
Date: 06 Apr 1997 11:19:21 +0200
From: sperber@informatik.uni-tuebingen.de (Michael Sperber [Mr. Preprocessor])
Subject: Re: Ousterhout and Tcl lost the plot with latest paper
Message-Id: <y9l67y0pkyu.fsf@modas.informatik.uni-tuebingen.de>
>>>>> "JO" =3D=3D John Ousterhout <ouster@tcl.eng.sun.com> writes:
JO> - It is possible to make languages with execution speeds like C or=
C++,
JO> that use dynamic typing successfully, whilst being high-level enoug=
h
JO> in the creation of abstractions to "glue" things together quite
JO> nicely and easily.
JO> Can you point to a specific language and identify a large community of
JO> users who agree with this assessment?
The Scheme implementations Gambit-C and Bigloo achieve both pretty
satisfactorily. Their highly optimizing compilers get quite close to
the execution speed of C (I've seen both perform faster on some stuff,
slower on other stuff). Both have fully developed C interfaces. It's
not really a question of "agreement," as these are already language
*implementations* that fulfill the requirements stated above.
--
Cheers =3D8-} Mike
Friede, V=F6lkerverst=E4ndigung und =FCberhaupt blabla
------------------------------
Date: Sun, 6 Apr 1997 12:07:12 GMT
From: jack@cwi.nl (Jack Jansen)
Subject: Re: Ousterhout and Tcl lost the plot with latest paper
Message-Id: <jack.860328432@news.cwi.nl>
ouster@tcl.eng.sun.com (John Ousterhout) writes:
> For example,
>there is a real-time Tcl application containing several hundred thousand
>lines of code that controls a $5 billion oil well platform and (much to
>my shock) it seems to be quite maintainable.
> [...]
>The oil well application
>actually subdivides into a whole bunch of small tasks, so it's really
>more like 500 smaller programs. Also, if the application is
>fundamentally gluing (i.e. the complexity is in the interconnections)
>then switching to a more strongly typed language will just make things
>worse.
I find this very hard to believe. With languages like Python or Tcl, with
no interface definitions whatsoever, you can only *hope* that you use
every interface correctly. I work on a largish project in Python, and
the one thing that gives continuous headaches is the lack of interface
definitions. Whenever you change an interface it is very very
difficult to check that you haven't inadvertantly broken something.
--
--
Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@cwi.nl | ++++ if you agree copy these lines to your sig ++++
http://www.cwi.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm
------------------------------
Date: 06 Apr 1997 05:19:19 -0700
From: "Graham C. Hughes" <graham.hughes@resnet.ucsb.edu>
Subject: Re: Ousterhout and Tcl lost the plot with latest paper
Message-Id: <87d8s8jqck.fsf@A-abe.resnet.ucsb.edu>
-----BEGIN PGP SIGNED MESSAGE-----
>>>>> "Donald" == Donald Syme <drs1004@cl.cam.ac.uk> writes:
Donald> Trash. Show me C++ which is as succinct and I may believe
Donald> you.
How much do you want? I've found that STL makes my code incredibly
brief, and with the correct toolkit (I like Qt), windowing isn't that
hard, either. Better, you can subclass existing components so you can
create a new widget, something you can't do in Tcl/Tk without
resorting to C extensions.
This is an aside, however; the real issue is that Tcl/Tk is a
glorified macro processor, full of weird tricks. Try explaining why
you can't pass an array, or why 'set $$foo bar' doesn't work some
time. *This* is the reason why Tcl/Tk is ``concise''; everything is a
string. Where else can we find:
- lists where accessing anything is an O(n) operation
- numbers that autoconvert when you don't want them to (on
east coast area codes, for example)
- non-extensible mathematical expressions (think expr here)
- call by name
- dynamic scoping
and other assorted nastiness. Even Perl is a breath of fresh air
compared to this.
I have nothing but good things to say about Tk. Its incarnation in
other languages like Scheme, Python, Perl, and O'Caml are very nice,
and in the correct language (I know Python does this, not sure about
the others) you can even subclass widgets. Tcl, however, is something
else entirely, and I reject it for anything except trivial programs
out of hand.
- --
Graham Hughes http://A-abe.resnet.ucsb.edu/~graham/ MIME & PGP mail OK.
const int PGP_fingerprint = "E9 B7 5F A0 F8 88 9E 1E 7C 62 D9 88 E1 03 29 5B";
#include <stddisclaim>
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3
Charset: noconv
Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface
iQCVAwUBM0eU1iqNPSINiVE5AQH7jgQAmWUpvQGnNmGUshzygBnonh+OrK7iO3Uq
+11DSwDQVsg9DsOfB3HNqD1H4qguNPe2DXZBHRS25DiYhBEXLr+1nWMibtyAvgD1
44xA+qPRyzzq2MQ31XCRjKqAMzQC7XCr7LUotRm5f3GbElouweATfRzrUfgZ+a32
px5rYhG001Y=
=J2TS
-----END PGP SIGNATURE-----
------------------------------
Date: 6 Apr 1997 13:10:58 GMT
From: James Lee <jlee@math.purdue.edu>
Subject: Re: Ousterhout and Tcl lost the plot with latest paper
Message-Id: <5i87d2$drr@mozo.cc.purdue.edu>
] 2. Many people objected to the fact that their favorite programming
] was left out of the white paper. Yes, I have heard of Scheme,
] Smalltalk, ML, etc. I left these languages out because they
] didn't seem particularly relevant for the discussion. No offense
] intended...
Why were they irrelevant? Your paper concentrates on system and
scripting languages exclusively while ignoring an entire genre of
languages that may offer the features you're looking for in both.
] - It is possible to make languages with execution speeds like C or C++,
] that use dynamic typing successfully, whilst being high-level enough
] in the creation of abstractions to "glue" things together quite
] nicely and easily.
]
] Can you point to a specific language and identify a large community of
] users who agree with this assessment? Many people have made claims like
] this to me, but no one has been able to point to a good real-world
] example. The white paper argues that you can't have a jack-of-all-trades
] language. Either you have a strongly typed language, which gives high
] speed and manageability but makes gluing hard, or you have a weakly
] typed language with the opposite properties.
Gambit-C is an exceptionally effecient Scheme -> C optimising compiler.
I believe the author, Marc Freeley, also has a Tk interface in the works.
] His arguments on "typeless" languages is useless.
] You don't need a "scripting language" to
] get usable abstractions without the need
] to deal with low-level issues.
]
] button .b -text Hello! -font {Times 16} -command {puts hello}
]
] In Macintosh Common Lisp I'll write this as:
]
] (make-instance 'button-dialog-item
] :dialog-item-text "Hello"
] :view-font '("Times" 16)
] :dialog-item-action (lambda (item) (print "hello")))
]
] I think this example supports my claim that scripting languages are a
] lot easier to use when you need to mix and match lots of things of
] different types. The MCL example is a lot more verbose and complicated
] than the Tcl example.
I disagree entirely and would like to know what grounds you base your
reaction on. The MCL example is certainly no more "complicated" and
the verbosity of the classes and accessors is a symptom common to Lisp
programmers but not enforced by the language itself. This usually aids
in readability (and hence reusability) although the example given above
doesn't illustrate this aspect very well.
James Lee -- <jlee@math.purdue.edu>
------------------------------
Date: Sun, 06 Apr 1997 12:22:43 +0000
From: Matthew Knight <matt@geenite.demon.co.uk>
Subject: Perl and NT
Message-Id: <33479593.281F@geenite.demon.co.uk>
I use Perl on a UNiX box at the moment, but I've been asked to develop a
site which will sit on an NT server.
What is the easiest way of getting Perl for an NT machine, is a case of
getting an NT Perl port, sticking it on the server, and then
referenceing it in the the usual way...
i'd be grateful if anyone who knows how to do it, could you email me at
matt@geenite.demon.co.uk
thanks alot
Matt Knight
------------------------------
Date: Sun, 6 Apr 1997 08:07:44 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Question: Using perl to execute shell commands
Message-Id: <0778i5.qo.ln@localhost>
Randy Hootman (randy@randysoft.com) wrote:
: Jason J. Levit wrote:
: >
: > Hi everyone,
: >
: > I'm trying to use perl to execute some simple shell commands, but
: > since they're built into the shell (i.e., sh, csh, tcsh, etc.), perl
: > can't
: > seem to handle them. For example, if I the perl command:
: >
: > system 'source $name';
: >
: > or
: >
: > system 'setenv $name';
: >
: > ...both of these come up with the shell error 'source: command
: > not found'. Obviously, /bin/sh/source doesn't exist, since it's
: > built into the shell. However, I do have the need of sourcing
: > some files and setting some environment variables to run another
: > program, which actually uses these environment variables to run.
: > The perl script handles passing various values to be input into
: > the program...does anyone know how I can get around this?
: You can invoke the shell in front of the other commands:
: system 'csh source $name';
^^^^^^^^^^^^^^^^^^^^^^^^^
Which will have _no_ visible effect!
system() runs as a subprocess, so when the system() call ends,
the environment modifications you just made go away when the
system()'s process goes away...
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 6 Apr 1997 10:22:59 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Simple array question by newbie...
Message-Id: <5i8bk3$qhu@panix.com>
In <334530C1.749C@cstr.ed.ac.uk> Laurence Molloy <lauriem@cstr.ed.ac.uk> writes:
>Alan Weiner wrote:
>>
>> <SNIP>
>>
>> $nxtMonth=getNxtMonth("Mar");
>> print "$nxtMonth";
>>
>> sub getNxtMonth {
>>
>> <SNIP>
>>
>The problem is a missing "&".
>In perl, to call a subroutine you must prefix the name of the subroutine
>with an ampersand thus
>$nxtMonth=&getNxtMonth("Mar");
>is what you want.
Maybe this was true in the god ol' days, but it isn't anymore. From
perlsub <http://www.perl.com/CPAN/doc/manual/html/pod/perlsub.html>:
To call subroutines:
NAME(LIST); # & is optional with parentheses.
NAME LIST; # Parentheses optional if pre-declared/imported.
&NAME; # Passes current @_ to subroutine.
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: Sun, 06 Apr 1997 08:56:07 -0400
From: Aaron Sherman <ajs@ajs.com>
Subject: Re: Sorting a text file?
Message-Id: <3347AB77.4AE5@ajs.com>
Park J. H. wrote:
>
> Burt Lewis wrote:
> > I have a text file that for example looks something like this:
> > This part of my code works fine, I just can't get sorting by specific column.
> You can use map function for this kind of sorting.
>
> @sorted = map{ $_->[0] } sort {$a->[1] cmp $b->[1]}
> map {/^\S+ +\S+ +(\S+) +\S+ +\S+/ && [$_, $1] } @lines;
Yes, this works, but if you don't need to preserve spacing, it's
easier as:
@lines = map {[split]} <FILE>;
@sorted_lines = sort {$a->[1] cmp $a->[1]} @lines;
Now, if you want to compare multiple fields:
@sorted_lines = sort {$a->[1] cmp $a->[1] ||
$a->[2] <=> $a->[2]} @lines;
Of course, as you point out, map is your friend, and I would use
it to re-assemble the strings:
print <OUTFILE> map {join ' ', @$_} @sorted_lines;
A combination of the two approaches yields:
%lines = map {($_, [split])} <FILE>;
@sorted = sort {$lines{$a}->[1] || $lines{$b}->[1]} keys %lines;
In this case, the resulting @sorted is a list of lines with their
original spacing. But, this is probably less efficient, and clearly
sucks lots of memory. For a large file, this would be a problem.
If the file is quite large, sometimes you're better off taking
the large performance hit to split the lines inside of the
sort. Otherwise, you can read the files, and save line number
information and JUST the fields that you want to sort. Then re-
read the file, printing lines by sorted line numbers. This
saves some memory.
-AJS
------------------------------
Date: 06 Apr 1997 08:03:45 -0600
From: Vladimir Alexiev <vladimir@cs.ualberta.ca>
Subject: Re: string comparision
Message-Id: <ombu7s5jum.fsf@tees.cs.ualberta.ca>
In article <5i427m$jia$1@mathserv.mps.ohio-state.edu> ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
> > $ perl -e 'print "\x80" cmp "\x7F", "\n";'
> > -1
> Upgrade. This particular bug in (Solaris?) CRT was discovered only
> recently, so perls starting from 5.003_16 (or around) check for it
> before the build.
Platform:
osname=sunos, osver=4.1.4, archname=sun4-sunos
uname='sunos sunkay 4.1.4 5 sun4m '
This is perl, version 5.003 with EMBED
built under sunos at Jul 10 1996 23:39:20
+ suidperl security patch
------------------------------
Date: Sun, 06 Apr 97 11:42:26 GMT
From: tomw@tsys.demon.co.uk (Tom Wheeley)
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <860326946snz@tsys.demon.co.uk>
In article <qgi5i5.4i.ln@localhost> tadmc@flash.net "Tad McClellan" writes:
> : No, *more* competition. The main force stifling competition in the computer
> : world is that of standards. If your product does not fit the standard then
> ^^^^^^^^^^^^^^^^^^^^
> : it will not sell in significant amounts. Microsoft understand and exploit
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> : this fact in order to prromulgate bg-ware as the standard; thus driving out
> : the competition.
>
> As exemplified by the close adherence to the HTML standard by
> Microsoft and Netscape? ;-)
But they do fit the standard; they just support extensions. Notice that they
*have* to support each others extensions in order to fit the new standard.
--
:sb)
------------------------------
Date: Fri, 4 Apr 1997 18:05:19 GMT
From: msohnius@novell.co.uk (Martin Sohnius x24031)
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <E84Kwv.467@ukb.novell.com>
Tom Wheeley (tomw@tsys.demon.co.uk) wrote:
: In article <5hiupr$svu@idiom.com> jsi@idiom.com "Michael Craft" writes:
: > > > You want a more productive capitalism? Scrap the copyright and
: > > > patent laws and let the little guy, who has invented *everything*,
: > > > unleash his creativity and capitalism will have a fighting chance;
: > > > otherwise, socialism is better in all ways than capitalism, which
: > > > inevitably leads to monopolization if it weren't for interference
: > > > by the state.
: > >
: > > Uh -- patents were invented to *protect* the little guy. Otherwise,
: > > everytime the "little guy" invented something, the "big guy" would
: > > simply use the idea, and blow out the little guy because of much
: > > greater resources.
: >
: > Then what value is the "little guy" if he is unable to compete?
: >
: > If the patent and copyright laws were revoked the assets of the
: > "big guy" would be substantially depleted as it is economic protection
: > by the state that gives the "big guys" their awesome power.
: Bollocks. Imagine if there were no patent laws, and Pharmacy, Ltd. discover
: paracetamol.
For our friends in the U.S.: he means Tylenol.
: They would still be charging a hundred pounds per pill today;
: were it not for the _openness_ afforded by the patent system which allows
: smaller medical companies to sell boxes of 100 paracetamol tablets for 1 pound.
[...]
: You are thinking of the software industry, where there is mis-use of copyright
: laws. There is no glasnost after x years in this industry.
There is. Except that the "x" is rather large, like 100 years or so
(depending on where you are), compared to more like 10 or 20 years for
patents.
: Believe me, the patent system was designed to encourage invention and
: openness by protecting the little guy. Copyright was designed to protect
: authors of printed works. The choice is whether you define software as
: Science (where knowledge is shared) or as literature. The fact is that due
: to the malleability of software, it is science.
Huh? Is science mallable? Or, for that matter, is the sharing of science
free? (Any idea what an annual subscription to something like "Nuclear
Physics B" or "Journal of Physics G" costs? You'd be amazed!)
But your basic point is correct: over the centuries, science or, more
widely, "the stuff that's done at universities" has developed an ethos
where knowledge comes into the public domain at the moment it is published,
with only a curtesy requirement to name the originator when using it,
rather than pay him or her. In parallel, the whole system of university
positions has developed, with peer review for advancement (based on how
much knowledge was released by the researcher into the public domain), and
funded by the tax-paying public or by fee-paying students (who are paying
for the research even though they really just want an education).
Do you see this as a model for the software industry? (Sometimes I do,
but then I used to be an academic boffin, too!)
--
*******************************************************************
Martin F. Sohnius msohnius@novell.co.uk
Novell IS & T, Bracknell, England +44-1344-724031
*******************************************************************
* if (status = UNDER_NUCLEAR_ATTACK) *
* launch_full_counterstrike(); *
*******************************************************************
(C) 1997 M.F.Sohnius -- free distribution on USENET
(Not a spokesperson -- just a cyclist!)
------------------------------
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 242
*************************************