[7254] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 879 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 16 13:07:11 1997

Date: Sat, 16 Aug 97 10:00:23 -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           Sat, 16 Aug 1997     Volume: 8 Number: 879

Today's topics:
     100 links limit for free for all & books "Programming P <webmaster@dmedia.net>
     Beginner problems <equi@herald.infi.net>
     Re: Binary I/O: simple question? (Eric Bohlman)
     Chomp and chop <nrana@aludra.usc.edu>
     Re: Chomp and chop (Mike Stok)
     Re: counter log (Eric Bohlman)
     Re: help with starting CPAN <xuchu@iscs.nus.edu.sg>
     Re: how can i find out how much free disk space is avai (Clay Irving)
     how to test $ua->env_proxy? <xuchu@iscs.nus.edu.sg>
     HTML --> Perl conversion <webmaster@dmedia.net>
     Interfacing with Netware Perl.NLM? <loekje@flatnet.tudelft.nl>
     Re: newbie cgi question. (Mike Stok)
     Perl books suggestions <webmaster@dmedia.net>
     Re: Perl Performance FAQ? <friedman@uci.edu>
     Re: Perl Performance FAQ? (Tad McClellan)
     Re: Perl Performance FAQ? (Tad McClellan)
     Re: Perl Performance FAQ? <friedman@uci.edu>
     Re: perl5 regexes slower than perl4? (Ilya Zakharevich)
     PROPOSAL: Overloaded subs in perl (Aaron Sherman)
     Re: PROPOSAL: Overloaded subs in perl (Aaron Sherman)
     Re: proxy problem in perl (Michael Fuhr)
     Re: Question on and associative arrays and -w switch (M.J.T. Guy)
     Re: sorting... <petri.backstrom@icl.fi>
     Test <cismail4.mallen01@eds.com>
     Re: Uninitialized Value?  Really? (Jeff Stampes)
     Re: XS (converting perl array to char**..) <fox@vulpes.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sat, 16 Aug 1997 10:48:39 +0200
From: Aitor <webmaster@dmedia.net>
Subject: 100 links limit for free for all & books "Programming Perl
Message-Id: <33F56968.7883@dmedia.net>

Hi,

I'm working in a free for all script.
All working fine but I want to limit  the links to 100.

The script  insert in the page for each link added: 

print FILE "<LI><a href=\"$url\">$sitename</a><br>\n";
print FILE "$descript<br>\n";

Last link added gets first.

If I add for example    <!--end of links-->   just the next after the
oldest link added.

How can I delete the two lines before <!--end of links--> (that's the
URL and description of the oldest link) when a new link is added? 


Also I can't get working the sendmail. Proved with \ and without it in
the e-mail.

$mailprog = "/usr/sbin/sendmail";
$my_email = 'webmaster\@dmedia.net';

sub sendmail {
open(MAIL, "| $mailprog -t") || die "I can't open $mailprog\n";
	print MAIL "To: $my_name <$my_email>\n";
	print MAIL "From: SuperLinks\n";
	print MAIL "Subject: Someone added a link\n";
	print MAIL "The following URL was added to your add link page\n";
	print MAIL "title: $sitename URL: $url\n";
	print MAIL "Description: $descript\n";
close(MAIL);
		}


And finally, I want to get  some Perl books, (I've got good programming
background) any suggestion apart "Programming Perl ".
Wanted Perl to use on the WWW.


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

Date: Sat, 16 Aug 1997 10:32:30 -0400
From: Dan <equi@herald.infi.net>
Subject: Beginner problems
Message-Id: <33F5B9FE.38C2@herald.infi.net>

Hello,
I've decided that learning perl would be the best for all around
platform use. I do not have any
programming skills, so I will be starting from scratch. I just purchased
a huge book on the subject
and allready have run into trouble. The book tells me i should have perl
5 software. Is that the same
thing as the interpreter? Anyhow, I went to a site and downloaded the
zip version for win 32. I have
a win 95 box. I followed the steps very carefully to try to print " My
name is Yon Yonson" and that
does not work. I'm confused? In the bin directory I put a file named
test.pl that had this in it, 
#!/usr/local/bin/perl -w
print("My name is Yon Yonson,\n");
print("I live in Wisconsin,\n", "I work in a lumbermill there.\n");

