[6989] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 614 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 16 08:07:26 1997

Date: Mon, 16 Jun 97 05:00:38 -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           Mon, 16 Jun 1997     Volume: 8 Number: 614

Today's topics:
     C function prototyper... <ibkim@lge.co.kr>
     Re: ENVIRONMENTAL VARIABLES...... how do you access the <perlprogrammer@hotmail.com>
     exec and system calls <jan@virtualf.com>
     Re: Fastest way to insert an element into a list (Tad McClellan)
     Re: file test operators <jbokma@caiw.nl>
     Re: How do i convert a (float) to (integer) ? (Tung-chiang Yang)
     Re: Is this decent? <friedman@uci.edu>
     libwww (IFHRK)
     Re: libwww <chchee@iti.gov.sg>
     Re: Opening Files <eike.grote@theo.phy.uni-bayreuth.de>
     Re: Opening Files (Anthony Ciarochi)
     Perl Compiler Trubles <maxi@chim1.unifi.it>
     Re: perl joke of the day ? (Steffen Kluge)
     Re: Premature end of script header <perlprogrammer@hotmail.com>
     Re: Premature end of script header <perlprogrammer@hotmail.com>
     Re: Problems with dynamic linking Perl 5 on Solaris 2.5 (Casper H.S. Dik - Network Security Engineer)
     Re: Reading in records from file <merlyn@stonehenge.com>
     RegExp Question (something stupid, I'm sure :) (J. Paul Reed)
     Re: Return Value of push, Perl 4 vs. 5 (Lack Mr G M)
     run-time eval efficiency question <web@calarts.edu>
     socket under solaris (Jan ' Kozo ' Vajda)
     Re: Sorting Associative Array? (Urgent) (Anthony Ciarochi)
     Re: Sorting within an object (Raymond Chen)
     Re: SQL formatting with PERL <sfairey@metrica.co.uk>
     teeing filehandles in perl <mwhite@csu.edu.au>
     Re: Tricky Syntax Question (M.J.T. Guy)
     Re: What is wrong with this? <shimpei@socrates.caltech.edu>
     Re: Writing a DBD driver: How? (John D Groenveld)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 16 Jun 1997 15:22:50 +0900
From: "Ikbae Kim" <ibkim@lge.co.kr>
Subject: C function prototyper...
Message-Id: <5o2lu9$7nk$1@michelle.lge.co.kr>

I want to know how can I generate c function prototypes from the source
code. For example;

/*
* file.c
*/

void
foo(int a)
{
 ....
}

c>proto file.c
void foo(int) ;

Is this possible?

Thanks in advance.
Good day.
                         
--
------------------------------------------
LG Electronics Inc. Seoul, Korea
Email: ibkim@lge.co.kr 




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

Date: Thu, 12 Jun 1997 20:05:58 -0700
From: perl guy <perlprogrammer@hotmail.com>
Subject: Re: ENVIRONMENTAL VARIABLES...... how do you access them in your program
Message-Id: <33A0B916.13CF@hotmail.com>

rthomas wrote:
> 
> I'm not sure how to pull the current environmental variables into my perl
> program. I tried the following:
> 
> $user=%ENV(REMOTE_USER);
> $host=%ENV(REMOTE_HOST);
> 
> also tried,
> $user=$ENV(REMOTE_USER);
> $host=$ENV(REMOTE_HOST);
> 
> no good either way.  The perl books don't make this very clear for a newbie
> but it seems as though the current environment is stored in an associative
> array %ENV and that you must associate a key (which is the name of the variable.
> ie %ENV(key).
> 
> But if you don't know what the names of the variables ie(keys) are how can
> you access the correct elements in the array.  I just took an educated quess
> on REMOTE_USER, REMOTE_HOST.
> 
> Any ideas?
> 
> Thank you for taking the time to help me.
> 
> Best,
> R. Thomas

I don't know what you're trying to do, but..
try...

$user = $ENV{'REMOTE_HOST'};

etc...


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

Date: 13 Jun 1997 11:53:16 GMT
From: "Yanco" <jan@virtualf.com>
Subject: exec and system calls
Message-Id: <01bc7831$a85d7900$166083c1@london22>
Keywords: Perl exec system calls

I'm having problems with my headers on IIS

I want to set a cookie, then go to a location.
Unfortunately, I can either set the cookie, or, go to the location, and
this method:
foreach $_ (@_) {
		if (/=/) {	
			print "Content-type: text/html\n";
			print "Set-Cookie: $_;\n";
		}else {
			print "Location: $_";
		}	
		print "\n";
}

doesn't work.  So resorting to an alternative, I am using this method: 

foreach $_ (@_) {
		if (/=/) {	
			print "Content-type: text/html\n";
			print "Set-Cookie: $_;\n";
			print "\n";
	
		} elsif (/cgi/) {
			#print "Content-type: text/html\n\n";
			exec $_;
			
		}elsif (/htm/) {
			open(READ, $_);
			print "Content-type: text/html\n\n";
	
			while (<READ>) {
				print;
			}
			close(READ);
		}
}

assume the parameters passed are in the order: name=value, then a cgi OR a
html page, and that there is (for now) only 1 name=value pair.

Now, with an html file, everything is cooking with gas - the cookie gets
set, and we end up at the desired page - , but when it comes to executing a
script, my browser doesn't want anything to do with it.

I tried with system $_ , and at the command line, cool, it works, but again
the browser says, NO.

Can anyone out there help me PLEEEEEEEEASE

P.S.	This is my first message posted to a newsgroup, so I'm not sure if
I've included too much, not enough, or ambiguous information, I'm not even
sure if a P.S. is frowned upon in such circles, so go easy on me, I'm
having a torrid time of things as late.








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

Date: Thu, 12 Jun 1997 19:54:05 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Fastest way to insert an element into a list
Message-Id: <dn5qn5.hd1.ln@localhost>

David Wuertele (dave@cave.gctech.com) wrote:
: I checked the man and the faq, but found no recommended way to insert an
: element into the middle of a big list:

---------------------
#! /usr/bin/perl -w

@ra = qw( zero one two three four six seven eight);

splice(@ra, 5, 0, "five");

print "@ra\n";
---------------------


[ snip pseudo code ]

: I am interested in both efficient-in-time and efficient-in-space methods.
                          ^^^^^^^^^^^^^^^^^

I submit that splice() is efficient in Programmer's development time ;-)

The Benchmark module is the way to evaluate efficiency in execution time.


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 16 Jun 1997 08:55:56 GMT
From: "John Bokma" <jbokma@caiw.nl>
Subject: Re: file test operators
Message-Id: <01bc7a33$43bcd1e0$c80ab2c2@tschai>



William Wueppelmann <williamw@host.igs.net> wrote in article
<33A17962.10D3@host.igs.net>...
> I was hoping someone could answer a question:
> 
> I'm trying to get a list of subdirectories in $path by using
> open(SRC,"$path");

opendir?


> @list = grep(-d, readdir(SRC));

John


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

Need a Freelance Software Developer (MSc)? (CGI, Perl, Java, C, C++)

http://www.caiw.nl/~jbokma [Java demo's, Curriculum Vitae and
more...]

email: jbokma@caiw.nl  phone: +31 10 4291827



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

Date: Fri, 13 Jun 1997 05:39:12 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: How do i convert a (float) to (integer) ?
Message-Id: <tcyangEBp91C.557@netcom.com>

$integer = int($random);

========================
Jonas Thvrnvall typed when the mommy tyrannosaurus found him:
: Hello!

: A silly question maybe, but however how do i convert $random, it's a
: floating point to an integer?

--
========= Try the low-crossposting robomoderated 'alt.culture.taiwan' ===

soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
   http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml


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

Date: 16 Jun 1997 06:08:16 GMT
From: "Eric D. Friedman" <friedman@uci.edu>
Subject: Re: Is this decent?
Message-Id: <5o2l8g$go5@news.service.uci.edu>

[mailed, posted]

In article <33A4C082.3DE@fit.qut.edu.au>,
Dan Smith  <daniel@fit.qut.edu.au> wrote:
<Hi all,
<
<I'm trying to assign a multi-field record to a hash, where the data for
<the hash is contained in a nicely-formatted scalar.  I was wondering if
<this is a good way to do it:
<
<my $blah = '{ "foo" => {"man" => "choo"}, "bar" => "none"}';
<my %blah2 = %{ eval $blah};
<print $blah2{'foo'}{'man'};
<
<Does anyone know a different (read "better") way to achieve it?
      ^^^^^^

The authors of the fine man page on perl data structures do!

man perldsc reveals-->

     " There are separate sections on each of the following:

     o arrays of arrays

     o hashes of arrays

     o arrays of hashes

     o hashes of hashes

     o more elaborate constructs"

Looks like you want hashes of hashes.

-- 
Eric D. Friedman
friedman@uci.edu


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

Date: 13 Jun 1997 14:31:43 GMT
From: cpeterma@emerald.tufts.edu (IFHRK)
Subject: libwww
Message-Id: <5nrlkf$da6$1@d2.tufts.edu>

Does anyone know where on the CPAN site I find all of the modules I need
to for libwww.  The release notes for Tk400.200 specify that I need
additional sets of modules.  

TIA

Charles Peterman



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

Date: Mon, 16 Jun 1997 13:57:00 +0800
From: Benny Chee <chchee@iti.gov.sg>
Subject: Re: libwww
Message-Id: <Pine.SOL.3.91.970616135631.14842A-100000@hercules.iti.gov.sg>

On 13 Jun 1997, IFHRK wrote:

> Does anyone know where on the CPAN site I find all of the modules I need
> to for libwww.  The release notes for Tk400.200 specify that I need
> additional sets of modules.  
> 
> TIA
> 
> Charles Peterman


Install prtl5.004, it has all the updated modules.

Benny Chee :)	    |	"I used to have a life, 
chchee@iti.gov.sg   |	  but now I have a modem."



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

