[7442] in Perl-Users-Digest
Perl-Users Digest, Issue: 1067 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 23 23:07:12 1997
Date: Tue, 23 Sep 97 20:00:33 -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, 23 Sep 1997 Volume: 8 Number: 1067
Today's topics:
Re: "here document" method of print erroring (Abigail)
Re: abs() function <stuartc@ind.tansu.com.au>
Array or Hash? <asmith@hsonline.net>
Configuring my autoexec.bat file to run Perl??? <jwc@idt.net>
Re: Deleting Files <dankogai@dan.co.jp>
Re: Getting backreferences from global pattern match? (Mike Stok)
Re: Getting next array element in a foreach <rpsavage@ozemail.com.au>
Re: Help: Give Perl to an uneducated slob & this is wha (Eric)
Re: How to redirect standard output of a backtick comma (Adrian Pepper)
How to telnet from perl using cron? (Don)
Re: Installing Perl modules w/o root? (Tad McClellan)
Re: Need help with pesky warning... <david.s.patterson@boeing.com>
Re: Need tokenizer code; example from FAQ doesn't seem (Brendan O'Dea)
Re: Nested subs and local vs my (Faust Gertz)
Re: perl mail on solaris (brian d foy)
Re: perl mail on solaris (Jason Gloudon)
Re: Printing perl - Win'95 <youngej@magpage.com>
Simulating POST method w/ PERL. <byron@teleport.com>
Re: sorting on 1 column in a record of columns (Mike Stok)
Re: UDP Server (Michael Fuhr)
Updating a field in a file <amhardin@erols.com>
Re: Where is perl/Tk for Win32 <youngej@magpage.com>
Re: Where is PerlShop to be found? (brian d foy)
why localize vars in foreach? psj@cgmlarson.com
Windows 95/NT GUI program with perl? (CherngJyh Lin)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 24 Sep 1997 01:29:08 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: "here document" method of print erroring
Message-Id: <EGzo4L.6BA@nonexistent.com>
change "void" to "kf8nh" (bsa@void.apk.net) wrote on 1483 September 1993
in <URL: news:3426a181$1$ofn$mr2ice@speaker.kf8nh.apk.net>:
++ In <EGuFxK.Ho9@nonexistent.com>, on 09/21/97 at 05:44 AM,
++ abigail@fnx.com (Abigail) said:
++ +-----
++ | ++ I am using the "here document" style of the print command and it is not
++ | ++ working correctly for me. please lemme know if I'm doing everything ++
++ | Are you sure you have the above fragment? No blanks after
++ | END_OF_TEXT? Perhaps a trailing ^M ?
++ +--->8
++
++ Is he using Perl 4, by any chance? Neither Perl3 nor Perl4 worked right when
++ combining print() and here documents (no output); in Perl 5 it works.
$ /usr/local/bin/perl -w
print <<EOT;
Foo bar
EOT
__END__
Foo bar
$ /usr/local/bin/perl -v
This is perl, version 4.0
$RCSfile: perl.c,v $$Revision: 4.0.1.6 $$Date: 91/11/11 16:38:45 $
Patch level: 19
Copyright (c) 1989, 1990, 1991, 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 4.0 source kit.
$
Abigail
------------------------------
Date: 24 Sep 1997 11:04:29 +1000
From: Stuart Cooper <stuartc@ind.tansu.com.au>
Subject: Re: abs() function
Message-Id: <yeon2l3zfmq.fsf@kudu.ind.tansu.com.au>
helen@panix.com (Helen Shen) writes:
> Here is my code
>
> $sNetExcep = ($NetLimit - abs($entityNet)) > 0 ?
> 0 : ($NetLimit - abs($entityNet));
>
> it's suppose to return a non-zero value if $entityNet is a larger number
> than $NetLimit, but it doesn't.
>
> am I using abs() incorrectly?
Well it does return non-zero on my machine, Helen. You're doing this in
an unnecessarily complicated and convoluted way. If you want to know if
entityNet is larger than NetLimit; simply use:
(abs($entityNet) > $NetLimit) # this is true if it's larger, false otherwise.
eg if $NetLimit is 100; it's true if $entityNet < 100 and $entityNet > -100; ie
-100 < $entityNet < 100
If all you want $sNetExcep to be is non-zero for $entityNet outside the
limit and 0 for inside the limit:
$sNetExcep = (abs($entityNet) > $NetLimit);
will do the trick.
($A > $B) is usually seen after an "if" statement; eg
if ($A > $B) {
print "A greater than B\n";
}
but it's actually an expression of it's own that evaluates to 0 (false)
or non-zero (true).
Hope this helps,
Stuart Cooper
stuartc@ind.tansu.com.au
------------------------------
Date: Tue, 23 Sep 1997 21:46:12 +0000
From: Andy Smith <asmith@hsonline.net>
Subject: Array or Hash?
Message-Id: <Pine.LNX.3.96.970923214123.337A-100000@drews.drews.net>
Why is perl trying to make a hash out of @services? Is there something i
need to do to make it see the variable as an array instead?
--------------------
@services={"witha","smile","anda","one","two",};
open(AFILE ">afile")
$n=0;
while($n<5)
{print AFILE {$services[$n]};
++$n
--------------------
thanks,
-Andy-
----Andy Smith ------ reply to: ----------------
-KB9KQD- (asmith@hsonline.net)
" Everybody knows that the dice are loaded,
Everybody rolls with their fingers crossed;
Everybody knows that the war is over,
Everybody knows that the good guys lost..."
-Leonard Cohen-
------------------------------
Date: Tue, 23 Sep 1997 22:30:28 -0400
From: John Coviello <jwc@idt.net>
Subject: Configuring my autoexec.bat file to run Perl???
Message-Id: <34287B44.7006@idt.net>
Could anyone tell me the proper text to enter in my autoexec.bat file to
run Perl? The book I have isn't very clear. I am running Windows 95.
--
John Coviello
Web Developer/Technical Documentation Specialist
Vice President, Frontier Research Seminars
http://idt.net/~jwc
------------------------------
Date: Wed, 24 Sep 1997 11:32:10 +0900
From: Dan Kogai <dankogai@dan.co.jp>
Subject: Re: Deleting Files
Message-Id: <34287B61.622A@dan.co.jp>
Melinda wrote:
> Can anyone tell me how to delete a file ?
unlink $afile;
Gee, I've answered this kind of question before. so let me make it a
bit different from what I posted before.
To delete a file via perl, you use unlink(). To be more precise, the
function removes directory entry of that file on Unixen. Unixen
consider the file deleted when a file (to be more exact, i-node) has no
reference from any directory. Consult "man unlink" for details. Though
the idea of file links does not apply to other systems such as DOS/Win
and Macs, Perl's unlink() is mapped to file deletion function on
corresponding systems (At least Win32 version of Perl and MacPerl did).
If you are uncontent with the name of the function (note delete()
deletes a hash entry), You can still use system(). This is often
convenient when you want to delete entire directory.
__END__
Dan the Camel Abuser
------------------------------
Date: 24 Sep 1997 00:09:59 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Getting backreferences from global pattern match?
Message-Id: <609lon$5hn@news-central.tiac.net>
In article <609e7r$fcs$1@newbabylon.rs.itd.umich.edu>,
Sean McAfee <mcafee@battlezone.rs.itd.umich.edu> wrote:
>I have a file containing lines of the form:
>
>A:abc B:xyz A:123 B:456 A:foo B:bar ...
>
>...where the A, B pair can repeat an arbitrary number of times. I want to
>extract the strings after the colon in each pair and store them in arrays
>@A and @B. This doesn't work:
>
>while (/A:(\S+) B:(\S+)/g) {
> push(@A, $1);
> push(@b, $2);
>}
>
>$1 and $2 are apparently never set, as I get only null strings in @A and
>@B (although I do get the correct *number* of null strings). I can't find
>any reason in the docs why this should be so. Can anyone shed some light
>on the situation for me? Thanks in advance.
Is that really what your code says? In the debugger I can do this:
DB<1> $line = 'A:abc B:xyz A:123 B:456 A:foo B:bar'
DB<2> while ($line =~ /A:(\S+) B:(\S+)/g) { push @A, $1; push @B, $2; }
DB<3> X A
@A = (
0 'abc'
1 123
2 'foo'
)
DB<4> X B
@B = (
0 'xyz'
1 456
2 'bar'
)
... maybe there's another match operation between the condition of the
while and the pushes?
Can you post a segment of your code "unsimplified" for us to see?
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: Wed, 24 Sep 1997 09:44:11 +1100
From: Ron Savage <rpsavage@ozemail.com.au>
Subject: Re: Getting next array element in a foreach
Message-Id: <3428463B.5537@ozemail.com.au>
Robert Crooks wrote:
>
> Gip wrote:
> >
> > How would one go about getting the next element after finding an element
> > in an array, using a foreach:
> >
> > # assume for this ex that the @array contains b d h t
> > foreach $item (@array) {
> >
> > if ($item eq "d") {
> >
> > # the next line is where my problem is; I want the next item 'h'!
> > $next_item = ??? ; # I've tried shift unshift pop push
> > $last;
> > }
> >[snip]
Or,
while ($element = pop(@array) )
{
# $element is non-null. If null, we dropped out of the loop.
if ($element eq $required) || ($element == $required)
{
$next = pop(@array);
process..
}
}
------------------------------
Date: 24 Sep 1997 01:26:31 GMT
From: pojo@gte.net (Eric)
Subject: Re: Help: Give Perl to an uneducated slob & this is what ya get
Message-Id: <609q87$gi8$1@gte2.gte.net>
On Mon, 25 Aug 1997 22:46:39 +1000, Michael Artz
<martz@standard.net.au> wrote:
>Ok
>Here's my problem:
>I have written the code to do almost everything, after buying a text.
>However I need to do the following.
>The program reads a text file, comma delimited & prints each line to
>seperate files
>The fields are presented thus:
>"AAA","Aristocrat","wda",2.30.etc
>I can split the file on the commas, but I need to get rid of the " from
Don't use the split() funciton, as it will (improperly) split fields
that are quoted yet containing commas ("field1", "hello, mom",
"field3", "field4"). This is a "split on whitespace blocks, except
when quoted" field splitter:
@words= ();
push(@words, $+) while $tag =~ m{(\"[^\"]*\"){1}|([^\s\"]+)}gx;
Modified for commas (haven't tried it yet, YMMV):
@words= ()
push(@words, $+) while $tag =~ m{(\"[^\"]*\"){1}|([^\,]*)}gx;
>those fields that have it.
>
>Also To save the files I have the following code... is there an easier
>way?
>$extension = ".csv";
>$code = $code.$security;
>$thisRecord="$date,$code,$issuer,$open,$close,$low,$high,$vol\n";
> $thisFile=$code.$extension;
>
>#print the data to a file and begin a new one
>open (OUTFILE, ">$thisFile") || die("Can't open output file");
> print OUTFILE ($thisRecord);
> close OUTFILE;
>
>Thanks in advance...
>I know this is very basic.... but then so am I
>Mick Artz
------------------------------
Date: Tue, 23 Sep 1997 22:33:00 GMT
From: arpepper@math.uwaterloo.ca (Adrian Pepper)
Subject: Re: How to redirect standard output of a backtick command
Message-Id: <EGzFz1.I1@undergrad.math.uwaterloo.ca>
daniel@2020tech.com wrote,
in article <5vklbn$ckf$1@wn.aksi.net>:
>
>Pierre BERGDOLT (Pierre.Bergdolt@ansf.alcatel.fr) wrote:
>: Hi perl fans,
>
>: I'm trying to redirect the standard output of a perl backtick command
>: (wich is run in a subshell) to the standard output of my perl script.
>
[...]
>
>Elementary.
>
> open (COMMAND,"cmd |");
> while ($line=<COMMAND>) {
> print $line;
> @log = (@log,$line);
> };
> close(COMMAND);
>
>BTW, I don't really know is the "close(COMMAND)" line is necessary. You
>would think that Perl closes commands automatically when they terminate...
>after all, what more can you do with the handle COMMAND after that?
According to the Camel book (p.342), under the UNIX implementation,
"close(COMMAND)" causes Perl to actually do the wait for the
termination of the process, and at that point sets $? to the process
exit status. (The process may in fact close its standard output,
thereby generating the EOF, long before it terminates).
Although you may have received an EOF on a UNIX file descriptor, it is
not automatically closed then and is not available for re-allocation
until you do close it. However, according to the Camel book (p. 13),
Perl *is* clever enough to automatically close the real file descriptor
associated with a Perl file handle which is re-opened before closing.
Note that file handles are global symbols and do not go out of scope,
so file descriptors and handles cannot be automatically tidied up at
scope exit time.
In short, failure to match every open() with a corresponding close() is
sloppy.
There is the possibility that the command producing the output may not
terminate even after sending you the EOF. In that case, you may need
to use an alarm call to generate a signal to interrupt the wait inside
the close. That sounds quite messy. To get that degree of control you
would probably want to write your own pipes, forks, execs, and waits,
thereby bypassing more convenient methods such as backticks and piped
opens. And in that case you may want to handle the case where the
command does not return an EOF in reasonable time either.
Assume I have some sort of disclaimer here in case I have a mistake
in the above...
Adrian Pepper
Math Faculty Computing Facility
University of Waterloo, Ontario, Canada
arpepper@math.uwaterloo.ca
------------------------------
Date: Wed, 24 Sep 1997 00:44:36 GMT
From: defike@ilstu.edu_nospam (Don)
Subject: How to telnet from perl using cron?
Message-Id: <34286124.2839678@news.alt.net>
I have been struggling with setting up a cron that runs a perl script
which executes a telnet. The script runs the way it should via the
command line. When trying to run it from a cron it always fails at
the telnet portion. I have tried this using a shell script and Expect
and everything will work via command line but fails when trying to
cron. I tried declaring the term env but that wasn't enough.
Suggestions are welcomed.
Thanks,
Don
defike@ilstu.edu
------------------------------
Date: Tue, 23 Sep 1997 21:18:49 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Installing Perl modules w/o root?
Message-Id: <9at906.fb6.ln@localhost>
peter@widgetworks.com wrote:
: I've installed many perl libraries into the standard library directory
: as root for years... Now I need to install some libraries on a system
: that has Perl 5.003 installed, but to which I do not have root
: access. To wit, I need to install these modules into my home
: directoty. Anyone know how to do this?
: Compiling perl and maintaining my own complete library is *not* an
: option.
Perl FAQ, part 8:
"How do I keep my own module/library directory?"
Guess you missed that when you checked before posting...
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 23 Sep 1997 23:33:08 GMT
From: "David S. Patterson" <david.s.patterson@boeing.com>
Subject: Re: Need help with pesky warning...
Message-Id: <342851B4.7D55@boeing.com>
Thanks for all the wonderful suggestions. They all worked,
for the most part. I found that the best solution was simply
to move from perl 5.002, (I was mistaken in my original note
to say that I was running 5.003) to perl 5.003 or better; the
warnings do not occur at all in those versions.
Regards,
-Dave Patterson
Tad McClellan wrote:
>
> I myself wrote:
>
> : print " [$3]" if $3;
>
> Uhhh, better make that:
>
> print " [$3]" if defined($3); # ;-)
>
> --
> Tad McClellan SGML Consulting
> tadmc@flash.net Perl programming
> Fort Worth, Texas
--
"A couple of months in the laboratory can frequently save a couple of
hours in the library..."
David S. Patterson, Software Engineer
------------------------------
Date: 23 Sep 1997 23:34:03 GMT
From: bod@compusol.com.au (Brendan O'Dea)
Subject: Re: Need tokenizer code; example from FAQ doesn't seem to work
Message-Id: <609jlb$d42$1@diablo.compusol.com.au>
In article <6069ob$87r@athos.cc.bellcore.com>,
Christopher Lott <lott@bellcore.com> wrote:
>
>Dear Perl experts,
>
>If you can please find a moment, I would appreciate the help.
>I plucked this bit of code straight from the FAQ, where it is
>credited to Jeffrey Friedl:
>
[snip]
> m/ \G( \d+\b )/gx && do { print "number: $1\n"; redo; };
[snip]
>
>This snippet appears under the question "What good is \G in a regular
>expression?" in http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html
This snippet in the FAQ pages distributed with perl5.004 uses the new
/c modifier (ie. the lines should read "m/ \G(...) /gcx") and notes
that this modifier prevents a failed match from resetting the search
position back to the beginning of the string.
Regards,
--
Brendan O'Dea bod@compusol.com.au
Compusol Pty. Limited (NSW, Australia) +61 2 9809 0133
--
Gupmundur Steinar Jsnsson
------------------------------
Date: Wed, 24 Sep 1997 00:21:23 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: Nested subs and local vs my
Message-Id: <34285a8b.2165912@news.wwa.com>
On 18 Sep 1997 18:09:24 GMT, turnerj@cliffy.lmtas.lmco.com (Jim Turner
) wrote:
Why wasn't $b undefined during the first iteration of the loop?
> #!/usr/bin/perl
> for ($i=1;$i<4;$i++)
> {
> &outerfn($i);
> }
> sub outerfn
> {
> my ($b); #DEFINED WITHIN OUTERFN'S LEXICAL SCOPE.
> sub innerfn
> {
> $b = $i;
> print "--inner: b=$b=\n";
> }
>
> &innerfn;
> print "--outer: b=$b=\n";
$b could be undefined here and, in fact, it is through the second and
third interation through the loop. The -w tells us that we have a
use of an uninitialized value at this point. Why it is defined on the
first iteration, I don't know.
>
> }
>
>produces the following results:
>
>--inner: b=1=
>--outer: b=1=
I would think that this should be '--outer: b==' instead of '-outer:
b=1='.
>--inner: b=2=
>--outer: b== #SHOULDN'T THIS BE 2, WHY UNDEFINED?
>--inner: b=3=
>--outer: b== #SHOULDN'T THIS BE 3?
I can write a script so what the &innerfn does not affect the outerfn:
#!/usr/local/bin/perl -w
use strict;
for (1,2,3) { &outerfn($_) }
sub outerfn {
my ($b) = shift;
sub innerfn {
my ($b) = $_[0] + 1;
print "--inner: b=$b=\n";
}
print "--outer: b=$b=\n";
&innerfn ($b);
print "--outer: b=$b=\n\n";
}
--outer: b=1=
--inner: b=2=
--outer: b=1=
--outer: b=2=
--inner: b=3=
--outer: b=2=
--outer: b=3=
--inner: b=4=
--outer: b=3=
and I can follow what the values of the variables should be by looking
at the code. But I can't understand why $b was defined at 'print
"--outer: b=$b=\n";' in the original script. Would someone please
explain it to me?
TIA
Faust
------------------------------
Date: Tue, 23 Sep 1997 21:30:51 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: perl mail on solaris
Message-Id: <comdog-ya02408000R2309972130510001@news.panix.com>
In article <609jac$5d2@camel2.mindspring.com>, jaws@atl.mindspring.com wrote:
>#usr/local/bin/perl
>
>my $Mailto="jaws@mindspring.com";
>my $MailSubject="test email";
>
>open (DOMAIL, "| mail -s $MailSubject $Mailto");
>print DOMAIL <<"EndOfMessage";
>
>this is a test
>EndOfMessage
>
>The operating system things $MailSubject is another recipient...
especially since you have that embedded space in $MailSubject.
how about using sendmail instead:
#!/usr/bin/perl
open( MAIL, " | /usr/lib/sendmail -t -oi -odq " ) or die "$!\n";
print MAIL <<"MESSAGE";
To: $Mailto
From: foo\@bar.com
Subject: $MailSubject
this is a test message
MESSAGE
close MAIL;
__END__
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: 24 Sep 1997 02:17:16 GMT
From: jgloudon@bbn.remove.com (Jason Gloudon)
Subject: Re: perl mail on solaris
Message-Id: <609t7c$3jg$1@daily.bbnplanet.com>
John Armsby (jaws@atl.mindspring.com) wrote:
: the following script send Email but I do not get the subject. A
: recipient gets the body of the message only. Can anyone help? I am
: using perl 5.003 on a sun sparc 20 running /usr/bin/mail on solaris.
: #usr/local/bin/perl
: my $Mailto="jaws@mindspring.com";
: my $MailSubject="test email";
: open (DOMAIL, "| mail -s $MailSubject $Mailto");
: print DOMAIL <<"EndOfMessage";
: this is a test
: EndOfMessage
: The operating system things $MailSubject is another recipient...
: John
: jaws@mindspring.com
You could try using /usr/ucb/mailx, which is the version of the mailer
for which -s works.
Jason Gloudon
------------------------------
Date: 24 Sep 1997 00:36:14 GMT
From: Ed Young <youngej@magpage.com>
To: "Lynn. Rickards" <lynnr@lynn.softnet.co.uk>
Subject: Re: Printing perl - Win'95
Message-Id: <609n9u$6fg$2@204.179.92.76>
Lynn. Rickards wrote:
> This question arises out of my recent usage of Gurusamy Sarathy's
> excellent Win95/NT port of perl/TK... but I guess this is more
> a perl question:
>
> Printing under perl/unix (for my needs, anyway) is easy:
>
> open PRINTER, "| cat | lpr -h 2>/dev/null" or die "no printer: $!";
> print PRINTER $stuff_to_print;
>
> How do you achieve this under Win95? Printer selection would be nice,
> too - the default printer on my own '95 machine is an A1 plotter,
> so I'd like to be able to choose a more sensible alternative....
Try:
open PRINTER, "> lpt1" or die "no printer: $!\n";
print PRINTER "hello there printer...\n\f";
close PRINTER;
You may have to use lpt2, lpt3, or prn in the example above. When
setting up your printer you need to associate MS-DOS print jobs
with a port. To do this follow the trail:
Windows Explorer
Printers
(Your Printer)
Printer
Properties
Details
Port Settings
check Spool MS-DOS print jobs
Also note the trailing "\n\f". I needed them. Experiment to see
what you need.
This should be enough to get you started (I hope).
You might also get prepared for some flak about the unnecessary
"cat" in your example ;-)
------------------------------
Date: Tue, 23 Sep 1997 18:45:21 -0700
From: Byron Stuart <byron@teleport.com>
Subject: Simulating POST method w/ PERL.
Message-Id: <342870B1.1635A9A4@teleport.com>
I can't figure this out... I need to write a PERL script that
connects to a web site CGI script. I need the PERL script to
send a request to the web server's CGI script exactly like an
HTML form using the POST method would. So, the web server's CGI
script will respond back to me as if I were using a normal web
browser. I have no idea where to begin. I've looked at the LWP
lib, but can't figure out how to simulate a POST method, and send
the "form" to the server. Any help would be great.
Byron
------------------------------
Date: 24 Sep 1997 00:26:02 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: sorting on 1 column in a record of columns
Message-Id: <609mmq$68f@news-central.tiac.net>
In article <342851A0.3522C174@gsfc.nasa.gov>,
Jim Blackwell <jim.blackwell@gsfc.nasa.gov> wrote:
>Hi,
>
>I have a bunch of records that are separated by vertical bars. parsing
>isn't the problem. What I am trying to do is sort on one column such
>that the entire row is carried with it.
>
>Ex:
>
>col1 col2 col3
>
>aaaa bbb ccc
>true false whatever
>
>Say I want to reverse sort on the 3rd column. What I'd like to end up
>with is
>
>col1 col2 col3
>
>true false whatever
>aaaa bbb ccc
>
>How do I setup a sort so I get this sort of result ? I've done it in
>IDL easily since what you get back from its sort routine is an index so
>you can take and sort on one component and get the rest to follow by
>saying something like array1=array1(index)
>where index was an array of indicies of the sorted array.
If you want to do it that way you can do something like this if the data
is in 3 arrays @col1 .. @col3
@indices = sort {$col3[$b] cmp $col3[$a]} (0 .. $#col3);
@sortedCol1 = @col1[@indices];
@sortedCol2 = @col2[@indices];
@sortedCol3 = @col3[@indices];
If you have the data as
@data = ([qw/aaa bbb ccc /],
[qw/true false whatever/],
);
you can say
$col = 2;
@indices = sort {$data[$b][$col] cmp $data[$a][$col]} (0 .. $#data);
or sort the data directly:
@data = @data[sort {$data[$b][$col] cmp $data[$a][$col]} (0 .. $#data)];
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 23 Sep 1997 20:46:06 -0600
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: UDP Server
Message-Id: <609ute$qv2@flatland.dimensional.com>
andreas@ostenberg.ping.de (Andreas Roeschies) writes:
> how can I receive UDP-Messages on a specific Port? I didnt find help in the
> Lama nor in the Camel Book.
What version of the Camel do you have? I find this in the index of
the 2nd edition:
UDP communications, 354
Camel I has no such entry, but there are several references under
"sockets". Some manual pages to look at are perlfunc, perlipc,
Socket, and IO::Socket[1].
[1] IO::Socket is part of the IO package, included with Perl 5.004.
If you're still using an older version of Perl, you can get IO
from CPAN <http://www.perl.com/CPAN/>.
--
Michael Fuhr
http://www.dimensional.com/~mfuhr/
------------------------------
Date: Tue, 23 Sep 1997 10:13:00 -0400
From: "Annie P. Harding" <amhardin@erols.com>
Subject: Updating a field in a file
Message-Id: <3427CE6C.5156@erols.com>
I know this may be pretty simple, but i am new to this whole thing...
i am trying to search a file (text file with %% as delimeters) for
a string - once found, i need to update one of the counter fields in
that record - i was going to use splice to do a replacement of that
counter field but wasn't sure how to get the offset value. (I was using
grep to search the file) ... any advice would be appreciated!
annie
------------------------------
Date: 24 Sep 1997 00:05:18 GMT
From: Ed Young <youngej@magpage.com>
Subject: Re: Where is perl/Tk for Win32
Message-Id: <609lfu$6fg$1@204.179.92.76>
Weihan Chang wrote:
>
> Hi,
> I saw someone mentioned about a version of perl/Tk on Win32(Windows
> NT). Does anyone know where I can get a binary copy ?
> Thanks a lot.
ftp://ftp.sedl.org/pub/mirrors/CPAN/ports/win95/Standard/x86/
perl5.00402-bindist04-bc.tar.gz (5014 Kb)
This excellent binary distribution of perl 5.004_02 by
Gurusamy Sarathy (Just Another Perl Porter)
includes perl/TK for Win32. Install this version, get your PATH set,
then run widget for a perl/TK widget demonstration that is more or less
the same as the TCL/TK demo (not to mention very impressive)...
------------------------------
Date: Tue, 23 Sep 1997 21:26:39 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Where is PerlShop to be found?
Message-Id: <comdog-ya02408000R2309972126390001@news.panix.com>
In article <34284DFE.8AFC4D2@net55.com>, rh <rh@net55.com> wrote:
>Benjamin Holzman wrote:
>> http://www.arpanet.com/PerlShop/perlshop.html
>
>Thanks...but the link is 'dead'...
>I had tried it prior to posting my message.
>
>I hope someone has a current link for PerlShop
it works for me *shrug*. perhaps you should try again?
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: 24 Sep 1997 00:10:49 GMT
From: psj@cgmlarson.com
Subject: why localize vars in foreach?
Message-Id: <609lq9$9om$1@news1.ispnews.com>
Hi all,
I've just got a quick question here. Why is it that a variable is localized
inside a foreach loop? I got REALLY tripped up on that for a while today
with a hash containing a hard reference to a my() variable that I needed to
access inside that foreach. I worked around it, but this was annoying. IS
there a REAL reason for doing things this way? I'm just curious.
Thanks!
Pat
--
| Patrick St. Jean '97 XLH 883 psj@cgmlarson.com |
| Programmer & Systems Administrator +1 713-977-4177 x106 |
| Larson Software Technology http://www.cgmlarson.com |
------------------------------
Date: Wed, 24 Sep 1997 02:00:05 GMT
From: a00lcj00@mail.dt.nchc.gov.tw (CherngJyh Lin)
Subject: Windows 95/NT GUI program with perl?
Message-Id: <342872a9.3062520@netnews.nchc.gov.tw>
On Mon, 22 Sep 1997 03:07:50 GMT, a00lcj00@mail.dt.nchc.gov.tw
(CherngJyh Lin) wrote:
>Hello, everybody:
> I like perl language because it's so powerful!
>But I seldom saw this language with any GUI interface.
>Is it possible to embed or be embedded with other
>windows languages? Does there exist any solution to
>do this? Please inform me if you ever do this kind
>of job. Thanks in advance.
>
Sorry, I means how to write the "MS Windows 95/NT like" program
with perl! Perl/Tk is different from win95/NT program although
they had been porting to Win95/NT platform.....Yaaaa!
------------------------------
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 1067
**************************************