[6718] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 343 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 22 12:37:27 1997

Date: Tue, 22 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           Tue, 22 Apr 1997     Volume: 8 Number: 343

Today's topics:
     (no subject) charles@max-net.com
     Re: -e switch <ajs@ajs.com>
     Re: [Q] who to return images <dehon_olivier@jpmorgan.com>
     Re: [Q] who to return images <ajs@ajs.com>
     Re: [Q] who to return images (Bob Wilkinson)
     Document Contains No Data (Gregory Reddin)
     Re: Good editor for W95? (Fred Elbel)
     Re: help: find pattern, then go down 3 lines (David Alan Black)
     Re: help: find pattern, then go down 3 lines <ajs@ajs.com>
     Re: help: find pattern, then go down 3 lines (David Alan Black)
     Re: How do I make libperl.a a shared lib? (Matthew Cravit)
     How the !@#$%^&* does this relate to comp.lang.java.adv <wcrosman@tecoinc.com>
     Re: How to expand a variable in a string? (David Alan Black)
     Re: howto post to www-form from Perl? <ajs@ajs.com>
     Re: Matching <ajs@ajs.com>
     Re: Name that OS(unix,nt,?) question. <ajs@ajs.com>
     Re: Name that OS(unix,nt,?) question. (Andrew M. Langmead)
     Re: Name that OS(unix,nt,?) question. (Bob Wilkinson)
     Re: Ousterhout and Tcl lost the plot with latest paper (Bjarne Stroustrup)
     Re: Perl as its own metalanguage? <michaeli@dra.com>
     Perl CGI scripts under Windows NT iis 3.0 (Gregory Reddin)
     Re: Q: How to sort an array of arrays (David Alan Black)
     Re: Reading this will take seconds! (Nathan V. Patwardhan)
     sorting hashes on values <Hans.Suijkerbuijk@SD.BE>
     Substitute <mak@dfki.uni-sb.de>
     Re: Substitute (Nathan V. Patwardhan)
     Re: Substitute (David Alan Black)
     Re: Substitute <usenet-tag@qz.little-neck.ny.us>
     Variable interpolation (substitution) <j-adamson@tamu.edu>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 21 Apr 1997 15:49:46 -0700
From: charles@max-net.com
Subject: (no subject)
Message-Id: <335BEF0A.3C88@max-net.com>

 .


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

Date: Tue, 22 Apr 1997 10:32:27 -0400
From: Aaron Sherman <ajs@ajs.com>
To: Olivier Dehon <dehon_olivier@jpmorgan.com>
Subject: Re: -e switch
Message-Id: <335CCBFB.63D1@ajs.com>

Olivier Dehon wrote:
> 
> Bill Banyai <banyai@llnl.gov> writes:
> 
> >
> > I am a newby and just installed version 5.003_07 on Win95 100MHz
> > pentium.
> >
> > When I enter: perl -e 'print("hello\n");'
> > I see a blank line and then a c:\ on the next line; e.g.
> > c:\ perl -e 'print("hello\n");'