Date: Mon, 16 Jun 1997 09:27:45 +0200
From: Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>
Subject: Re: Opening Files
Message-Id: <33A4EAF1.794B@theo.phy.uni-bayreuth.de>

Hi,

Arthur Merar wrote:
> 
> If I open a file for output, OPEN(FILE,">filename"), and the file
> already exists, will Perl overwrite the file that is there?

Why don't you just try it out ?


Bye, Eike
-- 
======================================================================
 Eike Grote, Theoretical Physics IV, University of Bayreuth, Germany
----------------------------------------------------------------------
 e-mail -> eike.grote@theo.phy.uni-bayreuth.de
 WWW    -> http://www.phy.uni-bayreuth.de/theo/tp4/members/grote.html 
           http://www.phy.uni-bayreuth.de/~btpa25/
======================================================================


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

Date: 16 Jun 1997 08:41:38 GMT
From: ciarochi@pe.net (Anthony Ciarochi)
Subject: Re: Opening Files
Message-Id: <5o2u82$1n6$2@nnrp1.snfc21.pacbell.net>

yes.

 - AFC


In article <33A4EAF1.794B@theo.phy.uni-bayreuth.de>, 
eike.grote@theo.phy.uni-bayreuth.de says...
>
>Hi,
>
>Arthur Merar wrote:
>> 
>> If I open a file for output, OPEN(FILE,">filename"), and the file
>> already exists, will Perl overwrite the file that is there?
>
>Why don't you just try it out ?
>
>
>Bye, Eike
>-- 
>======================================================================
> Eike Grote, Theoretical Physics IV, University of Bayreuth, Germany
>----------------------------------------------------------------------
> e-mail -> eike.grote@theo.phy.uni-bayreuth.de
> WWW    -> http://www.phy.uni-bayreuth.de/theo/tp4/members/grote.html 
>           http://www.phy.uni-bayreuth.de/~btpa25/
>======================================================================



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

