[13258] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 668 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 28 13:07:39 1999

Date: Sat, 28 Aug 1999 10:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 28 Aug 1999     Volume: 9 Number: 668

Today's topics:
        RE: broker <webmaster@compre-ya.com>
    Re: Bug Report: Perl5 - Passing =~ Expression to a Subr (M.J.T. Guy)
    Re: essentially; making a long file name into a 8.3 fil <kin@0011.com>
    Re: essentially; making a long file name into a 8.3 fil <wyzelli@yahoo.com>
        help with signal handler <yeeliu@convex.hhmi.columbia.edu>
    Re: help with signal handler (Larry Rosler)
        How do I ... ? (Pete Holsberg)
        IRC CONNECT <webmaster@compre-ya.com>
    Re: keep contents of new file when user ctrl-c's? (M.J.T. Guy)
    Re: keep contents of new file when user ctrl-c's? <meowing@banet.net>
        RE: Matching E-mail <webmaster@compre-ya.com>
    Re: mirror.pl on OS/2 Question <huffd@nls.net>
        Parsing 'Content-Disposition' Header on the fly with LW (Brian Reilly)
        RE: passing hidden varible between scripts <webmaster@compre-ya.com>
    Re: Pattern Matching (Abigail)
    Re: Perl.exe has an interpreted mode? <revjack@radix.net>
        Regular expression syntax? <treetops@icon.co.za>
    Re: Regular expression syntax? (Abigail)
        Removing <HTML> Tags <rob.slattery@amaonline.com>
    Re: Removing <HTML> Tags <jkline@one.net>
    Re: Removing <HTML> Tags (Abigail)
    Re: Removing <HTML> Tags <revjack@radix.net>
        Removing a line from a text file (Greg Shalette)
    Re: sorting a delimited string by second field <kin@0011.com>
    Re: sorting a delimited string by second field (Larry Rosler)
    Re: The extent of double-quotish interpolation (Randal L. Schwartz)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 26 Aug 1999 19:53:37 -0300
From: "Webmaster" <webmaster@compre-ya.com>
Subject: RE: broker
Message-Id: <7q3rho$s6f$1@vnews.prima.com.ar>

I´ve done it with PHP, and strongly recommend it for running shell commands.


Igor Vinokurov <igor@rtsnet.ru> escribió en el mensaje de noticias
37c52a6f.0@news.rtsnet.ru...
> Hello.
>
> There is a necessity to run on remote server (unix host) some
> administrative commands (create user, create home directory etc)
> from script on local host.
>
> I plan to realize it, as client/server.
>
> For example simple session:
>
> C: telnet host 106
> S: 200 broker ready
> C: USER admin
> S: 300 please send the PASS
> C: PASS adminpassword
> S: 200 login OK
> C: adduser user
> S: 200 OK
> C: QUIT
> S: 200 broker connection closed
>
> Well, from what to begin? :)
>
> How I understand, to me the unit Net::Daemon is necessary?
>
> Probably, someone already has written something similar?
>
> Probably, there are guidelines on writing such programs?
>
> --
> Igor Vinokurov
>
> P.S: Please add Cc: igor@rtsnet.ru when replying if possible.
>




------------------------------

Date: 28 Aug 1999 12:22:37 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Bug Report: Perl5 - Passing =~ Expression to a Subroutine
Message-Id: <7q8kad$eb8$1@pegasus.csx.cam.ac.uk>

Y2K Fear Not <Yikes2000@yahoo.com> wrote:
>
>Thank you.  And just to clarify, the ("" =~ /[c]/) in printArg( ("" =~
>/[c]/), 2, 3 ) is treated in the scalar context by Perl5.004.04, but
>in Perl5.005.02, it is a list?  (as it should be).

Actually, the problem wasn't wrong context  -  it was that a failed match
in list context returned the list ('') of length one, rather than the
list of length zero as documented.    This bug was present in all versions of
Perl5 up to 5.004_04, and is mended in 5.004_05 and 5.005+  (and Perl4
got it right as well  :-).


Mike Guy


------------------------------

Date: Sat, 28 Aug 1999 05:07:54 -0700
From: Kin Lum <kin@0011.com>
Subject: Re: essentially; making a long file name into a 8.3 filename..
Message-Id: <37C7D11A.77B78EE6@0011.com>