Then, I opened the perl 5 program and typed perl test.pl and hit enetr
and nothing.
Then, I typed C:\perl5\bin\perl test.pl and it said I had a bunch of
syntax errors.

Am I even going aboutnthis the right way. I don't know anybody who knows
anything about the
subject and all I want to do is get started. I would really like to talk
to somebody who would not
mind being of some assisitance. 
Thank you
Dan


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

Date: Sat, 16 Aug 1997 12:38:20 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Binary I/O: simple question?
Message-Id: <ebohlmanEF0B3w.Bs7@netcom.com>

Peter E. Pulsifer (pulsifer@ppdpi4.ppd.nrl.navy.mil) wrote:
: In desperation, I've tried masking each byte and concatenating into a string
: using chr($num) - which I would think would be pretty slow.  And perl 4
: doesn't seem to recognize chr().  Is there a better/more universal way to
: write in binary????

pack() would probably be helpful.

Perl 4 has expired and gone to meet the Great Camel In The Sky.  Bereft of
maintenance it sleep()'s in peace.  If your sysadmin hadn't nailed it to 
your filesystem it would be pushing up the daisies.  It is an ex-Perl.




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

Date: 15 Aug 1997 16:14:40 -0700
From: Nadim <nrana@aludra.usc.edu>
Subject: Chomp and chop
Message-Id: <Pine.SV4.3.94.970815161335.22551A-100000@aludra.usc.edu>


Could anyone let me know the difference between chomp and chop? I am
trying to use chomp in my script but it is not getting compiled. Why?

Thanks
Nadeem
nrana@scf.usc.edu



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

Date: 16 Aug 1997 11:57:20 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Chomp and chop
Message-Id: <5t44j0$sk8@news-central.tiac.net>

In article <Pine.SV4.3.94.970815161335.22551A-100000@aludra.usc.edu>,
Nadim  <nrana@aludra.usc.edu> wrote:
>
>Could anyone let me know the difference between chomp and chop? I am
>trying to use chomp in my script but it is not getting compiled. Why?

chomp was introduced in perl 5, so in the absence of any error message I
would guess you're running an earlier perl.  Chop gets rid of the last
character of a scalar regardless of what it is, chomp removes a (possibly
multi character) end of line sequence from a scalar (the end lf
line/record sequence is stored in $/) so if the scalar doesn't end in that
sequence it's left alone.  This is useful if you have saved a file in an
editor which thinks that the end of file is a good enough end of line
sequence for the last line in a file...

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Sat, 16 Aug 1997 12:49:05 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: counter log
Message-Id: <ebohlmanEF0BLt.C9o@netcom.com>

Bobbi Arlett (bja109@mail.usask.ca) wrote:
: Could anyone tell me how to change IP addresses to host names in a perl
: script for windows NT?  I tried nslookup but the version I have doesn't
: work.

Try using gethostbyaddr().

: Please respond via e-mail.

Please read the groups you ask questions in.



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

Date: 16 Aug 1997 09:30:31 GMT
From: Xu Chu <xuchu@iscs.nus.edu.sg>
Subject: Re: help with starting CPAN
Message-Id: <5t3rvn$i7h@nuscc.nus.sg>

ok, i found out that the problem is caused by the proxy settings. the proxy
should be set to http://proxy.nus.sg:8080. but the "$ua->env_proxy" doesnt seem to work! how can i set the proxy in the program? thx for any help.

-- 
wings
------
You cannot learn anything unless you almost know it already.



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

Date: 16 Aug 1997 11:42:46 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: how can i find out how much free disk space is available in perl
Message-Id: <5t4hpm$ftn@panix.com>

In <5st8it$sqd$1@netnews.upenn.edu> dmacks@sas.upenn.edu (Daniel E. Macks) writes:

>weiner (kweiner@bloomberg.com) said:
>: thanks!!!!!

>You're welcome. But don't thank us until you get an answer to a
>question that you almost asked with enough detail for an answer.  Most
>importantly: what OS? On Unix systems, you could parse the results of
>`df`. Otherwise, there may or may not be a some system call and/or
>routine in the OS-specific CPAN modules. I don't see a perlish wrapper
>for the actual system call on CPAN, but if you're feeling adventurous,
>you could write (and contribute:) blahblah::DF based on statvfs().

