[13168] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 578 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 18 17:12:26 1999

Date: Wed, 18 Aug 1999 14:10:14 -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           Wed, 18 Aug 1999     Volume: 9 Number: 578

Today's topics:
        problems compiling perl5.005_03 on Solaris 2.4 dhenry@info.usaid.gov
    Re: pushing an anonymous hash slice <uri@sysarch.com>
    Re: pushing an anonymous hash slice (Greg Bacon)
    Re: pushing an anonymous hash slice <uri@sysarch.com>
    Re: someone pleae help <makkulka@cisco.com>
        stupid socket question <rajan@nlm.nih.gov>
    Re: stupid socket question <uri@sysarch.com>
        which is better?(assignment(typeglob v ref)) <davidrubin@lucent.com>
    Re: While we are on the subject of tainting.... (Alan Curry)
        Win32::OLE + Word/Excel <andrewf@beausys.freeserve.co.uk>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Wed, 18 Aug 1999 19:40:50 GMT
From: dhenry@info.usaid.gov
Subject: problems compiling perl5.005_03 on Solaris 2.4
Message-Id: <7pf27v$eq8$1@nnrp1.deja.com>

I am getting errors on the comp/redef test when running 'make test', and
am getting prototype mismatches as well:

Solaris 2.4
Perl 5.005_03
gcc 2.6.0
gmake 3.71

==================
 ... in the t directory

poseidon# ./perl -I../lib harness
base/cond...........ok
base/if.............ok
base/lex............ok
base/pat............ok
base/rs.............ok, 4/14 subtests skipped
base/term...........ok
comp/cmdopt.........ok
comp/colon..........ok
comp/cpp............ok
comp/decl...........ok
comp/multiline......ok
comp/package........ok
comp/proto..........Prototype mismatch: sub X::foo4 ($) vs ($) at
comp/proto.t line 413.
ok
comp/redef..........dubious
        Test returned status 0 (wstat 139, 0x8b)
        test program seems to have generated a core
comp/require........ok
comp/script.........ok
comp/term...........ok
comp/use............ok
cmd/elsif...........ok
cmd/for.............ok
cmd/mod.............ok
cmd/subval..........ok
cmd/switch..........ok
cmd/while...........ok
io/argv.............ok
io/dup..............ok
io/fs...............ok
io/inplace..........ok
 .
 .
 .
lib/opcode..........Prototype mismatch: sub Opcode::opset_to_hex ($) vs
($) at ../lib/Opcode.pm line
 40.
Prototype mismatch: sub Opcode::opdump (;$) vs (;$) at ../lib/Opcode.pm
line 50.
ok
lib/open2...........ok
lib/open3...........ok
lib/ops.............Prototype mismatch: sub Opcode::opset_to_hex ($) vs
($) at ../lib/Opcode.pm line
 40.
Prototype mismatch: sub Opcode::opdump (;$) vs (;$) at ../lib/Opcode.pm
line 50.
ok
lib/parsewords......ok
lib/ph..............ok
lib/posix...........ok
lib/safe1...........Prototype mismatch: sub Opcode::opset_to_hex ($) vs
($) at ../lib/Opcode.pm line
 40.
Prototype mismatch: sub Opcode::opdump (;$) vs (;$) at ../lib/Opcode.pm
line 50.
ok
lib/safe2...........Prototype mismatch: sub Opcode::opset_to_hex ($) vs
($) at ../lib/Opcode.pm line
 40.
Prototype mismatch: sub Opcode::opdump (;$) vs (;$) at ../lib/Opcode.pm
line 50.
ok
==================

I've found postings (back in 1997!) that mention the same problems, but
no replies to them.

Any ideas?


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 18 Aug 1999 15:20:58 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: pushing an anonymous hash slice
Message-Id: <x7vhacyjxh.fsf@home.sysarch.com>

>>>>> "GB" == Greg Bacon <gbacon@itsc.uah.edu> writes:

  GB> In article <x77lmtyp80.fsf@home.sysarch.com>,
  GB> Uri Guttman <uri@sysarch.com> writes:

  GB> : push @results, { alternate( [ qw( rank file title group ) ],
  GB> : 			    [ (split /\t/ )[0,1,2,5] ] ) } ;

  GB> sub interleave {
  GB> my($a1,$a2) = @_;
  GB> my @result;
    
  GB> while (@$a1 || @$a2) {
  GB> push @result, shift @$a1 if @$a1;
  GB> push @result, shift @$a2 if @$a2;
  GB> }

  GB> @result;
  GB> }

