[25086] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7336 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 29 00:05:49 2004

Date: Thu, 28 Oct 2004 21:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 28 Oct 2004     Volume: 10 Number: 7336

Today's topics:
        FAQ 4.51: How do I permute N elements of a list? <comdog@panix.com>
    Re: file tests <jurgenex@hotmail.com>
    Re: How do I parse this Charactor? 2byte vs 1byte <see@sig.invalid>
    Re: Little question on regex. <lwt0301@bellsouth.net>
    Re: Little question on regex. <uri@stemsystems.com>
    Re: localizing %SIG handlers <nospam-abuse@ilyaz.org>
    Re: modifying hash key (dispatch table) <tadmc@augustmail.com>
        OT: perl errors <jeff@spamalanadingong.com>
    Re: OT: perl errors <noreply@gunnar.cc>
    Re: OT: perl errors <lwt0301@bellsouth.net>
    Re: OT: perl errors <mritty@gmail.com>
    Re: OT: perl errors <lwt0301@bellsouth.net>
    Re: OT: perl errors <matthew.garrish@sympatico.ca>
        PERL 64bit Question <tyates@newsguy.com>
    Re: perl errors <matthew.garrish@sympatico.ca>
    Re: print FILE function() <noreply@gunnar.cc>
    Re: print FILE function() <cNaOlSePbA@MvPeLtEsAtSaEr.com>
    Re: print FILE function() <1usa@llenroc.ude.invalid>
    Re: print FILE function() <mritty@gmail.com>
        returning from Net::Telnet cmd (justme)
        using Win32::ODBC - what's fast? <noemail@#$&&!.net>
    Re: using Win32::ODBC - what's fast? <matthew.garrish@sympatico.ca>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 29 Oct 2004 04:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.51: How do I permute N elements of a list?
Message-Id: <clsfdl$sv0$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

4.51: How do I permute N elements of a list?

    Use the List::Permutor module on CPAN. If the list is actually an array,
    try the Algorithm::Permute module (also on CPAN). It's written in XS
    code and is very efficient.

            use Algorithm::Permute;
            my @array = 'a'..'d';
            my $p_iterator = Algorithm::Permute->new ( \@array );
            while (my @perm = $p_iterator->next) {
               print "next permutation: (@perm)\n";
            }

    For even faster execution, you could do:

       use Algorithm::Permute;
       my @array = 'a'..'d';
       Algorithm::Permute::permute {
          print "next permutation: (@array)\n";
       } @array;

    Here's a little program that generates all permutations of all the words
    on each line of input. The algorithm embodied in the permute() function
    is discussed in Volume 4 (still unpublished) of Knuth's *The Art of
    Computer Programming* and will work on any list:

            #!/usr/bin/perl -n
            # Fischer-Kause ordered permutation generator

            sub permute (&@) {
                    my $code = shift;
                    my @idx = 0..$#_;
                    while ( $code->(@_[@idx]) ) {
                            my $p = $#idx;
                            --$p while $idx[$p-1] > $idx[$p];
                            my $q = $p or return;
                            push @idx, reverse splice @idx, $p;
                            ++$q while $idx[$p-1] > $idx[$q];
                            @idx[$p-1,$q]=@idx[$q,$p-1];
                    }
            }

            permute {print"@_\n"} split;



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Fri, 29 Oct 2004 02:57:20 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: file tests
Message-Id: <kkigd.11010$kr4.5761@trnddc01>

Xenos wrote:
> Do file tests only works with statements of the form:
>
> do_something if -e filename;
>
> can't I do something like:
>
> if -e filename
> {
>  do several things here
> }
>
> It doesn't see to like this.

Well, yeah, for rather obvious reasons. Didn't you get a syntax error? You 
should have included it in your posting. As an error description "It doesn't 
seem to like it" is about as useless as possible.

In Perl the condition in an "if" statement must be enclosed in paranthesis:

if (-e filename) {
      # do several things here
 }

Further details please see "perldoc perlsyn", section  "Compound statements"

jue 




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

Date: Thu, 28 Oct 2004 21:27:00 -0400
From: Bob Walton <see@sig.invalid>
Subject: Re: How do I parse this Charactor? 2byte vs 1byte
Message-Id: <41819a33$1_4@127.0.0.1>

nntp wrote:

> "Karel Kubat" <karel@e-tunity.com> ????
> news:417fdccf$0$142$e4fe514c@dreader19.news.xs4all.nl...
> 
 ...
> The first several lines:
> <HTML XMLNS:IE>
> <head>
> <mainD5>
> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
> URL of the page is www.ebay.com

When I download http://www.ebay.com, I find there are no characters 
present which appear to be encoded in any fashion whatever, nor any 
which are not in the ASCII character set (and thus in ISO-8859-1, in the 
half of it which does not have the high-order bit set).  Are you certain 
you are downloading and handling the data in the page correctly?

> I see charset=ISO-8859-1. Isn't that regular 1 byte encoding?

I'm not sure what you mean by "regular 1 byte encoding".  If you asking 
the question "is ISO-8859-1 a 1-byte encoding", then I guess the answer 
is no, ISO-8859-1 isn't an encoding at all.  It's just a character set. 
  Each character in it is one byte (8 bits, that is) long.  In 
ISO-8859-1, the high-order bit is used for some of the characters (well, 
about half of them).  If those are displayed using software which uses a 
different character set other than ISO-8859-1, the results may appear to 
be garbled.  Therefore, if you wish to view characters using the 
ISO-8859-1 character set, use a viewer that uses the ISO-8859-1 
character set.  If you want more detail, you might have better luck in a 
newsgroup dealing with character sets -- this newsgroup deals with Perl. 
  Or just look it up yourself.  Good references are found in the first 
page of results from Google.

 ...

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: Thu, 28 Oct 2004 22:19:00 -0400
From: Laura <lwt0301@bellsouth.net>
Subject: Re: Little question on regex.
Message-Id: <10o3aap1bhjlj96@news.supernews.com>

Uri Guttman wrote:

>>>>>> "L" == Laura  <lwt0301@bellsouth.net> writes:
> 
>   >> There is the pattern that I want to match:
>   >> 
>   >> I want a line that have a "..." string in but not any "//"
>   >> characters.
>   >> 
>   >> Exemple:
>   >> 
>   >> public void Foo("test")                 [This one match]
>   >> //  public void Foo("test")                 [This one doesn't match]
>   >> 
> 
>   L> $string = $ARGV[0];
>   L> if (!($string =~ m/\/\//))
>   L> {print "match!\n";}
>   L> else
>   L> {print "no match.\n";}
> 
> huh? that doesn't even come close to what the OP asked for. where is the
> match for '...' (i assume the OP means some arbitrary string
> there). then your logic is backwards with print "match" when the match
> fails. finally you should use alternate delimiters when you need to
> match / chars. 3 strikes and yer out! (just like the cardinals).

I hate to say it, but my solution does work.  As a complete Perl script, you
can cut&paste and run it using the 'OP's exact example and they will match
and not match exactly as he requested.  My 'backwards' logic leads to the
exact logical solution that was requested.  Not that it is the only or the
best solution, but it is a correct solution nonetheless.  Just because I am
a beginner in Perl (which I do not put down as you previously claimed and I
happen to like very much) and I am not a world renown, published Perl
hacker like yourself, does not mean that I do not have a brain and that I
cannot learn and come up with a workable solution in very simple cases such
as this.  I hate to have to respond like this in a thread that involves an
honest question and an honest answer, but you started it.  I would have
hoped to see the experts make constructive suggestions and propose more
advanced alternatives.  Sometimes it may be constructive to see the
beginner's solution as well as the expert's.  I may have been wrong on
other points I have made in the past, but you should judge my answer here
on its own merits.

I think the m/\/\// looks pretty and I'm sure that if a newcomer like me can
get it, most Perl programmers will have no problem identifying its meaning.

> 
> so when will you decide to actually learn perl? you seem to have the
> interest but haven't mastered even the basics. i recommend you read a
> few decent perl books and more of the docs before you embarrass yourself
> again here.
> 
> uri



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

Date: Fri, 29 Oct 2004 03:00:23 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Little question on regex.
Message-Id: <x7r7nitel4.fsf@mail.sysarch.com>

>>>>> "L" == Laura  <lwt0301@bellsouth.net> writes:

  L> I hate to say it, but my solution does work.  As a complete Perl
  L> script, you can cut&paste and run it using the 'OP's exact example
  L> and they will match and not match exactly as he requested.  My
  L> 'backwards' logic leads to the exact logical solution that was
  L> requested.  Not that it is the only or the best solution, but it is
  L> a correct solution nonetheless.  Just because I am a beginner in

it isn't correct. he wanted to match a string in lines that didn't
contain //. your code just matched // or not. not much of backwards
logic nor forwards logic.

  L> Perl (which I do not put down as you previously claimed and I
  L> happen to like very much) and I am not a world renown, published
  L> Perl hacker like yourself, does not mean that I do not have a brain
  L> and that I cannot learn and come up with a workable solution in
  L> very simple cases such as this.  I hate to have to respond like
  L> this in a thread that involves an honest question and an honest
  L> answer, but you started it.  I would have hoped to see the experts
  L> make constructive suggestions and propose more advanced
  L> alternatives.  Sometimes it may be constructive to see the
  L> beginner's solution as well as the expert's.  I may have been wrong
  L> on other points I have made in the past, but you should judge my
  L> answer here on its own merits.

you have not shown interest in listening to others and continue to spout
FUD. plenty of beginners here try to help out but not many spew stuff
like perl isn't compiled, and c is always faster and other nonsense.


  L> I think the m/\/\// looks pretty and I'm sure that if a newcomer
  L> like me can get it, most Perl programmers will have no problem
  L> identifying its meaning.

it is called leaning toothpick syndrome and it is why larry made sure
all quotelike operators could take alternative delimiters.

see, i am trying to teach you something. you decided it wasn't worth
it. so i decide your posts aren't worth much. i follow up your posts to
make sure others who read them later (via google) will see better
answers or at least refutations of yours.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Fri, 29 Oct 2004 03:47:00 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: localizing %SIG handlers
Message-Id: <clsefk$2nid$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Anno Siegel
<anno4000@lublin.zrz.tu-berlin.de>], who wrote in article <clleej$80c$1@mamenchi.zrz.TU-Berlin.DE>:
> > The first thing to check is whether just *assignment* to $SIG{HUP} is
> > a signal-safe operation (it may contain some more windows of
> > vulnerability).  If it is safe (10^8 signals savely delivered is a
> > good indication - should take couple of days on current OSes),
> 
> Eleven, signalling at a rate of 100 ticks per second.  One can signal
> faster, but (as far as I can see) only with a busy timer.  Is there
> anything particular to 10^8 or is it just an arbitrary big number?

I can signal at 1000/sec (recent OS/2).  Given reasonable delay on
Usenet of a day or two, this gives 10^8.  ;-) [If one believes
back-of-envelopo calculations, then the active code of a small test
program should be about 10^4 instructions; so n*10^4 signals have a
good probability to hit at all instruction boundaries.  However, I
have seen Perl signal handling problems which happen much more rare
than this...]

> > I would think that this would be safe too:
> > 
> >   #!/usr/bin/perl -w
> >   use strict;
> >   sub DESTROYER::DESTROY {shift->()}
> >   sub ON_DESTROY (&) {bless shift, 'DESTROYER'}
> >   sub LOCAL_SIG (&$) {my $s=pop; my $o = $SIG{$s}; $SIG{$s}=shift;
> > 		      ON_DESTROY {$SIG{$s}=$o || 'DEFAULT'}}
> > 
> >   $SIG{HUP} = \&global_sig;
> >   {  my $on_leave = LOCAL_SIG {warn 'got SIG'} 'HUP';
> >      # Do something...
> >   }

> Ah... so you oblige the user to accommodate an additional variable
> in the scope of the local handler.

Actually, I sent a patch to p5p a couple of years ago which "would do
the same" without an extra variable.  It would work as

   {  ON_LEAVE { do something };
      # Do something here
   }

Do not know whether it made it into 5.8.*...  (It was a part of
Scalar::Utils, IIRC.)

Yours,
Ilya


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

Date: Thu, 28 Oct 2004 21:25:46 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: modifying hash key (dispatch table)
Message-Id: <slrnco3aha.v2q.tadmc@magna.augustmail.com>

Jeff Thies <jeff@spamalanadingong.com> wrote:
> 
>>>   I'm calling a dispatch table:
>>>
>>>my $hashref=\%SOME_HASH;
>>>
>>>if(exists $DISPATCH{modify_hash_key}){
>>>my $sub_ref=$DISPATCH{modify_hash_key};
>>>&$sub_ref($hashref);


BTW: I would much prefer:

   $sub_ref->($hashref);

for code dereferencing or, even "better":

   $DISPATCH{modify_hash_key}->($hashref); # look Ma! No temp variable!


>>>}