Perl Modules are your friend.

Try: http://www.panix.com/~clay/perl/module.cgi?Filesys::Df

-- 
Clay Irving <clay@panix.com>                   http://www.panix.com/~clay/


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

Date: 16 Aug 1997 12:54:47 GMT
From: Xu Chu <xuchu@iscs.nus.edu.sg>
Subject: how to test $ua->env_proxy?
Message-Id: <5t47un$juq@nuscc.nus.sg>

how can i know if it works at all? any way to test it? mine doesnt seem to work:(

-- 
wings
------
You cannot learn anything unless you almost know it already.



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

Date: Sat, 16 Aug 1997 11:05:49 +0200
From: Aitor <webmaster@dmedia.net>
Subject: HTML --> Perl conversion
Message-Id: <33F56D6E.68DA@dmedia.net>

Is there any program (for Macintosh) to transtale to perl an HTML page?

Thanx.


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

Date: Sat, 16 Aug 1997 12:40:13 +0200
From: Loek Gijben <loekje@flatnet.tudelft.nl>
Subject: Interfacing with Netware Perl.NLM?
Message-Id: <33F5838C.867BA7AE@flatnet.tudelft.nl>

Wow, what a big newsflow this group has...

Anyway, it seems hard to find a Perl for Netware programmer who does
more than building cgi scripts :(

The info to the Perl NLM package is near to nothing. No source either :(

I need someone to point me in the right direction how to interface with
the system. I.E. how to make system calls.

There's a little example in the associate symbol.txt file which handles:

" Dynamic Symbol UserSub package for Perl.NLM "

a piece of script goes like:

sub SendConsoleBroadcast {  # ($msg [, @list of connections])
  local($msg) = shift(@_);
  local($func) = &Symbol'Import("SendConsoleBroadcast");
  die "$!" if ($func == 0);
  local($conn) = pack("S*", @_);
  local($args) = pack("pLp", $msg, scalar(@_), $conn);
  local($ret) = &Symbol'Call($func, $args);
  &Symbol'Unimport("SendConsoleBroadcast");
  $ret = unpack("i", $ret);
  # return $ret
}

$i = &SendConsoleBroadcast("this is the message", 2);

This won't work at all :-(
At least it seams that one can interface with "symbolcalls" to
SendConsoleMessage
But how on earth can I find other "symbols"

Any tips on how to make this work?
Any tips on where to find more info?

TIA,
Loek Gijben





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

Date: 16 Aug 1997 13:28:42 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: newbie cgi question.
Message-Id: <5t49ua$3jf@news-central.tiac.net>

In article <33F54057.5A63@sj.bigger.net>, ray  <raymond@sj.bigger.net> wrote:
>I am having problems in trying to use cgi.pm to get the selected list of
>items from a list created in a form for html. The list was created as a
>scrolling list with MULTIPLE added to its tag. However, when I call 
>
>$query = new CGI();
>$x = $query->param($listName);
>
>then $x only contains the first selected item from the list.

You might want to check out the documentation for the module (on a
properly installed recent perl distribution

  perldoc CGI

should get it) which says:

       FETCHING THE VALUE OR VALUES OF A SINGLE NAMED PARAMETER:


           @values = $query->param('foo');

                     -or-

           $value = $query->param('foo');

       Pass the param() method a single argument to fetch the
       value of the named parameter. If the parameter is
       multivalued (e.g. from multiple selections in a scrolling
       list), you can ask to receive an array.  Otherwise the
       method will return a single value.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Sat, 16 Aug 1997 11:19:08 +0200
From: Aitor <webmaster@dmedia.net>
Subject: Perl books suggestions
Message-Id: <33F5708D.36E9@dmedia.net>

I'm learning Perl and I want to get  some Perl books, 
(I've got good programming background) 

any suggestion apart "Programming Perl ". 

Wanted Perl to use on the WWW. 

I've got a  Mac and the server uses Unix.


Thanx in advance.


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

Date: 16 Aug 1997 07:53:50 GMT
From: "Eric D. Friedman" <friedman@uci.edu>
Subject: Re: Perl Performance FAQ?
Message-Id: <5t3mae$5sg@news.service.uci.edu>

[mailed, posted]

In article <5b203un3kx.fsf@smokey.prismnet.com>,
Mark A. Lehmann <mlehmann@prismnet.com> wrote:

<However, I would like to have a FAQ or common respository of hints, tips, and
<testimonies on increasing perl performance. 

Sounds like a good idea. Here's something to include (it was a surprise to
me):

However appealing it may be to write loops like this ->

for (0 .. 10000)
{
# do stuff
}

An efficient program will opt for this instead ->

for (my $i = 0 ; $i <= 10000; $i++)
{
# do stuff
}

Why? because in the first case, Perl has to create a list (wasting memory,
time) of 10,001 values, while in the second case it merely counts with
an integer.  Thus, while the first one LOOKS more efficient, it isn't.

Another tip I derive from a posting I saw here not too long ago:

If you have a loop which will be executed many times, it may actually
be faster if you declare 'my' variables outside of the repeated block,
since the declaration will then only take place once.

Thus, the following may be faster, even if it's uglier:

my $foo = undef;
for (my $i =0; $i <= 10000; $i++)
{
  $foo = some_function ($i);
  print "$foo\n";
}

A third thing to include would be a reminder that `each' exists and
should be used wherever possible with hashtable enumerations, since it
doesn't create an array the way `keys' does.

Fourth: document the Schwartzian Transform, which is reported to be
more efficient than other solutions to the problem of sorting
multi dimensional arrays by indices other than those of the outer array.

Fifth: the use of AUTOLOAD to create named accessor object methods
(documented in perltoot) is clever and useful, but the method is only
'found' and executed after all other possible places have been
checked.  I don't know if this search is repeated if the same method is
called repeatedly, but I'm willing to bet that this is one of those
circumstances where less code != more efficient.

Sixth:

s/^\s*//; is reputed to be much less efficient than
s/^\s+//; 

Seventh:

tr/// is often faster than the equivalent s///

But now I'm starting to drift into Friedl's territory, where I'm very
much out of my depth.

-edf
-- 
Eric D. Friedman
friedman@uci.edu


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

Date: Sat, 16 Aug 1997 08:29:25 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Perl Performance FAQ?
Message-Id: <lv94t5.5ha.ln@localhost>

Eric D. Friedman (friedman@uci.edu) wrote:
: [mailed, posted]

: In article <5b203un3kx.fsf@smokey.prismnet.com>,
: Mark A. Lehmann <mlehmann@prismnet.com> wrote:

: <However, I would like to have a FAQ or common respository of hints, tips, and
: <testimonies on increasing perl performance. 

: Sounds like a good idea. Here's something to include (it was a surprise to
: me):

[ snip ]


: Seventh:

: tr/// is often faster than the equivalent s///
           ^^^^^

Just "often"?

I would have thought "always".

Is there really some case where s/// would be faster?


: But now I'm starting to drift into Friedl's territory, where I'm very
: much out of my depth.


Me too, blub, blub, blub...


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Sat, 16 Aug 1997 08:47:46 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Perl Performance FAQ?
Message-Id: <22b4t5.uia.ln@localhost>

Mark A. Lehmann (mlehmann@prismnet.com) wrote:
: I see a lot of need to up my scripts performance.  I own a perl application
: that consists of about 100 perl files and perhaps 18,000 lines of Perl code.

[ snip ]

: However, I would like to have a FAQ or common respository of hints, tips, and
: testimonies on increasing perl performance.  I know that Perl programmers
: care mostly about the speed that they can produce quality code, but my
: customers don't care how quick I can write the code, they want quick
: application turnaround and quick implemtation.


But aren't 
   "don't care how quick I can write the code" 

and 
   "want quick ... implemtation" 

mutually exclusive?                    ;-)


: I'll provide the website or maintain the FAQ, but I need to know if this
: already exists and if there is interest in this topic.


This sounds very interesting to me. I would like to see such a FAQ.



Another potential subject area might be things that depend on the
particular data that perl accesses rather than on "general speed up"
type of things.

There are some things that will speed it up regardless of the data.
 eg: m//o (provided you meet the conditions that allow you to use it,
           of course)