This got me at first too (not being a DOS guy, and expecting it
to be just like UNIX now that I've installed perl... ;-)

The problem is that DOS does not do '' like UNIX shells do. You
have to use "", which limits you a lot. Get used to using qq()
when you use perl from the command-line....

	perl -e "print qq(Hello\n)"

That should work.

			-AJS
-- 
Aaron Sherman			"We are, all of us, living in the shadow of
Safety Net Solutions		 Manhatten." -The Watchmen
Email: ajs@ajs.com
WWW: http://ajs.com/~ajs/


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

Date: 22 Apr 1997 14:41:13 +0100
From: Olivier Dehon <dehon_olivier@jpmorgan.com>
Subject: Re: [Q] who to return images
Message-Id: <njzybab9nuu.fsf@jpmorgan.com>

Roman@pussycat.ping.de (Roman Bloeth) writes:

> 
> I'm a perl-beginner and started learning perl for being able to write CGI- 
> scripts (isn't that one of the main uses for perl?). It's really easy to  
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Nope. Perl stands for Practical Extraction and Report Language. It is
used in quite a lot of systems. I mainly use it as a replacement for
awk, or do feasibility studies, or prototype large projects...

> return (HTML-) text from a perl program. But then I've seen perl-scripts  
> being called out of HTML-pages using <IMG SRC="your_perl_here.cgi">. So  
> doesn't that mean that these so invoked perl-scripts won't return text but  
> instead output images in a binary form?!
> How would one do this?

Well, I think you could have crossposted your article to
comp.infosystems.www.authoring.cgi ;-)

Your script needs to output a document that is an image. For instance,
your perl script would output:

--------8<------------------------
Content-type: image/gif

GIF87a<GIF binary data>
--------8<------------------------

You could use GD.pm, available at the CPAN, to generate GIF from a
Perl script.

Hope this helps.

Olivier Dehon.




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

Date: Tue, 22 Apr 1997 10:39:21 -0400
From: Aaron Sherman <ajs@ajs.com>
To: Roman Bloeth <Roman@pussycat.ping.de>
Subject: Re: [Q] who to return images
Message-Id: <335CCD99.3EB7@ajs.com>


Roman Bloeth wrote:

> output images in a binary form?!
> How would one do this?

Two questions here. First, you want to use binmode on the output
filehandle (e.g. binmode(STDOUT)) if you are running under
MSDOS or a variant (e.g. Windows). Then, you need to tell your
server that you are going to give it image data. This can be
accomplished by printing out the HTTP headers:

	print "Content-type: image/gif\n\n";

This will tell the browser to expect an image. Many other (MIME)
types are allowed. You can find them in any decent HTTP reference
or the MIME specs.

			-AJS

PS If you are using CGI.pm, you can just hand the content type
to it, see the manual for CGI.pm.

-- 
Aaron Sherman			"We are, all of us, living in the shadow of
Safety Net Solutions		 Manhatten." -The Watchmen
Email: ajs@ajs.com
WWW: http://ajs.com/~ajs/


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

Date: Tue, 22 Apr 1997 15:12:15 +0100
From: b.wilkinson@NOSPAM.pindar.co.uk (Bob Wilkinson)
Subject: Re: [Q] who to return images
Message-Id: <b.wilkinson-2204971512150001@ip57-york.pindar.co.uk>

In article <6VMu0xZ4jQB@pussycat.ping.de>, Roman@pussycat.ping.de (Roman
Bloeth) wrote:

> Hi folks!
> 
> I'm a perl-beginner and started learning perl for being able to write CGI- 
> scripts (isn't that one of the main uses for perl?). It's really easy to  
> return (HTML-) text from a perl program. But then I've seen perl-scripts  
> being called out of HTML-pages using <IMG SRC="your_perl_here.cgi">. So  
> doesn't that mean that these so invoked perl-scripts won't return text but  
> instead output images in a binary form?!
> How would one do this?
> 
> Awaiting a hint or two,
> Roman.
> 
> 
> Mutants for nuclear power! }-)

You've asked this question to the wrong newsgroup - try

comp.infosystems.www.authoring.cgi

for future questions of this ilk.

However, since I'm writing I may as well answer your question. Pages are, by
default, of the form text/html. This can be made explicit by passing a string
of form "Content-type: text/html" in the header of the HTTP page. If this header
said something like "Content-type: image/gif", this would specify that the data
which followed was an image of type gif. This "text/html" or "image/gif" bit is
the MIME type of the data.

Bob

-- 
I have become death, destroyer of the worlds.


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

Date: Tue, 22 Apr 1997 14:21:56 GMT
From: ranger@onramp.net (Gregory Reddin)
Subject: Document Contains No Data
Message-Id: <335cc8ee.65221044@news.onramp.net>


Hi again all:

Please excuse this message if you've already read it before in a
similar message. 

I have a simple URL selection script that keeps giving me "Document
Contains No Data" when using Netscape 3.01. The problem doesn't appear
when I'm using MSIE 3.02. I recently moved the website from Unix to
Window NT. All other Perl scripts work fine.

Can anyone help?

Thank you,

Gregory Reddin
greddin@objectspace.com


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

Date: Tue, 22 Apr 1997 14:06:59 GMT
From: felbel@NOSPAMcsn.net (Fred Elbel)
Subject: Re: Good editor for W95?
Message-Id: <3360c4b1.3466928@news-2.csn.net>


> I'm writing CGI scripts in perl on my W95 machine, and then uploading
> them to the Unix server.  I'm looking for recommendations on good
> editors that can easily save in a Unix format.

MultiEdit Pro
< http://www.amcyber.com >
800.899.0100

I've used it for years.  The current version is great!