Date: Mon, 16 Jun 1997 10:47:13 +0100
From: Massimo Fontanelli <maxi@chim1.unifi.it>
Subject: Perl Compiler Trubles
Message-Id: <33A50BA1.6E2@chim1.unifi.it>

I have a Perl Compiler Toolkit problem, so I posted a message, but many
informations
about were missing, let's try again?

My environment is: Dec Aplha running DEC Unix V3.2, Perl Version 5.004 +
Perl Compiler Toolkit,
both was compiled without problems using DEC OSF/1 C compiler

The origin of the truble was that I wish to compile the following code:

    #!/usr/bin/perl
    $the_dir="/tmp";
    opendir(CDIR, $the_dir);
    @files = grep(/./,readdir(CDIR));
    closedir(CDIR);
    print "\n@files\n";

The message of the toolkit is:
>test syntax OK
>Can't locate object method "first" via package "B::OP" at /usr/local/lib/perl5/s
>ite_perl/B.pm line 95.

So I tried to use POSIX, adjusting the code as following:

    #!/usr/bin/perl
    use POSIX;
    $dirtest='/tmp';
    $dir = POSIX::opendir( $dirtest );
    @files = grep(/./,(POSIX::readdir( $dir )));
    POSIX::closedir( $dir );
    print "\n@files\n";