Some that speed things up for "most" data.
 eg: for(;;) rather than foreach() if the array is large (as mentioned 
     in Eric's followup), and we could assume they are large, else the 
     programmer would not be looking at a FAQ to get better speed  ;-)

Some that rely a great deal on the qualities of data. Particularly
helpful if you can define a "typical" data set for the application.
 eg: study()


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: 16 Aug 1997 15:57:59 GMT
From: "Eric D. Friedman" <friedman@uci.edu>
Subject: Re: Perl Performance FAQ?
Message-Id: <5t4im7$h9o@news.service.uci.edu>

In article <lv94t5.5ha.ln@localhost>, Tad McClellan <tadmc@flash.net> wrote:
<Eric D. Friedman (friedman@uci.edu) wrote:
<
<: tr/// is often faster than the equivalent s///
<           ^^^^^
<Just "often"?
<
<I would have thought "always".
<

And you're surely right.  I was just covering my assets. ;-)  Thanks
for confirming my somewhat fuzzy guess!

-edf
-- 
Eric D. Friedman
friedman@uci.edu


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

Date: 16 Aug 1997 10:53:53 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: perl5 regexes slower than perl4?
Message-Id: <5t40s1$18f@agate.berkeley.edu>

In article <5t3jef$129$1@vixen.cso.uiuc.edu>,
Andrew Dalke <dalke@ks.uiuc.edu> wrote:
>   I think I found the culprit - character classes.  Here's the
> description of the different things I tried.  The general code
> framework is at the end of this post.