Fred
--  Fred Elbel  felbel@NOSPAMcsn.net 
--      To e-mail: delete NOSPAM in my return address
--  How to eliminate junk mail and spam: 
--      http://www.csn.net/~felbel/jnkmail.html 



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

Date: 22 Apr 1997 12:55:27 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: help: find pattern, then go down 3 lines
Message-Id: <5jicfv$1vq@pirate.shu.edu>

Hello -

david@penney.mv.com (David Penney) writes:

>Hi,

>I have a file that I want to read and look for a pattern. When I find
>the pattern, I would like to go down 3 lines in the file and read in
>the value (actually the  5th and 6th character on that line but I
>think I can figure that one out) on that line and continue reading in
>the file. I'm pretty sure it's straightforward but am having trouble.
>Could someone help?

>while (<>)
>	if (/pattern/)
>		?????

One rather general purpose way (in case you need to catch
multiple or embedded occurrences) would be:

while (<>) {
    $to_do{$count+3}++  if /$pattern/;
    &do_me              if $to_do{$count++};
}


David Black
dblack@icarus.shu.edu


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

Date: Tue, 22 Apr 1997 10:21:40 -0400
From: Aaron Sherman <ajs@ajs.com>
To: David Penney <david@penney.mv.com>
Subject: Re: help: find pattern, then go down 3 lines
Message-Id: <335CC974.3C62@ajs.com>

David Penney wrote:
> 

> I have a file that I want to read and look for a pattern. When I find
> the pattern, I would like to go down 3 lines in the file and read in
> the value (actually the  5th and 6th character on that line but I
> think I can figure that one out) on that line and continue reading in
> the file. I'm pretty sure it's straightforward but am having trouble.
> Could someone help?

You can see two other approaches posted to the group, but here's
a tangential thought. Are you reading a file which has multi-line
records (e.g. several fields repeated over and over)? If so,
you would be better served (and your code would be more useful
the next time you have to deal with this file format) if you
read the file in a record at a time.

There are several ways to do this, depending on how you delimit
records. If you delimit with a unique string (e.g. two newlines
or __EOR__ or a nul, etc) you can set $/ to that string, and
then the <> operator will read one record at a time.

If the file is just a series of named fields, and the transition
between records is marked by an introductory field (e.g. From in
a UNIX mail archive), then you can just write a small state machine
which reads the file, and buffers the lines. When it hits the into
field name, it should send all buffered lines off to be processed
as a unit.

If the file is just a series of lines, and every n'th line marks
the beginning of a new record, you can use the method above, but
instead of waiting for a field name, just keep a counter, and send
the buffered lines off to be dealt with when you've read
count modulo lines-in-record lines.

For the last two approaches, you will need to check, after your
loop exits, to see if there are buffered lines pending, and send
them off to your routine that deals with a record.

Hope this helps.

			-AJS
-- 
Aaron Sherman			"We are, all of us, living in the shadow of
Safety Net Solutions		 Manhatten." -The Watchmen
Email: ajs@ajs.com
WWW: http://ajs.com/~ajs/


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

Date: 22 Apr 1997 13:22:31 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: help: find pattern, then go down 3 lines
Message-Id: <5jie2n$41a@pirate.shu.edu>

Hello -

Alastair Aitken <a.aitken@unl.ac.uk> writes:

>David Penney wrote:

>> I have a file that I want to read and look for a pattern. When I
>> find
>> the pattern, I would like to go down 3 lines in the file and read in
>>
>> the value (actually the  5th and 6th character on that line but I
>> think I can figure that one out) on that line and continue reading
>> in
>> the file. I'm pretty sure it's straightforward but am having
>> trouble.
>> Could someone help?
>>
>> while (<>)
>>         if (/pattern/)
>>                 ?????

>Set up a count when you find the pattern and just count through the
>three lines:

>$count = 0;
>$test = 0;
>while ( <> ) {
>    $count++;
>    if ($test == ($count + 3)) {

I think you mean:  if ($count == ($test + 3)) {...}

However....  This will print the third line of input if
the pattern has *not* been found (because $count will be
3 and the $test test will succeed).

You'd probably have to manipulate and check definedhood.


David Black
dblack@icarus.shu.edu


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

Date: 21 Apr 1997 13:24:43 -0700
From: mcravit@shell3.ba.best.com (Matthew Cravit)
Subject: Re: How do I make libperl.a a shared lib?
Message-Id: <5jgieb$nba@shell3.ba.best.com>


In article <5jgh88$apn$1@nnrp.cs.ubc.ca>,
Henry Avatar Chan <q8e192@ugrad.cs.ubc.ca> wrote:
>
>How do I make libperl.a a shared lib?

If I recall correctly, one of the questions perl's Configure script asks is
something like "make a shared libperl?". Answer yes to that question.

/MC

-- 
--
Matthew Cravit, N9VWG               | Experience is what allows you to
E-mail: mcravit@best.com (home)     | recognize a mistake the second
        mcravit@taos.com (work)     | time you make it.


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

Date: Tue, 22 Apr 1997 06:47:18 -0600
From: Tom Crosman <wcrosman@tecoinc.com>
Subject: How the !@#$%^&* does this relate to comp.lang.java.advocacy was Who will win?  Borland or Microsoft or Programmers?
Message-Id: <335CB356.6CA7@tecoinc.com>

M A wrote:
> 
> Hi,
>         My company is planning to start a project.  We have a big question
> about our investments.  We don't know if we should use Microsoft
> compiler or Borland.  Some myth we heard over the net.
> 
> 1) 90% of the programmer uses Microsoft Compiler.
> 2) Borland will vanish in 2 years (NASDAQ:BORL)
> 3) Borland has better compiler
> 4) 99% of the College in US have/use Borland Compiler.
> 
> Some one show us the way?
> 
> I myself use Borland Compiler and haven't thought about Microsoft yet!
How about not cross posting to groups that are not related.


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

Date: 22 Apr 1997 12:48:24 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: How to expand a variable in a string?
Message-Id: <5jic2o$1bf@pirate.shu.edu>

Aaron Sherman <ajs@ajs.com> writes:

>David Alan Black wrote:

>> >I have read a string into my variable $str. The string may be something
>> >like this:
>> >           "some text $variable and some text again"

>> It's very easy.  You have no idea how easy it is....
>> Just run your code and watch the magic :-)

>Note the words "read a string". Perhaps this indicates some sort of
>I/O (like, oh, say reading in a string that the user types...)

Yes, that's why I canceled my original article - I realized later
that I had misunderstood the question.  I guess the cancellation
didn't propagate quickly enough to your site.  (Or maybe it
didn't work at all - I never feel quite sure....)

I'm actually secretly pleased that the lack of a '\' in the
original poster's sample string confused me - at least my
Perl syntax instincts are humming along, even if I've forgotten
how to read English.  :-)


David Black
dblack@icarus.shu.edu


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

Date: Tue, 22 Apr 1997 10:08:23 -0400
From: Aaron Sherman <ajs@ajs.com>
To: Tad McClellan <tadmc@flash.net>
Subject: Re: howto post to www-form from Perl?
Message-Id: <335CC657.6F63@ajs.com>

Tad McClellan wrote:
> 
> vparekh@panix.com wrote:
> 
> : I want to post to a form on the web from Perl. For example,
> : I want to send the search string "automobile" to Yahoo's home page(or some
> : other form on the web) and get the results.

> You need info on the HTTP (protocol) and/or the CGI (interface).
> 
> Neither of those are likely to be at perl sites, because they are
> not part of perl...

The correct answer is LWP (libwww-perl) version 5.x is on CPAN
under:

	http://www.perl.com/perl/CPAN/modules/by-module/WWW

With LWP, posting a form is:

	use LWP::UserAgent;
	use HTTP::Request;
	my $ua = LWP::UserAgent->new();
	my $r = HTTP::Request->new('POST',"http://www.foo.com/script");
	my $resp = $ua->request($r);
	print $resp->content;

modulo error-checking and parameters to the POST (which you provide
to $r).

			-AJS

-- 
Aaron Sherman			"We are, all of us, living in the shadow of
Safety Net Solutions		 Manhatten." -The Watchmen
Email: ajs@ajs.com
WWW: http://ajs.com/~ajs/


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

Date: Tue, 22 Apr 1997 10:29:08 -0400
From: Aaron Sherman <ajs@ajs.com>
To: "Jordyn A. Buchanan" <jordyn@bestweb.net>
Subject: Re: Matching
Message-Id: <335CCB34.163C@ajs.com>

Jordyn A. Buchanan wrote:

>       $tmp = '\d\d\t  \d';
>       while(<INFILE>) {
>          if (/$tmp/o) {       # Note the 'o' here to save CPU cycles
>             do something;     # Actually, this does nothing
>          }
>       }

Be very careful with //o, I always get caught by it. For example,
if I decided to take this and turn it into a subroutine, and then
pass $tmp to it, all of a sudden, everything after my first call
to the sub is wrong.... //o is really only useful when you have
a tremendous amount of data.

Also, in the example, you could just put \d\d\t \d in the //.
I also suspect that the requestor would want /\d{2}\s+\d/
in the regex, a "\t " is an odd thing to expect....

			-AJS

-- 
Aaron Sherman			"We are, all of us, living in the shadow of
Safety Net Solutions		 Manhatten." -The Watchmen
Email: ajs@ajs.com
WWW: http://ajs.com/~ajs/


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

Date: Tue, 22 Apr 1997 10:25:16 -0400
From: Aaron Sherman <ajs@ajs.com>
To: "cssm.com" <mcdowell@magicnet.net>
Subject: Re: Name that OS(unix,nt,?) question.
Message-Id: <335CCA4C.795E@ajs.com>

cssm.com wrote:
> 
> How can one tell what Platform a perl script is being run on. I've seen
> PERL scripts that check system files to see if a box is system V or
> BSD, but I also have to deal w/ Windows NT as well.

use Config;
if ($Config{ostype} eq 'Win32') ...

This is from memory, you will want to check out the Config
module for more info. In the Win32 distribution, it's under
the lib directory, on UNIX boxes, it's under the OS-specific
directory in the lib area.

			-AJS

-- 
Aaron Sherman			"We are, all of us, living in the shadow of
Safety Net Solutions		 Manhatten." -The Watchmen
Email: ajs@ajs.com
WWW: http://ajs.com/~ajs/


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

Date: Tue, 22 Apr 1997 13:34:00 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Name that OS(unix,nt,?) question.
Message-Id: <E91KCo.52E@world.std.com>
Keywords: NT, unix, perl, os

mcdowell@magicnet.net (cssm.com) writes:


>How can one tell what Platform a perl script is being run on. I've seen
>PERL scripts that check system files to see if a box is system V or
>BSD, but I also have to deal w/ Windows NT as well.

Use the Config module or the $^O variable.