The new error message is:
posix_test syntax OK
cc -std -D_INTRINSICS -I/usr/local/include -D__LANGUAGE_C__
-I/usr/local/lib/per
l5/alpha-dec_osf/5.004/CORE -O2 -o posix.exe src.c  -L/usr/local/lib
-L/usr/loca
l/lib/perl5/alpha-dec_osf/5.004/CORE -lperl -lgdbm -ldbm -lm
/usr/lib/cmplrs/cc/cfe: Error: src.c, line 300: Select field within a
non-struct
 data pointer
        ((XPVCV*)(0)->sv_any )->xcv_gv  = 0 ;
        ------------^

What do You think about? The only I cannot compile are the dir handling
functions,
the other code goes fine...

Thank You in advance,

\___Maxi


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

Date: 16 Jun 1997 16:08:53 +1000
From: kluge@fujitsu.com.au (Steffen Kluge)
Subject: Re: perl joke of the day ?
Message-Id: <5o2l9l$e7c$1@syd0128.fujitsu.com.au>

In article <339F646C.228E@MCI.com>,
Michael J Cameron  <Michael.Cameron@MCI.com> wrote:
>Steffen Beyer wrote:
>> 
>
>Or maybe the guy just needs some help.
>
>Why poke fun at those who are less experienced than yourself?

Maybe those guys should go back and read the docs themselves?
E.g, from the Camel Book's preface:

  Any level of language proficiency is acceptable in Perl
  culture. We won't send the language police after you. A
  perl script is "correct" if it gets the job done before
  your boss fires you.

Cheers
Steffen.

-- 
Steffen Kluge <kluge@fujitsu.com.au>
Fujitsu Australia Ltd
Keywords: photography, Mozart, UNIX, Islay Malt
--


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

Date: Mon, 16 Jun 1997 02:37:54 -0700
From: perl guy <perlprogrammer@hotmail.com>
Subject: Re: Premature end of script header
Message-Id: <33A50971.2071@hotmail.com>

perl guy wrote:
> 
> Bohannon wrote:
> >
> > I have the same problem, Im wondering if it is a file conversion problem
> > going from PC's to UNIX using FTP in binary mode. I would appreciate any
> > info on this!
> >
> > -ivan
> 
> Your problem.. Are you having it say that on your borwser window, or are
> you meaning in the error log?.. that would be helpful to know..  I
> assume the error log?.

ack!... wait.. sorry.. i just re-read your posting.. I seriosly missed
something!!.. Do I understand you right, in you saying you *DID* FTP in
binary mode???????,,


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

Date: Mon, 16 Jun 1997 02:18:16 -0700
From: perl guy <perlprogrammer@hotmail.com>
Subject: Re: Premature end of script header
Message-Id: <33A504D7.5C0@hotmail.com>