>>>### In some external config file


I think I wasn't paying very close attention when I read the OP,
I seem to have missed that line...


>>>$DISPATCH{modify_hash_key}=sub{
>>>my $hashref=shift;
>>>
>>>????
>>>
>>>};
>> 
>> 
>> 
>> That code is not attempting to add/modify a hash key, it is
>> modifying a hash *value*.


Errr, no it isn't. You were just supplying its initial value.

So... never mind.


>> What happened when you tried it?
>> 
>> 
> Well I always take that as I've missed something obvious.


When I use it, it usually means "looks like it should work to me".


> And when I do this:
> 
> $hashref->{new_key}='some_value';
> 
> It does work!
> 
> I think I was doing this:
> 
> my %hash=%$hashref;
> $hash{new_key}='some_value';
> 
> And that doesn't.


Oh, well the OP did not show any hash _copying_ going on...


> I've got a pretty good 50-50 grip on why that is!
                         ^^^^^

No need to settle for... uhh ... half measures, let's go for 100%.

The 2nd one operates on a *copy* of the hash. The copy will get
a new key, but the original hash won't.

Maybe you were looking for the new element in the wrong hash?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 29 Oct 2004 02:04:35 GMT
From: Jeff Thies <jeff@spamalanadingong.com>
Subject: OT: perl errors
Message-Id: <Tyhgd.11063$5i5.2812@newsread2.news.atl.earthlink.net>

   I'm used to doing something like this when I'm debugging scripts:

#!/usr/bin/perl -w

use CGI::Carp 'fatalsToBrowser';

my $a

use NO_MODULE_FOUND;

I would get explicit error messages about the missing semicolon and that 
perl couldn't find the module in @INC.

The web server (perl 5.8, Enterprise Redhat,Apache/2.0.46) I'm running 
now does not throw those nice explicit errors.  What I get now is just a 
plain 500 server error.

This will drive me crazy. Is this an OS issue, an Apache issue or perl 
issue that my nice error messages have flown away?

A fix?

   Jeff


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

Date: Fri, 29 Oct 2004 04:02:45 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: OT: perl errors
Message-Id: <2udnasF28th8fU1@uni-berlin.de>

Jeff Thies wrote:
>   I'm used to doing something like this when I'm debugging scripts:
> 
> #!/usr/bin/perl -w
> 
> use CGI::Carp 'fatalsToBrowser';
> 
> my $a

Does it make a difference if you add a semicolon?

> use NO_MODULE_FOUND;
> 
> I would get explicit error messages about the missing semicolon and that 
> perl couldn't find the module in @INC.
> 
> The web server (perl 5.8, Enterprise Redhat,Apache/2.0.46) I'm running 
> now does not throw those nice explicit errors.  What I get now is just a 
> plain 500 server error.
> 
> This will drive me crazy. Is this an OS issue, an Apache issue or perl 
> issue that my nice error messages have flown away?
> 
> A fix?

Use some other version of CGI::Carp?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 28 Oct 2004 22:33:37 -0400
From: Laura <lwt0301@bellsouth.net>
Subject: Re: OT: perl errors
Message-Id: <10o3b66bhl2au22@news.supernews.com>

Jeff Thies wrote:

>    I'm used to doing something like this when I'm debugging scripts:
> 
> #!/usr/bin/perl -w
> 
> use CGI::Carp 'fatalsToBrowser';
> 
> my $a
> 
> use NO_MODULE_FOUND;
> 
> I would get explicit error messages about the missing semicolon and that
> perl couldn't find the module in @INC.
> 
> The web server (perl 5.8, Enterprise Redhat,Apache/2.0.46) I'm running
> now does not throw those nice explicit errors.  What I get now is just a
> plain 500 server error.

That means that the problem is probably in your HTML and not your Perl
script.  You could look at the server log or try this:  Push your cgi
function statements into an array and then print them out all together. 
This way you can also include a statement to save them to a file and look
at the bad html that led to the 500 error.  How to save an array to file? 
There is a module not included with Perl that you can download that will do
it.  Or just

open FILE, ">htmlerror";
print FILE @html;
close FILE;

I think that's it, not tested and without error checking.