Jim Matzdorff wrote:
> I want to essentially take a string that is a long filename, with any
> number of periods being replaced by "_" except for the last, all to make
> it into a 8.3 valid format.

I think the following solution is the most complete so far:

#!/usr/local/bin/perl

test("thislongfile.name");
test("a.long.file.description");
test("noextention");
test("no_extention");
test("thislongfilehello");
test("hello");
test("hi");
test("a");
test("0.abcdefghijklm");
test("abc.db");
test("abc.");
test(".c");
test(".cshrc");
test(".cshrc123456789");
test("a.b");
test("0.0");

sub test {
    my $s = shift;
    printf "%-30s =>   %-30s\n", $s, conv($s);
}

sub conv {
    my $s = shift;

    if ($s !~ /\./) { $s =~ /(.{1,8})(.{0,3})/; return ($2 ne "") ? "$1.$2" : $1; }
    $s =~ /(.*)\.(.*)/;
    my $base = $1;  my $ext = $2;
    if ($base eq "") { return conv("_$ext"); }
    $base =~ s/(.{8}).*/$1/;
    $base =~ s/\./_/g;
    $ext =~ s/(.{3}).*/$1/;
    return ($ext ne "") ? "$base.$ext" : $base;
}

Output:
=======
thislongfile.name              =>   thislong.nam
a.long.file.description        =>   a_long_f.des
noextention                    =>   noextent.ion
no_extention                   =>   no_exten.tio
thislongfilehello              =>   thislong.fil
hello                          =>   hello
hi                             =>   hi
a                              =>   a
0.abcdefghijklm                =>   0.abc
abc.db                         =>   abc.db
abc.                           =>   abc
 .c                             =>   _c
 .cshrc                         =>   _cshrc
 .cshrc123456789                =>   _cshrc12.345
a.b                            =>   a.b
0.0                            =>   0.0


I think Larry's solution is very nice, short and
elegant.  There are a few catches, however, and
I can't seem to fix it using Larry's solution:

thislongfilehello              =>   thislong.llo
hello                          =>   he.llo
0.abcdefghijklm                =>   0_abcdef.klm
 .c                             =>   .c
 .cshrc                         =>   _cs.hrc
 .cshrc123456789                =>   _cshrc12.789

Gabor's solution and mine produce very similar
results.  

incidentally, it seems filenames such as ".login"
or  "abc."  are not valid 8.3 filenames.
I took the liberty of converting  ".cshrc"
to "_cshrc" instead of considering it to be invalid.

If you consider getting the famous owl regular
expressions book, please consider getting it from 
  http://www.0011.com/books/perl
and help a poor programmer!


------------------------------

Date: Sat, 28 Aug 1999 23:35:16 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: essentially; making a long file name into a 8.3 filename..
Message-Id: <t0Sx3.26$j_4.1450@vic.nntp.telstra.net>

Kin Lum <kin@0011.com> wrote in message news:37C7D11A.77B78EE6@0011.com...
> Jim Matzdorff wrote:
> > I want to essentially take a string that is a long filename, with any
> > number of periods being replaced by "_" except for the last, all to make
> > it into a 8.3 valid format.
>
> I think the following solution is the most complete so far:
>
> #!/usr/local/bin/perl
>
> test("thislongfile.name");
> test("a.long.file.description");
> test("noextention");
> test("no_extention");
> test("thislongfilehello");
> test("hello");
> test("hi");
> test("a");
> test("0.abcdefghijklm");
> test("abc.db");
> test("abc.");
> test(".c");
> test(".cshrc");
> test(".cshrc123456789");
> test("a.b");
> test("0.0");
>

what about :
thislongfilehello
thislongfilehell0
thislongfilehello1

etc?

Wyzelli




------------------------------

Date: Fri, 27 Aug 1999 10:44:58 -0400
From: Yee Liu <yeeliu@convex.hhmi.columbia.edu>
Subject: help with signal handler
Message-Id: <37C6A46A.EFE2D330@convex.hhmi.columbia.edu>

Hi,

I wonder if I can get some help with the following simple piece of code
:

#!/bin/perl -l
$SIG{HUP} = \&hup_handler;
init();

sub init() {
    print "init";
    sleep;
}
sub hup_handler() {
    print "hup receiverd";
    init();
}


What I want is a little program that sits there and waits, do something
when it receives
a HUP signal and then waits again. The above code worked only with the
first HUP signal it received, but it does not work when subsequent HUP
signals were sent. What is wrong here?