Bohannon wrote:
> 
> I have the same problem, Im wondering if it is a file conversion problem
> going from PC's to UNIX using FTP in binary mode. I would appreciate any
> info on this!
> 
> -ivan

Your problem.. Are you having it say that on your borwser window, or are
you meaning in the error log?.. that would be helpful to know..  I
assume the error log?.


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

Date: 13 Jun 1997 09:16:17 GMT
From: Casper.Dik@Holland.Sun.COM (Casper H.S. Dik - Network Security Engineer)
Subject: Re: Problems with dynamic linking Perl 5 on Solaris 2.5.1
Message-Id: <casper.866193633@uk-usenet.uk.sun.com>

dutka@rantanplan.dr.gdf.fr (DUTKA-MALEN Ivan) writes:

>lib/anydbm........Can't load '../lib/auto/Fcntl/Fcntl.so' for module Fcntl:
>      ld.so.1: ./perl: fatal: relocation error: symbol not found: 
>      Perl_markstack_ptr: referenced in ../lib/auto/Fcntl/Fcntl.so at 
>      ../lib/DynaLoader.pm line 155.


Weird; this looks like perl itself is compiled w/ 5.003 binary compatibility
but the dynamic extensions are compiled w/o that compatibility.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.


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

Date: 13 Jun 1997 09:04:05 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Dan Smith <daniel@fit.qut.edu.au>
Subject: Re: Reading in records from file
Message-Id: <8cwwnypk0a.fsf@gadget.cscaper.com>

>>>>> "Dan" == Dan Smith <daniel@fit.qut.edu.au> writes:

Dan> Greetings to all perl'ers and CGI-Joes out there ...
Dan> In the perldsc man page, the author shows how to declare the following
Dan> (relatively) complex data structure ...

[data deleted]

Dan> ... and then mentions that ...

>> perl is happy to parse complex datastructures if declared as data, so
>> sometimes it's easiest to do that

Dan> So which of you out there could come up with the simplest way of doing
Dan> this (efficiency- and/or code length-wise), using the above as an
Dan> example?

Uh, you mean to have Perl parse it?  Just stick that data in that
format into your program (zero lines of code :-), or stick it into
a separate file and just "do" it:

	do "separate-data-file.pl";