well i wasn't saying you couldn't write a sub to do it. but since you
did, here is another way using map (assuming @a >= @b)

sub alternate {
	my ( $a, $b ) = @_ ;
	map { $a->[$i], $b->[$i] } 0 .. $#{$a} ;
}

and if you don't mind destroying @b (which shouldn't be a problem with
anon arrays but could be with a ref to a real array):

sub alternate {
	my ( $a, $b ) = @_ ;
	map { $_, shift @$b } @$a ;
}

and finally another one that doesn't destroy @b but rotates it.
@a must == @b in this one.

sub alternate {
	my ( $a, $b ) = @_ ;
	my $c ;
	map { push @$b, $c = shift @$b; ($_, $c) } @$a ;
}

BTW that technique can be applied to multiple arrays which need to be
processed in parallel.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: 18 Aug 1999 19:52:06 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: pushing an anonymous hash slice
Message-Id: <7pf2t6$m35$1@info2.uah.edu>

In article <x7vhacyjxh.fsf@home.sysarch.com>,
	Uri Guttman <uri@sysarch.com> writes:

: well i wasn't saying you couldn't write a sub to do it.

What do you suppose the hypothetical alternate() would be if it weren't
a Perl operator? :-)

:                                                         but since you
: did, here is another way using map (assuming @a >= @b)
: 
: sub alternate {
: 	my ( $a, $b ) = @_ ;
: 	map { $a->[$i], $b->[$i] } 0 .. $#{$a} ;
: }

If @a and @b are different lengths, then you end up with undefs in the
result.  There's also the minor gripe about the calling context
propagating to the map().

: and if you don't mind destroying @b (which shouldn't be a problem with
: anon arrays but could be with a ref to a real array):
: 
: sub alternate {
: 	my ( $a, $b ) = @_ ;
: 	map { $_, shift @$b } @$a ;
: }

Same problems as above.

: and finally another one that doesn't destroy @b but rotates it.
: @a must == @b in this one.
: 
: sub alternate {
: 	my ( $a, $b ) = @_ ;
: 	my $c ;
: 	map { push @$b, $c = shift @$b; ($_, $c) } @$a ;
: }

Same problems.

: BTW that technique can be applied to multiple arrays which need to be
: processed in parallel.

So could interleave.

    sub interleave {
        my @result;

        # 'twould be nice to have lazy eval here
        while (grep @$_, @_) {
            for (@_) {
                push @result, shift @$_ if @$_;
            }
        }

        @result;
    }

It obviously has the side effect of destroying the referent arrays,
but you could fix that with a dclone if it were that important.  There's
probably also a cool way to do it with mjd's reduce.

Greg
-- 
The ability to quote is a serviceable substitute for wit. 
    -- Maugham


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

Date: 18 Aug 1999 16:28:51 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: pushing an anonymous hash slice
Message-Id: <x7so5gygsb.fsf@home.sysarch.com>

>>>>> "GB" == Greg Bacon <gbacon@itsc.uah.edu> writes:

  GB> In article <x7vhacyjxh.fsf@home.sysarch.com>,
  GB> Uri Guttman <uri@sysarch.com> writes:

  GB> : sub alternate {
  GB> : 	my ( $a, $b ) = @_ ;
  GB> : 	map { $a->[$i], $b->[$i] } 0 .. $#{$a} ;
  GB> : }

  GB> If @a and @b are different lengths, then you end up with undefs in the
  GB> result.  There's also the minor gripe about the calling context
  GB> propagating to the map().

i did mention the differing lengths issue. but it is not well defined
how to interleave two arrays of differing lengths. do you truncate, pad
or just append the tail of the longer one? all are valid but need
different code. i assumed equal lengths in advance as you should check
or know that before you merge in most cases. in the original post, the
lengths were known to be equal as one list was keys and the other an
array slice.