> 
> This will drive me crazy. Is this an OS issue, an Apache issue or perl
> issue that my nice error messages have flown away?
> 
> A fix?
> 
>    Jeff



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

Date: Thu, 28 Oct 2004 22:48:35 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: OT: perl errors
Message-Id: <clsb2j$2md$1@misc-cct.server.rpi.edu>

Laura wrote:
> Jeff Thies wrote:
> 
>>   I'm used to doing something like this when I'm debugging scripts:
>>
>>#!/usr/bin/perl -w
>>
>>use CGI::Carp 'fatalsToBrowser';
>>
>>my $a
>>
>>use NO_MODULE_FOUND;
>>
>>I would get explicit error messages about the missing semicolon and that
>>perl couldn't find the module in @INC.
>>
>>The web server (perl 5.8, Enterprise Redhat,Apache/2.0.46) I'm running
>>now does not throw those nice explicit errors.  What I get now is just a
>>plain 500 server error.
> 
> 
> That means that the problem is probably in your HTML and not your Perl
> script.  

Uhm.  Huh?  What HTML?  The above program didn't generate any HTML at 
all.  Obviously there is 'a problem' with the Perl script - that's the 
whole point.  However, 'the problem' - that is, that the browser is not 
showing the compilation errors - has nothing to do with the Perl script, 
and certainly nothing to do with any non-existent HTML. It has to do 
with either his server configuration and/or the permissions set on the 
file or directory.


> You could look at the server log or try this:  Push your cgi
> function statements into an array and then print them out all together. 
> This way you can also include a statement to save them to a file and look
> at the bad html that led to the 500 error.  

"Bad HTML" does not lead to a 500 error.  This is nonsensical.  A 500 
is, by definition "An Internal Server Error".  There is no HTML 
involved.  Indeed, if the program manages to correctly output HTML, 
chances are the server did not encounter errors executing the program. 
"Bad HTML" will simply cause the browser to not render the webpage 
correctly.

All of this is irrelevant, of course, because again, the program listed 
above did not create any HTML.

The only correct solution to this problem is to view the errors stored 
in the OP's server log.

Paul Lalli


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

Date: Thu, 28 Oct 2004 23:00:41 -0400
From: Laura <lwt0301@bellsouth.net>
Subject: Re: OT: perl errors
Message-Id: <10o3coucordaec3@news.supernews.com>

Paul Lalli wrote:

> Laura wrote:
>> Jeff Thies wrote:
>> 
>>>   I'm used to doing something like this when I'm debugging scripts:
>>>
>>>#!/usr/bin/perl -w
>>>
>>>use CGI::Carp 'fatalsToBrowser';
>>>
>>>my $a
>>>
>>>use NO_MODULE_FOUND;
>>>
>>>I would get explicit error messages about the missing semicolon and that
>>>perl couldn't find the module in @INC.
>>>
>>>The web server (perl 5.8, Enterprise Redhat,Apache/2.0.46) I'm running
>>>now does not throw those nice explicit errors.  What I get now is just a
>>>plain 500 server error.
>> 
>> 
>> That means that the problem is probably in your HTML and not your Perl
>> script.
> 
> Uhm.  Huh?  What HTML?  The above program didn't generate any HTML at
> all.  Obviously there is 'a problem' with the Perl script - that's the
> whole point.  However, 'the problem' - that is, that the browser is not
> showing the compilation errors - has nothing to do with the Perl script,
> and certainly nothing to do with any non-existent HTML. It has to do
> with either his server configuration and/or the permissions set on the
> file or directory.
> 
> 
>> You could look at the server log or try this:  Push your cgi
>> function statements into an array and then print them out all together.
>> This way you can also include a statement to save them to a file and look
>> at the bad html that led to the 500 error.
> 
> "Bad HTML" does not lead to a 500 error.  This is nonsensical.  A 500
> is, by definition "An Internal Server Error".  There is no HTML
> involved.  Indeed, if the program manages to correctly output HTML,
> chances are the server did not encounter errors executing the program.
> "Bad HTML" will simply cause the browser to not render the webpage
> correctly.
> 
> All of this is irrelevant, of course, because again, the program listed
> above did not create any HTML.
> 
> The only correct solution to this problem is to view the errors stored
> in the OP's server log.
> 
> Paul Lalli