If you already have a data structure that you want a future Perl
program to parse, get the Data::Dumper module from the CPAN.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 444 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 14 Jun 1997 09:04:09 GMT
From: preed@psd.k12.co.us (J. Paul Reed)
Subject: RegExp Question (something stupid, I'm sure :)
Message-Id: <5ntmq9$cg1$1@mercury.psd.k12.co.us>

Hey all!

How's it going?

When I run the following, I don't get any output? Can anyone tell me why?

Thanks in advance!
Later,
Paul

#!/usr/bin/perl

$blah = "EP = 23412;";

if ($blah =~ /^EP = [\w*\d*]\;$/) {
print "YEAH!\n";
}


   -------------------------------------------------------------------
   J. Paul Reed                 preed@psd.k12.co.us || paul@619pro.com
   Such a noble creature; a quality we sometimes lack...
   				--Borg Queen; Star Trek: First Contact
   Geek Code and various other frivolities at www.psd.k12.co.us/~preed


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

Date: Mon, 16 Jun 1997 12:16:18 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Return Value of push, Perl 4 vs. 5
Message-Id: <1997Jun16.121618@ukwit01>

In article <5o0tlf$g3r@lyra.csx.cam.ac.uk>, mjtg@cus.cam.ac.uk (M.J.T. Guy) writes:
|> Mark Stallard  <mrs@cae091.ed.ray.com> wrote:
|> >I've been using Perl 5.003 whenever I can, but occasionally forced
|> >to revert to Perl 4.035.  Perl 4 is still great, but I usually find
|> >myself giving up some nice features of Perl 5.
|> >
|> >One exception is push's return value.  I was playing with one-liners
|> >yesterday, and Perl 4 did what I wanted, but not Perl 5.
|> >
|> >In Perl 4, push returned the first value of the list it pushed; a
|> >null value there was nothing to push.  Perl 5, however, returns the
|> >scalar() value of @inc regardless of whether any values were pushed.
|> >As a result, my Perl 5 test printed output for every input line fol-
|> >lowing the first successful push.
|> >
|> >The 2nd edition of the Camel Book doesn't appear to mention this
|> >behavior, nor could I find it in the FAQ's.  Did I discover a
|> >Perl 5 bug, an unintended feature of Perl 4, or just another
|> >4-to-5 trap?
|> 
|> What behaviour were you expecting?   Neither the perl4 nor the perl5
|> man page say anything about the result value from push, so if you
|> are using it, you are in a serious state of sin.

   However, perlfunc for perl5 states:

 "Returns the new number of elements in the array"

   The Camel Book (Edtn 2, p201) states:

 "The function returns this new length".

both of which look like a well documented feature to me.


   So, I suggest a code re-write:

|>   while ( $line = <> ) {
|>      if ( push( @inc, $line =~ /INC\W+(\d{5})/ig )) {
|>         print join( " ", @inc ), "\n" ;
|>      }
|>   }

should become:

   while ( $line = <> ) {
      if ($line =~ /INC\W+(\d{5})/ig ) {
         push (@inc, $1);
         print join( " ", @inc ), "\n" ;
      }
   }


-- 
----------- Gordon Lack ----------------- gml4410@ggr.co.uk  ------------
The contents of this message *may* reflect my personal opinion.  They are
*not* intended to reflect those of my employer, or anyone else.


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

Date: Thu, 12 Jun 1997 14:45:51 -0700
From: Jason Lamport <web@calarts.edu>
Subject: run-time eval efficiency question
Message-Id: <33A06E0F.452F@calarts.edu>

Does anyone know just how intelligent perl is about not recompiling code
passed to an eval function when that code doesn't need to be
recompiled?  e.g. I know that in

foreach (1..10) { eval 'print "Hello!";'; }

the 'print "Hello!";' gets compiled at runtime; but does it get compiled
once at runtime, or does it get compiled ten times?  What about:

foreach (1..10) { eval $some_code; }

Since $some_code is never modified in the loop, Perl _could_ compile it
just once -- but does it?  What about:

$f1 = sub { eval $some_code; }
foreach (1..10) { &$f1; }

or

$f1 = eval "return sub { $some_code }";
foreach (1..10) { &$f1; }

?  

Let me explain why I'm asking:  I'm currently working on a script to
search a database file according to various user-defined criteria.
(Needless to say, these criteria are not known until runtime.) The
script reads data from the database one record at a time, compares the
data in that record to the search criteria, does some appropriate things
depending on whether the record matched or not, and then goes on to the
next record.

The problematic part of all this is the comparison section.  If coded in
the normal, straight-forward way, this section is going to be a horrible
mess of nested if/elsif statements.  What's worse is that most of these
tests are tests not on the record data, but on the search criteria
itself:  IF the user is searching by date then... ELSIF the user is
searching by keyword then... etc.  In other words, I'm going to have to
do thousands of tests on boolean expressions that will always evaluate
the same, every single time.  It seems a terrible waste of time to keep
testing the same values over and over, but there doesn't seem to be any
way around it.

But this is Perl, so there's no requirement that I do anything in a
"normal, straight-forward way."  It occured to me that at the beginning
of my search routine, I could use eval to build a custom comparison
function, based on the user's search criteria. Since this function will
be customized for the particular search being conducted, it could be
made very, very efficient.  If, that is, it only gets compiled once. 
If, on the other hand, Perl has to recompile it each time through the
loop, then the normal, straight-forward approach is still going to be
much, much faster, even with all those extra if/elsif statements.

Anyone care to enlighten me on this subject? (Oh, and in case it makes a
difference, I'm using Perl 5.003 under IRIX release 5.3.)

-jason


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

Date: 13 Jun 1997 09:29:43 GMT
From: jvajda@ns.somi.sk (Jan ' Kozo ' Vajda)
Subject: socket under solaris
Message-Id: <5nr3u8$orc@gringo.somi.sk>
Keywords: Socket.pm, solaris

how use Socket.pm under solaris 2.5.x ???

i tried it, but I resolved error:
socket: Protocol not supported

thx .. 

	                                  K O Z O    
			     ====================================
                        	 e-mail: Jan.Vajda@somi.sk
                       	       URL: http://www.sanet.sk/~vajda




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

Date: 16 Jun 1997 08:36:49 GMT
From: ciarochi@pe.net (Anthony Ciarochi)
Subject: Re: Sorting Associative Array? (Urgent)
Message-Id: <5o2tv1$1n6$1@nnrp1.snfc21.pacbell.net>

In article <33A4D734.1C3A@global.com.my>, ckng@global.com.my says...
>
>Does anyone know how to sort an associative array by the key value?
>Example data is %array=("name","id",.....) and I need to sort by the key
>name. Anyone?
>I've look into http://www.perl.com/perl/everything_to_know/sort.html,
>but couldn't find anything.
>Thanks in advance.
>

How about - 

@list = sort(keys(%array));

 - or better yet if it's a big hash -

foreach $key (sort(keys(%array)))
{
	# do something spectacular
}



If you need to sort by the value contained IN the hash try this:

foreach $key (sort { $array{$a} <=> $array{$b} } keys %array))
{
	# do something	
}

 - or - 

foreach $key (sort { $array{$a} cmp $array{$b} } keys %array))
{
	# for strings
}