also propogating the calling context to the map is the user's
problem. this function obviously must return a list so assuming a useful
value in a scalar context is dumb. what would you want, the last value
of the merge? or if it was generated in a temp array, the size of the
array? 

  GB> : BTW that technique can be applied to multiple arrays which need to be
  GB> : processed in parallel.

  GB> So could interleave.

  GB> sub interleave {
  GB> my @result;

  GB> # 'twould be nice to have lazy eval here

or first.

  GB> while (grep @$_, @_) {
  GB> for (@_) {
  GB> push @result, shift @$_ if @$_;


on the original topic, making an interleaved list is more general than what
building a hash needs. you can easily rewrite it to do that.

sub build_anon_hash {

	my( $a, $b ) = @_ ;

	{ map { $a->[$i], $b->[$i] } 0 .. $#{$a} } ;
}

and this makes sense with $a having the keys. if $b is shorter, you
get the extra keys with undef for values. and no ugly context propogation

the other styles would work too if you don't mind destruction or
rotation or @$b

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: Wed, 18 Aug 1999 13:30:34 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: someone pleae help
Message-Id: <37BB17EA.727BF452@cisco.com>

[ Carlos Cerna wrote:

> My problem is that I need a script that would read a html page that
> contains a
> table (html generated) and allow me to change 6 text fields and write
> the changes back to the file.

What you ideally need is a script that can pick your 6 text fields
and generate your HTML page dynamically.  The form will
allow users to change the 6 text fields. When the new HTML
page is generated it will use the new updated values for these 6 text
fields.

--



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

Date: Wed, 18 Aug 1999 15:55:25 -0400
From: Jayant Rajan <rajan@nlm.nih.gov>
Subject: stupid socket question
Message-Id: <37BB0FAD.87D11DB5@nlm.nih.gov>

Hi-

I have what I hope is a pretty straightforward question, and I'd really
appreciate it if someone could help me out. Basically, what I have to do

is submit a query to a WWW search engine and save the output (in
non-HTML format - the engine actually allows this as an output option)
on my machine. The code I've written to do so is of the form:

use IO::Socket;

$EOL = "\015\012";
$BLANK = $EOL x 2;

$remote = IO::Socket::INET->new (Proto => "tcp",
     PeerAddr => "www.server",
     PeerPort => "http(80)");

$remote->autoflush(1);

open(OUT,">myfile");

print $remote "GET REQUEST HTTP/1.0".$BLANK;

while(<$remote>) {
  print OUT $_;
}

close($remote);
close(OUT);

Unfortunately, the program peters out without saving everything that it
should locally (I know this, b/c I've done the search manually via my
browser), and I'm certain that what I'm running into is a buffering
issue. Any help that anyone can odder is appreciated. Thanks!

Jay R





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

Date: 18 Aug 1999 16:45:40 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: stupid socket question
Message-Id: <x7lnb8yg0b.fsf@home.sysarch.com>

>>>>> "JR" == Jayant Rajan <rajan@nlm.nih.gov> writes:

  JR> $EOL = "\015\012";
  JR> $BLANK = $EOL x 2;

  JR> $remote = IO::Socket::INET->new (Proto => "tcp",
  JR> PeerAddr => "www.server",
  JR> PeerPort => "http(80)");

for simple sockets this is cleaner

$remote = IO::Socket::INET->new ( 'www.server:80' ) ;

  JR> $remote->autoflush(1);

i think this is turned on by default in the current versions of IO::Socket

  JR> open(OUT,">myfile");

  JR> print $remote "GET REQUEST HTTP/1.0".$BLANK;

what is REQUEST? 

  JR> Unfortunately, the program peters out without saving everything that it
  JR> should locally (I know this, b/c I've done the search manually via my
  JR> browser), and I'm certain that what I'm running into is a buffering
  JR> issue. Any help that anyone can odder is appreciated. Thanks!

i am very odder. does that help?


and you have done all this in one line with with LWP::Simple

use LWP::Simple ;

	getstore( 'http://www.server:80/QUERY_HERE', 'myfile' ) ;

substitute QUERY_HERE with your own query.
the :80 is redundant for http but what the hey!

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: Wed, 18 Aug 1999 12:52:31 -0400
From: David L Rubin <davidrubin@lucent.com>
Subject: which is better?(assignment(typeglob v ref))
Message-Id: <37BAE4CF.8DE2602A@lucent.com>

Let's say I want to do something like this (pseudocode):

	(array,err) = foo();
	if (err) {
		switch: {
			# error processing
		}
	}
	# process array

It seems that there are three choices for how to return an array and an error
code from a function:

1. ($err, @array) = foo();	# having err first irks me, so I don't like this soln
2. ($arrayref, $err) = foo();	# now I have to use $$arrayref[$i] or @$arrayref
3. (*array, $err) = foo();	# I can still use $array[$i] or @array

Of options 2 and 3, which is preferable? The only problem with 3 IME is that
array must be declared as local (I don't want it to be a global). So, everywhere
you use idiom 3, you have to do something like

	use vars qw(@array);
	local @array;
	my $err;

	(*array, $err) = foo();

This seems a bit clumsy, but the ability to refer use 'array' as a list as
opposed to a list reference (2) may make 3 worth the trouble...unless there is
another way.

I recall reading in some perl documentation that one should use idiom 3, but I
can't remember which document it was.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
David L Rubin			      f 1.973.581.6665 v 1.973.386.8598
Lucent Technologies, NJ0117 14J-211, 67 Whippany Rd, Whippany, NJ 07981


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

Date: Wed, 18 Aug 1999 18:29:28 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: While we are on the subject of tainting....
Message-Id: <cYCu3.9826$x04.531970@typ11.nn.bcandid.com>

In article <FGnKKp.LC0@csc.liv.ac.uk>, I.J. Garlick <ijg@connect.org.uk> wrote:
>In article <SViu3.7267$x04.408766@typ11.nn.bcandid.com>,
>pacman@defiant.cqc.com (Alan Curry) writes:

>I had figured that out, but my problem is I have to know exactly what
>'myprog' returns on both STDOUT while throwing away STDERR (most of the
>time) ocassionally I need what's on STDERR as well.
>
>MY denseness is, everything seems to imply that you can't do
>
>	my @ret = exec 'myprog', 'arg1', 'arg2' or die "can't exec myprog: $!";

No, you don't do it that way.

>I have never seen this done (not looked that hard I must admit) and the
>perlfunc man page says this in the first 2 lines on exec:-
>
>		The exec() function executes a system command AND NEVER
>		RETURNS - use system() instead of exec() if you want it to
>		return.
>
>But as I said the part on system says to use `` to capture output.

The warning you have seen about "don't use exec to capture output" is just
there because some people think exec by itself is supposed to return
subcommand output. It doesn't. To do that, you need to make a pipe, create a
new process, then exec and read, just as shown in the perlsec example. `` is
a shortcut which does all that stuff for you. Unfortunately it also uses a
shell to parse the command, which makes it harder to verify its security when
user input is involved.

>>   exec $prog, split(/\s+/, $opts) or die "exec failed: $!";
>> 
>> That doesn't take care of your 2>$errout though. To do that, you should put
>> before the exec:
>
>Mostly I put /dev/null in $errout but sometimes it needs to be 2>&1,
>standard unix stuff. Why wouldn't '2>/dev/null' work as an argument to
>'myprog' in the exec call?

Because 2> is shell syntax, and the whole reason for doing this thing the
long way is to avoid the shell.

The perl equivalent to 2>&1 is open(STDERR, ">&STDOUT")
-- 
Alan Curry    |Declaration of   | _../\. ./\.._     ____.    ____.
pacman@cqc.com|bigotries (should| [    | |    ]    /    _>  /    _>
--------------+save some time): |  \__/   \__/     \___:    \___:
 Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman


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

Date: Wed, 18 Aug 1999 20:16:26 +0100
From: Andrew Fry <andrewf@beausys.freeserve.co.uk>
Subject: Win32::OLE + Word/Excel
Message-Id: <32zSYAAKawu3EwQN@beausys.freeserve.co.uk>

Anyone know to use WIn32::OLE to...
1. Determine how many lines are in a Word document,
   and then read these lines ?
2. Determine how many rows/cols are occupied in an
   Excel document, and then read the cells ?
   (Actually, I think I know how to read the cells...).

I've been reading the ActivePerl documentation, but it
doesnt go very far. Very few examples about.

---
Andrew Fry
"Time flies like an arrow. Fruit flies like a banana". (Groucho Marx).


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

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


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