Oh, I assumed that maybe he cut out some CGI.pm generated HTML.  I may be
wrong, but I think that if the header is not formed properly, you can get
the 500 internal server error.  For example, if you forget:

print header();

and then you print anything at all in a cgi program, the server may have a
problem with the header being absent or wrong.  I am only proposing this as
a possibility because I had the same exact problem when I tried to do my
header by hand and when I went with header(), the 500 error went away.



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

Date: Thu, 28 Oct 2004 22:53:07 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: OT: perl errors
Message-Id: <lgigd.21505$Qs6.1634845@news20.bellglobal.com>


"Laura" <lwt0301@bellsouth.net> wrote in message 
news:10o3b66bhl2au22@news.supernews.com...
> Jeff Thies wrote:
>
>>
>> The web server (perl 5.8, Enterprise Redhat,Apache/2.0.46) I'm running
>> now does not throw those nice explicit errors.  What I get now is just a
>> plain 500 server error.
>
> That means that the problem is probably in your HTML and not your Perl
> script.

Huh?!?

Matt 




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

Date: Thu, 28 Oct 2004 21:15:36 -0400
From: Sparky <tyates@newsguy.com>
Subject: PERL 64bit Question
Message-Id: <i563o0hk1egdcr5gvm9c8vgjk4ntkstfrk@4ax.com>

I've compiled PERL 5.8.2 on AIX 5.1 64bit, I think.  Can someone tell
me for sure from this output.  The questions I have are, how is it
possible, if this is in fact compiled as 64bit, that I can execute it
on a 32bit AIX 5.1 system?  Other programs I've used would fail with
an error.  How does one tell exactly that is compiled for 64bit from
this output.

 ./perl -Ilib -V

Summary of my perl5 (revision 5.0 version 8 subversion 2)
configuration:
  Platform:
    osname=aix, osvers=5.1.0.0, archname=aix-64int-ld
    uname='aix s11f30n01 1 5 0029449a4c00 '
    config_args='-Duse64bitint -Duselongdouble
-Aprepend:libswanted=C128 '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=define
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc -qnolm', ccflags ='-D_ALL_SOURCE -D_ANSI_C_SOURCE
-D_POSIX_SOURCE -qmaxmem=16384 -qnoansialias -qlongdouble
-DUSE_NATIVE_DLOPEN -q32 -D_LARGE_FILES -qlonglong',
    optimize='-O',
    cppflags=''
    ccversion='6.0.0.0', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=87654321
    d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=16
    ivtype='long long', ivsize=8, nvtype='long double', nvsize=16,
Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='ld', ldflags =' -brtl -L/usr/local/lib -b32'
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lC128 -lc128 -lbind -lnsl -ldbm -ldl -lld -lm -lcrypt -lc
-lbsd
    perllibs=-lC128 -lc128 -lbind -lnsl -ldl -lld -lm -lcrypt -lc
-lbsd
    libc=/lib/libc.a, so=a, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_aix.xs, dlext=so, d_dlsymun=undef, ccdlflags='
-bE:/gpfs/database/dba/utilities/perl582/lib/5.8.2
/aix-64int-ld/CORE/perl.exp'
    cccdlflags=' ', lddlflags=' -bhalt:4 -bM:SRE
-bI:$(PERL_INC)/perl.exp
-bE:$(BASEEXT).exp -bnoentry -lc128 -lc  -L/usr/local/lib'

Characteristics of this binary (from libperl):
  Compile-time options: USE_64_BIT_INT USE_LONG_DOUBLE USE_LARGE_FILES
  Built under aix
  Compiled at Oct 28 2004 15:32:11
  @INC:
    lib
    /gpfs/database/dba/utilities/perl582/lib/5.8.2/aix-64int-ld
    /gpfs/database/dba/utilities/perl582/lib/5.8.2

/gpfs/database/dba/utilities/perl582/lib/site_perl/5.8.2/aix-64int-ld
    /gpfs/database/dba/utilities/perl582/lib/site_perl/5.8.2
    /gpfs/database/dba/utilities/perl582/lib/site_perl
    .


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

Date: Thu, 28 Oct 2004 22:12:43 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: perl errors
Message-Id: <uGhgd.21100$Qs6.1617385@news20.bellglobal.com>