Note that switching $array{$a} and $array{$b} reverses the sort.

Also Note that you can save yourself a lot of time and stress by buying the 
(camel) book!



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

Date: Fri, 13 Jun 1997 01:48:05 GMT
From: raymondc@microsoft.com.--- (Raymond Chen)
Subject: Re: Sorting within an object
Message-Id: <33a0a565.30032238@157.55.96.156>

# To sort within an object you need to use a closure that knows
# what object it is sorting.

package foo;

sub new {
  bless { weight => { bob => 150, mary => 120 } };
}

sub weightorder {
  my $self = shift;
  sort
        { $self->{weight}{$a} cmp $self->{weight}{$b} }
        keys %{$self->{weight}};
}

package main;

$x = new foo;
foreach ($x->weightorder) {
  print "$_ weighs $x->{weight}{$_}\n";
}

--
(My return address is intentionally invalid; delete ".---" to get my real address.
My responses are not to be considered official technical support or advice.)


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

Date: Fri, 13 Jun 1997 11:21:46 +0100
From: Simon Fairey <sfairey@metrica.co.uk>
To: naxos@rocketmail.com
Subject: Re: SQL formatting with PERL
Message-Id: <33A11F3A.3F54@metrica.co.uk>

chris smith wrote:
> 
> Howdy,
> I need to format a whole flog of PL/SQL programs so that all SQL
> statements (SELECT, FROM, WHERE, LIKE, etc...) are capitalized, while
> the remainder of the statements (field names, table names, etc) remain
> lowercase.  Needless to say, the formatting for these programs is
> sketchy at best.  I also need to make sure all indenting is properly set
> up (aka in IF, THEN, WHILE  or IF, ELSIF, ELSE statements, indenting at
> each nest of a looping statement, then backing out of the indent when it
> is completed.).  Any ideas?  I was thinking of first making an arry of
> all the reserved words, and then running through the file to
> transliterate all these to uppercase, and I have a high-level idea how
> to do this stuff, but some guidance would be much appreciated.
> 
> Please post and email me back, as I can't always check newsgroups.
> 
> Thanks
> 
> Chris Smith
> naxos@rocketmail.com

Try something like this for upper-caseing the words:

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

#!/bin/perl

# Open the supplied file or die trying.
open( SQL_FILE, shift ) or die "Unable to open file: $!.";

# Set up array of reserved words.
@reserved_words = ( 'if', 'then', 'else', 'endif' );

# Undefine the input record seperator and slurp the whole file
# into a variable ( assuming you don't have humungus files!! )
undef $/;
$file = <SQL_FILE>;