> I then replaced the @regex strings with a character class equivalent,
> so the line with the comment (1) would look like:
>   @regex = ('[W][D]', '[C][A][W][Q][F][F]'. '[G][Y][D]', '[D][D][O]', ... );
> 
> The time for perl 5.004 on this is about 78 seconds (3 runs)
> The time for perl 4.036 on this is about 30 seconds (2 runs)

This change happened between 5.003_07 and 5.003_09.  It should be easy
to pinpoint the problem now, when this is known.  (Note that
pinpointing not necessarily means an easy fix, though in this case it
may - the major change between these versions is introduction of
locales, and locales are disabled by default now.)

Thank you a lot for your great work, this may explain many mysterious
slowdowns.

Best,
Ilya


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

Date: 16 Aug 1997 03:38:32 -0400
From: ajs@lorien.ajs.com (Aaron Sherman)
Subject: PROPOSAL: Overloaded subs in perl
Message-Id: <5t3ldo$eqh@lorien.ajs.com>

This is what comes of waking up a 3AM and drinking Gatorade while
re-reading _Effective C++ Programming_....

Here's a proposal for how to handle C++ style function overloading in
perl. It requires some funky syntax, but it should work. I'm aware
that I can do this by hand for each sub that I write, but dagnabbit, I
don't wanna! This also gives me a cheap way out for argument checking
and error reporting.

The usage would be:

	overloaded_sub mysub => q($$), sub {
		....code....
	};

	overloaded_sub mysub => q($$$), sub {
		....code....
	};

Or, for methods:

	overloaded_sub mymethod => q(\My::Package$$), sub {
		....code....
	};

The idea would be that \% would expect a ref to HASH, but \packname
would expect a ref to a packname or a package whose ISA cotains
packname.

This introduces alphas into prototypes, but since it doesn't change
the underlying mechanism Larry is still free to put parameter names
into prototypes at some future date. Woefully, you can't get
overloading and true prototypes together unless function overloading
is put into the core, which I'm not sure I would want.

In some cases, your prototypes would just get less specialized, and
order would matter:

	overloaded_sub mysub => q(\%\@$), "Usage: Choke", sub {};
	overloaded_sub mysub => q(\%\&$), "Usage: Choke", sub {};
	overloaded_sub mysub => q(\%$$), "Usage: Choke", sub {};
	overloaded_sub mysub => q($$$), "Usage: Choke", sub {};

Here, the last mysub would match any of the others, but because it's
last, it just acts as a catch-all.

Below, I've included my outline for how overloaded_sub would be
defined. It uses a couple of utility routines which would have to be
defined. The most complex of these is match_proto, which would have to
parse a prototype string.

Anyone up to it?

package Overload::Sub;