"Jeff Thies" <jeff@spamalanadingong.com> wrote in message 
news:Tyhgd.11063$5i5.2812@newsread2.news.atl.earthlink.net...
>   I'm used to doing something like this when I'm debugging scripts:
>
> #!/usr/bin/perl -w
>
> use CGI::Carp 'fatalsToBrowser';
>
> my $a
>
> use NO_MODULE_FOUND;
>
> I would get explicit error messages about the missing semicolon and that 
> perl couldn't find the module in @INC.
>
> The web server (perl 5.8, Enterprise Redhat,Apache/2.0.46) I'm running now 
> does not throw those nice explicit errors.  What I get now is just a plain 
> 500 server error.
>

What does it say in the Apache error log when this happens? There could be 
any number of reasons why you're not getting the errors, but I expect the 
log will be more helpful in diagnosing the problem than anyone here can be.

Matt 




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

Date: Fri, 29 Oct 2004 03:25:00 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: print FILE function()
Message-Id: <2udl35F28rpadU1@uni-berlin.de>

Eric Bohlman wrote:
> Gunnar Hjalmarsson wrote: 
>>
>>     sub hdump {
>>         my $offset;
>>         for (1..3) {
>>             $offset += 5;
>>         }
>>     };
>>
>>     print '[', hdump(), "]\n";
>>
>> Outputs:
>> []
> 
> Hmmm.  *Why* this behavior?  It doesn't strike me as consistent with the 
> documentation in perlsub:
> 
> The return value of a subroutine is the value of the last expression 
> evaluated by that sub, ...

Does it really have anything to do with the behaviour of the sub? Isn't 
it rather about what a foreach loop 'returns' (which appears to be - 
accidentally or not - the null string)?

     my $ret = do { for (()) {} };
     print "null\n" if defined $ret and $ret eq '';

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 28 Oct 2004 20:15:50 -0600
From: Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com>
Subject: Re: print FILE function()
Message-Id: <10o39umgnva84e9@corp.supernews.com>

Gunnar Hjalmarsson wrote:

> Does it really have anything to do with the behaviour of the sub? Isn't 
> it rather about what a foreach loop 'returns' (which appears to be - 
> accidentally or not - the null string)?
> 
>     my $ret = do { for (()) {} };
>     print "null\n" if defined $ret and $ret eq '';
> 

Hey thanks for all your help - you folks are a blast. I've only been a 
this Perl/perl (?) thing two days now and I'm quite enjoying it.

Here's how I solved the problem by changing the second-to-last line of 
the sub:
printf FILE $format,$offset,$offset,@array,$data;

I appreciate the troubleshooting tips some of you gave too, thanks.

Caleb


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

Date: 29 Oct 2004 02:42:21 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: print FILE function()
Message-Id: <Xns9590E6FA68586asu1cornelledu@132.236.56.8>

Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com> wrote in news:10o39umgnva84e9
@corp.supernews.com:

> Here's how I solved the problem by changing the second-to-last line of 
> the sub:
> printf FILE $format,$offset,$offset,@array,$data;

You should not do that because now you have made the subroutine depend on 
global data.

Instead, do this (untested):

my $path = '/path/to/file';
open my $file, '<', $path or die "Cannot open $path: $!";

dump_to_file($file);
 ...

sub dump_to_file {
   my ($output) = @_;
   ...
   print $output "....";
}

This achieves two things: First, notice the my and $ sign in front of the 
file handle in the open statement. That way, the filehandle is limited to 
the lexical scope in which it is created instead of living in the global 
namespace. 

Second, the subroutine is now independent of the code it is calling it. 
This way, you can reuse the hexdump routine later (say, by putting it in a 
module or something). See also Paul Lalli's response 
(news:clrrgk$18n$1@misc-cct.server.rpi.edu) in this thread.

Sinan.

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Thu, 28 Oct 2004 22:43:31 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: print FILE function()
Message-Id: <clsap4$2lv$1@misc-cct.server.rpi.edu>

Spin wrote:

> I've only been at this Perl/perl (?) thing 

I'm taking this to be a question.  In fact, I'm taking it to be a 
Frequently Asked Question:

perldoc -q difference
What's the difference between "perl" and "Perl"?

You should probably read the whole answer given, but to boil it down:
Perl is the language.
perl is the interpreter - that is, the executable program that runs your 
Perl script.

Paul Lalli


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

Date: 28 Oct 2004 19:21:52 -0700
From: eight02645999@yahoo.com (justme)
Subject: returning from Net::Telnet cmd
Message-Id: <c0837966.0410281821.63cea262@posting.google.com>