# Do a case insensitve search ( allow for any mixed case words ) on
# a word boundary for any reserved words then convert them to upper
# case globally throughtout $file.
for( @reserved_words ) { $file =~ s/\b$_\b/uc($_)/gei; }

# Reset the input record seperator.
$/ = "\n";

print "\nYour file is now:\n$file\n";

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

Regarding the indentation I would be tempted to go through the file and
remove all spaces/tabs from the start of each line and then going
through line by line indenting as required which shouldn't be too
difficult if you have a completely indent free file to start with.

Hope this helps to get you started, if you get really stuck gimme a
shout.

Simon


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

Date: Mon, 16 Jun 1997 17:28:53 +1000
From: Matthew White <mwhite@csu.edu.au>
Subject: teeing filehandles in perl
Message-Id: <33A4EB35.16D72B1@csu.edu.au>

How do I tee a filehandle in perl?

Or more explicitly, How can I select a FileHandle to output to 2 files
similtaneously?

For example, if I run a script that produces a report and, on exception
spits the relevant part of the report to a an error log AS WEll as to
the REPORT. This may happen a number of times.

Eg:

open(ERROR,">errorfile");

for $hasref (sort keys %hash) {
	if ($hashref->{error}) { tee STDOUT to ERROR } # how?
	print "stuff: $hashref->{stuff}\n"; #if error send to both STDOUT +
ERROR
	untee STDOUT # how?
}

Please don't suggest better ways of solving this example.

Matthew


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

Date: 13 Jun 1997 09:39:51 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Tricky Syntax Question
Message-Id: <5nr4h8$h78@lyra.csx.cam.ac.uk>

Tom Phoenix  <rootbeer@teleport.com> wrote:
>On 6 Jun 1997, Helmut Jarausch wrote:
>
>> my C++ background let my try the following construct which Perl (5.004)
>> didn't like.
>> 
>> push ( /\! / ? @Rest : @Selected ),$_;
>> 
>> it says:  Type of arg 1 to push must be array
>> 
>> Now the question is - what is the type of a conditional expression
>> if both alternatives are arrays?
>
>In this case, they're lists instead of arrays. (The variable, which is an
>array, is expanded to a list in that expression.)

Several other responders have also said effectively this, but it isn't true.
You can have a conditional of arrays, and you can assign to it, so the
result of such a conditional must be an array lvalue.   For example,

         ( $bool ? @a : @b ) = @c;

produces the answers you might expect.

So I suspect that the problem is actually with the prototyping of push,
(or indeed with protyping in general), and is a bug.

And why does the error message

Type of arg 1 to push must be array (not null operation) at - line 5, near "23)
"

refer to a conditional as a "null operation"?   Looks like another bug.


Mike Guy


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

Date: 13 Jun 1997 08:05:22 GMT
From: Shimpei Yamashita <shimpei@socrates.caltech.edu>
Subject: Re: What is wrong with this?
Message-Id: <5nqv02$1c3@gap.cco.caltech.edu>

Tom Phoenix  <rootbeer@teleport.com> writes:
>    $file = '/mnt/web/guide/mav/nc/dvdepot/emails.txt';
>    open FILE, ">> $file" or
                ^^^^^^^^^^
>	die "Can't open '$file' for append: $!";

Wow. I did not know about this leading/trailing whitespace stripping
business until I saw this post and RTFManpage'ed. Just out of curiosity,
what is the rationale behind this design decision (aside from "who needs
leading whitespaces in files anyway?")? Is it just for readability?

-- 
Shimpei Yamashita                  <http://socrates.caltech.edu/%7Eshimpei/>



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

Date: 16 Jun 1997 01:10:43 -0400
From: groenvel@cse.psu.edu (John D Groenveld)
Subject: Re: Writing a DBD driver: How?
Message-Id: <5o2hsj$14g$1@tholian.cse.psu.edu>

Join the DBI/DBD developers mail list via http://www.fugue.com/dbi/
John
groenvel@cse.psu.edu


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

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

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