use strict;
use vars qw(@EXPORT @EXPORT_OK @ISA $VERSION %sub_info);
require Exporter;
use Carp;

@ISA=qw(Exporter);
@EXPORT=qw(overloaded_sub);
@EXPORT_OK=qw(overloaded_sub);

$VERSION="0.1a";
sub VERSION {$VERSION}

%sub_info = ();

sub overloaded_sub ($$$;$) {
  my $sub_name = shift;
  my $proto = shift;
  my $usage;
  if (@_ == 2) {
    $usage = shift;
  } else {
    $usage = make_usage($proto);
  }
  my $code = shift;
  my $pkg = caller(0);
  
  if (defined &{$pkg."::".$sub_name}) {
    if (!exists $sub_info{$sub_name}) {
      croak "overloaded_sub: $sub_name is already defined as a sub";
    }
  } else {
    *{$pkg."::".$sub_name} = sub {
      my $subs = $sub_info{$sub_name};
      foreach $sub (@$subs) {
	if (match_proto($sub->{proto},\@_)) {
	  goto &{$sub->{code}};
	}
      }
      croak("Available usages for ${pkg}::$sub_name:\n".
	    join("\n",map{$_->{usage}}@$subs)."\n\t");
    };
  }
  push(@{$sub_info{$sub_name}}, {
				 proto => $proto,
				 usage => $usage,
				 code => $code
				});
  return 1;
}

1;

__END__


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

Date: 16 Aug 1997 11:31:17 -0400
From: ajs@lorien.ajs.com (Aaron Sherman)
Subject: Re: PROPOSAL: Overloaded subs in perl
Message-Id: <5t4h45$gb5@lorien.ajs.com>


One thing that I did not mention is the difficulty in handling this case:

	package x;
	overloaded_sub a => q(\x$), sub { print 1 };
	package y;
	@ISA=qw(x);
	overloaded_sub a => q(\y), sub { print 2 };
	package main;
	$o = bless {}, y;
	$o->a(1);

You really want this to generate a call to x::a, not an error, but that
means some wild ISA handling in the stub sub.

			-AJS


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

Date: 16 Aug 1997 08:46:29 -0600
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: proxy problem in perl
Message-Id: <5t4eg5$3ip@flatland.dimensional.com>

Xu Chu <xuchu@iscs.nus.edu.sg> writes:

> i wanna extract html files from a certain url. thanks to R.L.Schwartz's web Techniques, i can do the job when the url is 
> an intra one. for example, i am studying in NUS and if I am fetching files from NUS server, then no problem; however, when
> i try to fetch files from outside NUS, it fails. The university uses a proxy and everything has to pass thru it... i think 
> there must be a way in the CPAN LWP module to handle it but i cant find it out:( can anyone show me how to handle this proxy
> problem?

  "Give a man a fish and he eats for a day.
   Teach a man to fish and he eats for a lifetime."

Have you considered searching for the word "proxy" in the LWP
documentation?  :-)

-- 
Michael Fuhr
http://www.dimensional.com/~mfuhr/


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

Date: 16 Aug 1997 14:54:40 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Question on and associative arrays and -w switch
Message-Id: <5t4evg$1h7$1@lyra.csx.cam.ac.uk>

Craig Berry <cberry@cinenet.net> wrote:
>Saviz Artang - MPG ~ (sartang@pcocd2.intel.com) wrote:
>: The problem I'm having is that I'm using an associative array to 
>: represent a hash of a list that I have.  I do searches through 
>: this hash and when things are found every thing is good 
>: but when things are not found in this associative array the 
>: -w causes the code to spit out warnings saying an uninitialize 
>: value was used, since I have an if statement to see if the 
>: item was there or not:  
>: 
>: if ( a{"key"} ) { 
>
>Yes; test for ( defined $a{"key"} ) instead of just ( $a{"key"} ).  Hope 
>this helps!

Almost always, you should use   exists $a{"key"}  to see if a given hash
entry exists, rather than  defined $a{"key"}.   See the perlfunc entries on
"defined" and "exists" for the difference between the two.


Mike Guy


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

Date: Thu, 14 Aug 1997 13:30:56 +0300
From: Petri Backstrom <petri.backstrom@icl.fi>
Subject: Re: sorting...
Message-Id: <33F2DE60.4325@icl.fi>

Pat Trainor wrote:
> 
>         Thanks to everyone who replied with the count++ problem, I learned a lot fast!
> Now for another lob..
> 
>         if I output:
> 
> while (($key, $value) = each(%MAIN_CHOICES)) {
>         print "$key has a value of $value\n <br>";
> }
> 
>         The output is unsorted.
> 
>         What is the best way to sort the output by either key or value? Do I need to
> port the output through sort and build another array? Sorry for the newbie question!

One way to sort by key:

 foreach ( sort keys %ENV ) {
       print "Key $_ has a value of $ENV{$_}\n";
   }

See also, e.g., the frequently asked question (FAQ):

   "How do I sort a hash (optionally by value instead 
   of key)?"