hi

i have a question regarding the usage of Net::Telnet cmd.
here is some of my code
use Net::Telnet;
$key = <STDIN>;
$dir = '/home';
chomp($key);
my $telnet = Net::Telnet-> new
(      Timeout => 30,
       Prompt=>'server#'                                              
                           );                                         
                $telnet->open("$telnetserver");                       
                                                 $telnet->
login($login,$pass);
my @listing = $telnet-> cmd("cd $dir;/usr/bin/grep '$key' *");
$telnet->close;                                                       
                     print "@listing\n";

here is my situation. in $dir, there are many text files, as much as
8000 files.
and i need to grep for $key in every file. sometimes i can get the
results
if the grep results is small. Otherwise, no results will be output if
the grep is big.
Anyway i can work around this or is there something i miss in the
code?. Is it better print to screen as the cmd executes using a while
loop? any suggestions is greatly appreciated thanks..


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

Date: Thu, 28 Oct 2004 20:17:40 -0400
From: Fred <noemail@#$&&!.net>
Subject: using Win32::ODBC - what's fast?
Message-Id: <pan.2004.10.29.00.17.40.139861@#$&&!.net>

I have these subs... init_sku_lookup() takes 20 seconds to run on a
pentium IV... when done it has 70k sku numbers in it. It's coded the way
it is so that it only gets unique values. The other sub check_for_sku()
runs like instantly. And I call it before I build an add record for an
item. (If the sku is on file we don't build the add record.) So I guess I
was wondering if there was any way to speed up init_sku_lookup(). Critism
is welcome. I'm processing 70k items and a call to init_sku_lookup() for
each one would be insane. So I build the hash and depend on perl's
'exists' to do the fast work. But I wonder..... I don't tknow the
internals of Win32::ODBC but I wish I could just slurp the whole record
set..... did I mention I ask myself about every 30 minutes... "Do you
really know what your doing here?"

TIA
Fred



sub init_sku_lookup() {
    %skuhash;
    $db = new Win32::ODBC("sg") || die "Error: " . Win32::ODBC::Error();
    if ( !$db->Sql("SELECT DISTINCT SKU_tbl.sku from SKU_tbl") ) {
        while ( $db->FetchRow() )    # iterate over the data set {
            $val = $db->Data();

            # load file values into hash
            $skuhash{$val} = $val;
        }
    }
    $db->Close();
}

sub check_for_sku() {

    if ( exists $skuhash{ $Fld[11] } ) {
        return 0;    # it's true! it did exist
    }
    else {
        return 1;    # it was not there so build the add record
    }

}


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

Date: Thu, 28 Oct 2004 22:30:14 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: using Win32::ODBC - what's fast?
Message-Id: <UWhgd.21292$Qs6.1623780@news20.bellglobal.com>


"Fred" <noemail@#$&&!.net> wrote in message 
news:pan.2004.10.29.00.17.40.139861@%23$&&!.net...
>I have these subs... init_sku_lookup() takes 20 seconds to run on a
> pentium IV... when done it has 70k sku numbers in it.
>

Are all your tables indexed on the select column to maximize for speed?

>  It's coded the way
> it is so that it only gets unique values. The other sub check_for_sku()
> runs like instantly. And I call it before I build an add record for an
> item. (If the sku is on file we don't build the add record.) So I guess I
> was wondering if there was any way to speed up init_sku_lookup().

Why are you reading all 70,000 unique ids into memory? It would be faster 
just to execute a select statement each time you need to check if an sku 
already exists. I've never used the Win32::ODBC module, but if you were 
using the DBD driver you could just check whether the unit id exists like 
so: (untested)

sub check_exists {

   my ($tid, $unitid) = @_;

   my $sel_sth = $dbh->prepare("SELECT sku from $tid WHERE sku = ?") or die 
$dbh->errstr();

   $sel_sth->execute($unitid) or die $dbh->errstr();

   if ($sel_sth->fetchrow_array) {
      $sel_sth->finish();
      return 1;
   }

   return 0;

}

Remember that most of the overhead involved in database access is in setting 
up the connection. Once you have that connection, querying the database 
should be very fast (assuming your data is well structured and indexed).

Matt 




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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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.

#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 V10 Issue 7336
***************************************


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