The Config module is present in all version of perl 5.00 and
later. (Earlier than that and NT isn't an issue.)

use Config;
print "running under $Config{osname}\n";

In 5.002 the $^O variable was added. (Which means that you can't use
it in the very widely distributed build 110 of the
Hip/Activeware/Microsoft port.) It contains the same information as
$Config{osname} but doesn't require the same module loading overhead.
-- 
Andrew Langmead


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

Date: Tue, 22 Apr 1997 15:03:29 +0100
From: b.wilkinson@NOSPAM.pindar.co.uk (Bob Wilkinson)
Subject: Re: Name that OS(unix,nt,?) question.
Message-Id: <b.wilkinson-2204971503290001@ip57-york.pindar.co.uk>

In article <5jhk3e$ru6$1@comet2.magicnet.net>, mcdowell@magicnet.net (cssm.com) 
> writes:
> 
> >
> >How can one tell what Platform a perl script is being run on. I've seen
> >PERL scripts that check system files to see if a box is system V or
> >BSD, but I also have to deal w/ Windows NT as well.
> >
> >Curious..
> >
> >-Patrick.
> >patrick.mcdowell@tivoli.com
> >
> >

Pulled from the top of CGI.pm by Lincoln Stein

# Some systems support the $^O variable.  If not
# available then require() the Config library
unless ($OS) {
    unless ($OS = $^O) {
        require Config;
        $OS = $Config::Config{'osname'};
    }
}

So I think that the answer is that it is in $^O (pp. 137 of the turquoise Camel
supports this supposition). However, it's also found in the Config module

-- 
I have become death, destroyer of the worlds.


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

Date: Tue, 22 Apr 1997 12:51:35 GMT
From: bs@research.att.com (Bjarne Stroustrup)
Subject: Re: Ousterhout and Tcl lost the plot with latest paper
Message-Id: <E91IDz.IL9@research.att.com>


From: Thant Tessman <thant@nospam.acm.org> writes

 > Obligatory Ousterhout slam:  The argument I hate the most from people is "X 
 > is better than Y because more people use X than Y."   This argument is 
 > particularly infuriating when it comes from people like Ousterhout and 
 > Stroustrup and Gates because they are clearly content to perpetuate people's 
 > ignorance of superior alternatives, thus protecting their trump-card argument.  
 > (Not that it's their job to inform people of superior alternatives.)

An Hmmm. I don't know what - if anything - Ousterhout said to deserve
that label, and I find it hard to think of something significant to say
that applies to "Ousterhout and Stroustrup and Gates."

I do not think that I ever said:

	"C++ is better than Y because more people use C++ than Y."

To repeat what I posted last time someone accused me of making
that argument in comp.lang.c++:

	The furthest I go is to claim that unless C++ had at least some
	of the virtues I claim for it, it would have died during the
	early years where there were essentially no C++ marketing and
	alternatives languages with marketing dollars behind them existed.

	Naturally, even that is invariably mistaken for the disreputable
	"5 million morons cannot be wrong" argument :-(

I recommend "The Design and Evolution of C++" (Addison-Wesley) for people
who are interested in what I actually claim for C++.

	- Bjarne

Bjarne Stroustrup, AT&T Research, http://www.research.att.com/~bs/homepage.html



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

Date: Tue, 22 Apr 1997 10:05:05 -0400
From: Michael Iles <michaeli@dra.com>
Subject: Re: Perl as its own metalanguage?
Message-Id: <335CC591.7FD6@dra.com>

Tom Christiansen wrote:
> There is no such thing as a "hash context", and an "array context"
> is just a quaint way of saying "list context".  So there are only
> two contexts, singular and plural.  C shares this.

Can you elaborate on this? In C++, at least, you can't overload based on
return type. I'm having trouble thinking of a construct in C that would
act differently based on a 'singular' or 'plural' context.

Mike.

-- 
Michael Iles, michaeli@dra.com
Ceci n'est pas une .sig


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

Date: Tue, 22 Apr 1997 14:19:08 GMT
From: ranger@onramp.net (Gregory Reddin)
Subject: Perl CGI scripts under Windows NT iis 3.0
Message-Id: <335cc7bc.64914953@news.onramp.net>


Hi all:

I have a problem that's escaped me as to what's happening. I recently
moved our website over to Windows NT from Unix. On Unix all my Perl
scripts worked fine. Now under Windows NT I'm having a problem with a
couple of them. I keep getting "Document Contains No Data" when using
Netscape 3.01. When using MSIE 3.02 I do not see the problem. The
scripts in particular are simple URL selection drop-down boxes. I have
installed Perl 32 from www.hip.com. I feel as though it's installed
correctly since it passes all test and most scripts work fine. 

Can anyone tell me how to get rid of the "Document Contains No Data"
error message? This only happens with Netscape!

Thank you,

Gregory Reddin
greddin@objectspace.com


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

Date: 22 Apr 1997 13:47:20 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: Q: How to sort an array of arrays
Message-Id: <5jifh8$6qf@pirate.shu.edu>

Hello -

"Harry Kas" <harry@bci.se> writes:

>Can somebody tell me if it is possible to use the sort function on an array
>of arrays?

Yes.

>I have an array[0][1] and want to sort on the first array.
>"@array2 = sort @array" is not working. How should I do?

I'm not sure what you mean.  The elements of @array are
array references, so if you really want to sort them, then
what you're doing is correct.  But it's almost impossible
that that's what you want to do.

If you mean that you want to sort on the first element of
each array to which @array contains references, then you
would do something like:

@sorted = sort { $a->[0] <=> $b->[0] } @array;

or cmp instead of <=> for an alphanumeric sort.

If you want to sort the first array in @array, then:

@sorted = sort @{$array[0]};


David Black
dblack@icarus.shu.edu


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

Date: 22 Apr 1997 13:50:27 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Reading this will take seconds!
Message-Id: <5jifn3$j2f@fridge-nf0.shore.net>

Sly@yournamehere.com wrote:

: Thanks for your time.  We at I.S.P.O.T. (The International Society
: for the Preservation Of Trees (URL http://www.local-touch.com/ISPOT/)) feel
: that electronic messages are great for getting the word out while preserving
: our friend the tree.  Anyway, please stop by our home page!

How about the "International Society for the Preservation of Bandwidth?"  :-)

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: Tue, 22 Apr 1997 16:52:15 -0700
From: Hans Suijkerbuijk <Hans.Suijkerbuijk@SD.BE>
Subject: sorting hashes on values
Message-Id: <335D4F2F.754C@SD.BE>

Hi,

specs: I'm using Perl 5.001 on NT 4.0.
My problem:

I get an undefined number of hashes as results of a query. (each hash is
a record) In each hash i have three keys: code, title and a score. I
want to collect the hashes (in a hash or in an array?) and then sort the
collection of hashes according to the (integer) value of the key score
before displaying the collection. How do I do this (i experimented a lot
with sort-stuff, but nothing worked)?

Thanks in advance!

P.S. I have my reasons to solve my sorting-problem NOT in my
SQL-statement.


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

Date: Tue, 22 Apr 1997 14:47:07 +0200
From: "Markus Kaiser" <mak@dfki.uni-sb.de>
Subject: Substitute
Message-Id: <5jibub$8tb@hades.rz.uni-sb.de>

Hi *,

can anyone tell me how to do the following substitution:

original: %Test%
result: content of variable $Test.

s/%(.*)%/$\1/
 isn't working. Any elegant solutions are
welcome 8^)

Markus

---
Markus Kaiser

Malstatter Str. 4 Tel. +49 681 92630 10
D-66117 Saarbruecken Fax. +49 681 92630 15
Germany EMail mak@dfki.uni-sb.de 




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

Date: 22 Apr 1997 13:49:34 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Substitute
Message-Id: <5jifle$j2f@fridge-nf0.shore.net>

Markus Kaiser (mak@dfki.uni-sb.de) wrote:

: original: %Test%
: result: content of variable $Test.

: s/%(.*)%/$\1/

Is this what you were looking for?

perl -e '$val="%Test%"; $val =~ s/\%(.*)\%/$1/g; print $val,"\n";'

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 22 Apr 1997 14:09:53 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: Substitute
Message-Id: <5jigrh$9ko@pirate.shu.edu>

Hello -

"Markus Kaiser" <mak@dfki.uni-sb.de> writes:

>Hi *,

>can anyone tell me how to do the following substitution:

>original: %Test%
>result: content of variable $Test.

>s/%(.*)%/$\1/
> isn't working. Any elegant solutions are
>welcome 8^)

Elegant solutions-are-us  :-)

orig = '%Test%';
$Test = "This is a string\n";

$orig =~ s/%(.*?)%/$$1/g;

The two main modifications here are (1) the use of the
non-greedy quantifier *?, and (2) the $$1 syntax, which
symbolically dereferences (desymbolically references?)
$1.

David Black
dblack@icarus.shu.edu


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

Date: 22 Apr 1997 14:45:54 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: Substitute
Message-Id: <5jiiv2$k7u$1@news.netusa.net>


David Alan Black <dblack@icarus.shu.edu> wrote:
>"Markus Kaiser" <mak@dfki.uni-sb.de> writes:
>>Hi *,

" *" doesn't match my name. Did you leave a '.' out?

>>can anyone tell me how to do the following substitution:
>>original: %Test%
>>result: content of variable $Test.

Personally I would substitute a $ in and then do an eval.

>> isn't working. Any elegant solutions are welcome 8^)
>Elegant solutions-are-us  :-)
>
>$orig =~ s/%(.*?)%/$$1/g;

".*?" is not elegant in my book. "[^%]*" is much better.
For multibyte boundry conditions, back references and a few other
nasty cases, the non-greedy modifier is better, but for a case like
this the proper greedy condition will be faster and more portable.

Elijah
------
portable includes into the minds of non-perlre gurus who might maintain it


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

Date: Tue, 22 Apr 1997 09:25:37 -0600
From: John Adamson <j-adamson@tamu.edu>
Subject: Variable interpolation (substitution)
Message-Id: <335CD871.70B2@tamu.edu>

Could use some advice on variable interpolation (as Wall uses 
the term) in a conditional statement.

Consider this simple statement:
  for ($i=1;$i<=10;$i++){print "$i\n";}

Is it possible to use:
  for ($arg1;$arg2;$arg3){print "$i\n";}
where $arg1-3 are defined elsewhere?

Seems like it oughta be simple but haven't been able to get 
it to work.  Thoughts will be appreciated and - if this is an 
incredibly dumb question - well, heck, I'm sorry.  TIA ..
ja


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

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 343
*************************************

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