You can find the FAQ through

   http://www.perl.com/FAQ/

regards,
 ...petri.backstrom@icl.fi
    ICL Data Oy
    Finland


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

Date: Fri, 15 Aug 1997 13:30:05 -0500
From: Marcus Allen <cismail4.mallen01@eds.com>
Subject: Test
Message-Id: <33F4A02D.34AB@eds.com>

Verifing I can Post!!


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

Date: 16 Aug 1997 16:13:45 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Re: Uninitialized Value?  Really?
Message-Id: <5t4jjp$7ud$1@neocad.com>

Tad McClellan (tadmc@flash.net) wrote:
: Jeff Stampes (stampes@xilinx.com) wrote:
: :    if (@platforms == ()) {@platforms = keys %platforms} ## Line 317

: I assume you are trying to check if @platforms has any elements in it?

: Can't you just do this instead?

:    if (@platforms == 0) {@platforms = keys %platforms} ## Line 317


[Smacking forehead]  

Of course I can...not only can I, but I should, could, and will.

Thanks,

Jeff

--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com


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

Date: Sat, 16 Aug 1997 09:51:51 -0400
From: Ken Fox <fox@vulpes.com>
To: John Tucker <jatucker@austin.dsccc.com>
Subject: Re: XS (converting perl array to char**..)
Message-Id: <33F5B077.4565@vulpes.com>

John Tucker wrote:

> I'm using perlxs to create a perl extension ...
> most of these functions expect a "char**" member which
> represents an array of file pathnames.

> The following shows a the way I want the Perl interface to
> the C function to be and the ".xs" code that I'm trying to
> develop:

>   my $result = &MyExt::func(@files, "fixed all errors.");

You'll have to prototype your function as (\@;$$) if you
want to call it like this.  Otherwise the @files is flattened
out before it gets passed to your subroutine.

>   int
>   func(files, branch="", comment=".")
>         char **files;
>         char *comment;

The way I'd do this is to create a typedef for your 'char **'
called 'StringArray'.  Then I'd write a typemap to convert
from perl to that.  It can be done without a typemap, but you'll
write a lot of the same code over and over.  If you can move
the files argument to the end, you can write your typemap so
that users can pass in a list or an array or an array ref.
It would mean giving up the optional arguments, but you can
provide perl sub wrappers to get the same effect.

So, the XS code I'd write would look something like:

int
func(branch, comment, files)
	char *		branch
	char *		comment
	StringArray	files
	CODE:
		RETVAL = func(files, branch, comment);
		freeStringArray(files);
	OUTPUT:
		RETVAL

The perl sub wrappers would be:

sub func_no_comment {
	my $branch = shift;
	func($branch, ".", @_);
}

sub func_no_branch {
	my $comment = shift;
	func("", $comment, @_);
}

These are stupid names of course, but I have no way of knowing
what would be better ones for your module.

I don't have time to show you the typemap right now, but if
you (or anybody else) is interested I can do it later.

If you need the length of StringArray, just make it a two
element struct like:

typedef struct {
	char **data;
	int len;
} *StringArray;

and then change the typemap to build one of those instead of
a simple 'char **'.

This technique actually generalizes into a "helper" perl class.
The reason the helper is attractive (hmm...) is that it removes
a possible memory leak if your function croaks before
getting a chance to free the temporary 'char **'.  It can also
create better performance possibilities if you start creating
higher level subs that pass the same StringArray into several
different XS routines.

- Ken


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

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

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