Thanks,

yee




------------------------------

Date: Sat, 28 Aug 1999 09:05:27 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: help with signal handler
Message-Id: <MPG.1231a899e209e16b989ec1@nntp.hpl.hp.com>

In article <37C6A46A.EFE2D330@convex.hhmi.columbia.edu> on Fri, 27 Aug 
1999 10:44:58 -0400, Yee Liu <yeeliu@convex.hhmi.columbia.edu> says...
> #!/bin/perl -l
> $SIG{HUP} = \&hup_handler;
> init();
> 
> sub init() {
>     print "init";
>     sleep;
> }
> sub hup_handler() {
>     print "hup receiverd";
>     init();
> }
> 
> What I want is a little program that sits there and waits, do something
> when it receives
> a HUP signal and then waits again. The above code worked only with the
> first HUP signal it received, but it does not work when subsequent HUP
> signals were sent. What is wrong here?

Signal handlers need to be reestablished after being used.  Move the 
assignment to $SIG{HUP} into init().

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 28 Aug 1999 16:24:26 GMT
From: pjh@mccc.edu (Pete Holsberg)
Subject: How do I ... ?
Message-Id: <7q92fq$1t5$1@lawrenceville.mccc.edu>


I'm reading fixed length values into a set of variable
(data file is a screen dump) and the values are of course
padded with trailing blanks. (I'm trying to convert each
screen's values into a line of delimited field values.)

Is there a simply way to eliminate those blanks? 

Thanks,
Pete
--
Pete Holsberg
MCCC
Trenton, NJ


------------------------------

Date: Thu, 26 Aug 1999 03:41:30 -0300
From: "Webmaster" <webmaster@compre-ya.com>
Subject: IRC CONNECT
Message-Id: <7q22j2$47s$1@vnews.prima.com.ar>

Does anyone of you know a perl script or someway to connect to a irc server
from perl???

Thx

Gastón Gorosterrazú
webmaster@compre-ya.com
http://www.compre-ya.com




------------------------------

Date: 28 Aug 1999 12:36:02 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: keep contents of new file when user ctrl-c's?
Message-Id: <7q8l3i$f1f$1@pegasus.csx.cam.ac.uk>

In article <87u2pwd90v.fsf@banet.net>, meow  <meowing@banet.net> wrote:
>
>      There are some gotchas when dealing with signal handlers, but
>most of them don't really matter if you're going to terminate the
>process anyway.

Sadly, that's not true.   For example, if you happen to be in the stdio
routines when the signal happens, and you close the file in the
handler, you could get a mangled file.

Of course, the various windows are quite small, so programs will mostly
"seem to work".    But that's not a wise way of proceeding.

In a signal handler, you should restrict yourself to either a die()
(with a constant argument) or setting a preallocated flag variable.


Mike Guy


------------------------------

Date: 28 Aug 1999 09:04:14 -0400
From: meow <meowing@banet.net>
Subject: Re: keep contents of new file when user ctrl-c's?
Message-Id: <87aercoy41.fsf@banet.net>

M J T Guy <mjtg@cus.cam.ac.uk> wrote:

> In article <87u2pwd90v.fsf@banet.net>, meow  <meowing@banet.net> wrote:
>> 
>>      There are some gotchas when dealing with signal handlers, but
>> most of them don't really matter if you're going to terminate the
>> process anyway.

> Sadly, that's not true.   For example, if you happen to be in the stdio
> routines when the signal happens, and you close the file in the
> handler, you could get a mangled file.

Can you show an example of this happening in that context?  A report
file was being created and a report being written sequentially, with
autoflush on.  Abrupt termination of the output is expected; where
does the mangling come in?


------------------------------

Date: Thu, 26 Aug 1999 03:38:17 -0300
From: "Webmaster" <webmaster@compre-ya.com>
Subject: RE: Matching E-mail
Message-Id: <7q22d1$47k$1@vnews.prima.com.ar>

if ($form{'email'} =~ /.+\@.+/)
{
            ALL RIGHT!
}



Winter <tungyat@yahoo.com> escribió en el mensaje de noticias
2G4v3.5979$dr6.134029@news1.rdc2.on.home.com...
> Hi,
>
> Can anyone write a regular expression to detect email address? I have a
line
> of string $str may or may not contain email adress..
>
> Thanks in advance for you help, if you can help, please send it to
> ty.wong@utoronto.ca
>
> Regards,
> Winter
>
>




------------------------------

Date: Sat, 28 Aug 1999 16:13:12 GMT
From: "David D. Huff Jr." <huffd@nls.net>
Subject: Re: mirror.pl on OS/2 Question
Message-Id: <37C80947.BB77D4F3@nls.net>

Thank you, I will compose future questions using those guidelines.


> >And can give instruction without witticisms.
>
> That'd be me, then.
>
>
> The main reason you're getting unhelpful responses is that you've
> given people almost nothing to work with.  Perhaps you think that
> everyone is familiar with 'mirror.pl', but that's such a generic
> name for a program that there are probably a dozen scripts called
> that littering the Perl repositories.
>
> You need to post the relevant section of code which is failing to
> delete the files (cut and paste, don't type it in), along with the
> exact error message (not the hint you've given us).  Then you'll
> cease being sport and become someone worth helping.
> --
> Malcolm Ray                           University of London Computer Centre



------------------------------

Date: Sat, 28 Aug 1999 15:05:58 GMT
From: reillyb@gusun.georgetown.edu (Brian Reilly)
Subject: Parsing 'Content-Disposition' Header on the fly with LWP
Message-Id: <37c7fb48.0@bandit>

I'm looking for some suggestions on the best way to use LWP to grab the 
'filename=whatever' value in an HTTP Response 'Content-Disposition' header 
and save the content as that filename.

Basically I want to mimic the 'Save As' feature in Netscape, but save as 
the default filename and not prompt the user for one.

Code snippet:
-----
$request2v2 = new HTTP::Request('POST', "$MY_URL/download.pl");
$request2v2->header('Connection' => 'Keep-Alive');
$request2v2->header('accept' => '*/*');
$request2v2->content('action=Download+All');

$ua2v2 = new LWP::UserAgent;
$response2 = $ua2v2->request($request2v2,'/tmp/filename');
$response2->header('content-disposition');
-------------

i.e. for 
Content-Disposition: filename="foo.tar"

I'd like to have my program save the content as /tmp/foo.tar instead of 
/tmp/filename.  

Is it possible to get the value of 'Content-Disposition', pause my HTTP
requset while I get the filename value, and then save the content as that
filename? 

Any help would be much appreciated.

Thanks,

Brian
--
Georgetown University
<reillyb@gusun.georgetown.edu>



------------------------------

Date: Thu, 26 Aug 1999 19:56:09 -0300
From: "Webmaster" <webmaster@compre-ya.com>
Subject: RE: passing hidden varible between scripts
Message-Id: <7q3rmg$s6n$1@vnews.prima.com.ar>

There´s no problem with that. you pass the hidden variable as another form
object. and read it without difficulty.


<kidbunny@my-deja.com> escribió en el mensaje de noticias
7q2jkc$37p$1@nnrp1.deja.com...
> Is it possible for a first cgi script (written in
> PERL), that generates a HTML form to pass along a
> hidden varible (so it's not shown in the
> navigation bar) to the second cgi script when the
> form is posted?
>
> Something like...
>
> print "<form method=post
> action=%%/cgi-bin/secondscript.cgi%%>";
> print "<input type=%%hidden%% name=%%notseen%%
> value=%%,$secertid,%%";
> print "<input type=submit name=%%callnextcgi%%
> value=%%go%%>";
>
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.




------------------------------

Date: 28 Aug 1999 10:42:26 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Pattern Matching
Message-Id: <slrn7sg10l.tt.abigail@alexandra.delanet.com>

Bart Lateur (bart.lateur@skynet.be) wrote on MMCLXXXVIII September
MCMXCIII in <URL:news:37cbbd13.2265052@news.skynet.be>:
() 
() Yup. Note that these options:
() 
() 	print quotemeta($pattern);
() and
() 	print "\Q$pattern\E";
() 
() will insert them (only) where necessary, for you.


     $pattern = ";";
     print "\Q$pattern\E";

How `necessary' is that backslash?
Note that the \E isn't needed in this case.


Abigail
-- 
perl -wle 'print "Prime" if ("m" x shift) !~ m m^\m?$|^(\m\m+?)\1+$mm'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: 28 Aug 1999 14:56:31 GMT
From: revjack <revjack@radix.net>
Subject: Re: Perl.exe has an interpreted mode?
Message-Id: <7q8tav$q2c$2@news1.Radix.Net>
Keywords: Hexapodia as the key insight

elephant explains it all:

:oh god - here we go .. don't tell me they've changed it in Windows98

Yes. Empirical testing here yields the following results:

       |    ^D        ^Z
-------+-------------------
Win NT |   runs     runs
       |
Win 98 |   runs     exits
       |
Win 95 |   runs     exits

Different perl builds may conceivably yield different results.


------------------------------

Date: Sat, 28 Aug 1999 17:22:35 +0200
From: " Warren Brown" <treetops@icon.co.za>
Subject: Regular expression syntax?
Message-Id: <7q8ush$2va$1@news.is.co.za>

Hi

I'm reading a file from the disk, but I want to write certain lines to
another file.
Basically those lines contain the words smap, bytes but not the words exits
and <>.

I am using the expressiion

if ( (m/smap/) && (m/bytes/) && ! (m/exits/)  && (m/\<\>/) print FILE $_

I thought this was working fine, until I checked it against the following:-

cat testfile| grep smap|grep bytes|grep -v exits grep -v \<\> > outfile.

I would think that both these files would contain the same data, but the
perl script file is larger than the cat file.
Also if I change the perl script to send any data that doesn't match to
another file, the two file sizes don't match up to the original file size.

Any help would be appreciated.

Thanks







------------------------------

Date: 28 Aug 1999 10:49:19 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Regular expression syntax?
Message-Id: <slrn7sg1di.tt.abigail@alexandra.delanet.com>

 Warren Brown (treetops@icon.co.za) wrote on MMCLXXXVIII September
MCMXCIII in <URL:news:7q8ush$2va$1@news.is.co.za>:
'' 
'' if ( (m/smap/) && (m/bytes/) && ! (m/exits/)  && (m/\<\>/) print FILE $_
'' 
'' I thought this was working fine, until I checked it against the following:-
'' 
'' cat testfile| grep smap|grep bytes|grep -v exits grep -v \<\> > outfile.

Are you sure? Both the Perl line and the shell line contain errors,
and should not work at all. The Perl line is missing a ')', and '{',
'}', while the shell line misses a `|'.  After inserting the necessary
characters, the Perl line insists on having '<>' in the line, while the
shell line insists on *not* having '<>' there.

Of course, a simple 'diff' between the files should have revealed that.



Abigail
-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: Sat, 28 Aug 1999 09:29:09 -0500
From: "Rob S" <rob.slattery@amaonline.com>
Subject: Removing <HTML> Tags
Message-Id: <njSx3.1204$586.6242@newsfeed.slurp.net>

I need to remove <html> tags
for a project I'm working on.

How can I do this? I suspect
there is a module I can use. I don't
want to reinvent the wheel here.
I just want to strip everything
inside the <> markers.

Thanks very much,
Rob Slattery
--
rob.slattery@amaonline.com
http://members.amaonline.com/chicago/
http://www.srh.noaa.gov/ama/




------------------------------

Date: Sat, 28 Aug 1999 11:19:11 -0400
From: Joe Kline <jkline@one.net>
Subject: Re: Removing <HTML> Tags
Message-Id: <37C7FDEF.3E7109A4@one.net>

Rob S wrote:
> 
> I need to remove <html> tags
> for a project I'm working on.
> 
> How can I do this? I suspect
> there is a module I can use. I don't
> want to reinvent the wheel here.
> I just want to strip everything
> inside the <> markers.

Have you given www.perl.com or CPAN a look? There are many fine wheels
to be found there.

If you want a very simple/stupid solution:

s!<[^>]+?>!!g;

I recommend the fine modules to be found in CPAN.

joe


------------------------------

Date: 28 Aug 1999 10:50:44 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Removing <HTML> Tags
Message-Id: <slrn7sg1g7.tt.abigail@alexandra.delanet.com>

Rob S (rob.slattery@amaonline.com) wrote on MMCLXXXVIII September
MCMXCIII in <URL:news:njSx3.1204$586.6242@newsfeed.slurp.net>:
 .. I need to remove <html> tags
 .. for a project I'm working on.
 .. 
 .. How can I do this? I suspect
 .. there is a module I can use. I don't
 .. want to reinvent the wheel here.
 .. I just want to strip everything
 .. inside the <> markers.

If you don't want to reinvent the wheel, why don't you bugger off to
the FAQ instead of reinventing one of the 10 most asked questions in
this group?

I think you're just plain lazy.


Abigail
-- 
perl -e 'for (s??4a75737420616e6f74686572205065726c204861636b65720as?;??;??) 
             {s?(..)s\??qq \?print chr 0x$1 and q ss\??excess}'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: 28 Aug 1999 16:27:42 GMT
From: revjack <revjack@radix.net>
Subject: Re: Removing <HTML> Tags
Message-Id: <7q92lu$54c$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight

Joe Kline explains it all:

:s!<[^>]+?>!!g;
        ^^
I keep seeing '+?'

What does it mean? "One or more or zero"?

Wouldn't '*' work better?


------------------------------

Date: 28 Aug 1999 12:35:19 -0400
From: gshalet@panix.com (Greg Shalette)
Subject: Removing a line from a text file
Message-Id: <7q9347$89l$1@panix3.panix.com>

How does one remove a line of text from the middle of a text file
in perl?  Is rewriting the file without the line the only way
or is their a function?  Thanks.
-- 

Greg Shalette
gshalet@panix.com


------------------------------

Date: Sat, 28 Aug 1999 05:22:18 -0700
From: Kin Lum <kin@0011.com>
Subject: Re: sorting a delimited string by second field
Message-Id: <37C7D47A.DB780EBC@0011.com>


LinksNetwork Admin wrote:
> I have an array of delimited strings, which I would like to sort by the
> second field.
> 17|Afghanistan
> 18|Albania
> My question is basically, how can I form an expression to return just the
> second part of each record, to include in a sort{} operation?

you can use something like this:
($i,$name) = split(/\|/, "26|Australia");

for making the sort call, use something like

@sorted = sort byName @array;

sub byName {
  # split ...   $a  $b

  lc($nameA) cmp lc($nameB);  # lc to make lower case
}

the books Learning Perl and Programming Perl could
help you a lot:
  http://www.0011.com/books/perl
getting books there will help support me
as a poor programmer.


------------------------------

Date: Sat, 28 Aug 1999 09:30:47 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: sorting a delimited string by second field
Message-Id: <MPG.1231ae9629d6ad2c989ec2@nntp.hpl.hp.com>

In article <37C7D47A.DB780EBC@0011.com> on Sat, 28 Aug 1999 05:22:18 -
0700, Kin Lum <kin@0011.com> says...
> 
> LinksNetwork Admin wrote:
> > I have an array of delimited strings, which I would like to sort by the
> > second field.
> > 17|Afghanistan
> > 18|Albania
> > My question is basically, how can I form an expression to return just the
> > second part of each record, to include in a sort{} operation?
> 
> you can use something like this:
> ($i,$name) = split(/\|/, "26|Australia");
> 
> for making the sort call, use something like
> 
> @sorted = sort byName @array;
> 
> sub byName {
>   # split ...   $a  $b
> 
>   lc($nameA) cmp lc($nameB);  # lc to make lower case
> }

If the list is short, or processing time is irrelevant, this naive 
approach is acceptable.  But it repeats the same computation over and 
over every time two variables are compared.  There are several ways to 
do the computation only once per variable and to store the results for 
further use in comparisons.

See `perldoc -f sort`, perlfaq4: "How do I sort an array by (anything)", 
or the comprehensive paper at 
<URL:http://www.hpl.hp.com/personal/Larry_Rosler/sort/>.

> the books Learning Perl and Programming Perl could
> help you a lot:
>   http://www.0011.com/books/perl
> getting books there will help support me
> as a poor programmer.

At least you are open about getting kickbacks if your links are used.  
But I wonder about the propriety of such a posting.  Others haven't been 
as honest, and this trend is proliferating. 

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 28 Aug 1999 08:17:13 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: The extent of double-quotish interpolation
Message-Id: <m1aerc2ava.fsf@halfdome.holdit.com>

>>>>> "Randal" == Randal L Schwartz <merlyn@stonehenge.com> writes:

Randal> It's not.  It's a slice (closer to an "array" than "list").

Argh.  What was I thinking.  You can't take a reference to a slice,
so it doesn't exist as an array.  <sigh>

Sometimes, I should wait 12 hours after I compose something before I
post.

Ignore me here. :-)

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu. 

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 V9 Issue 668
*************************************


home help back first fref pref prev next nref lref last post