[26832] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8861 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 17 21:05:20 2006

Date: Tue, 17 Jan 2006 18:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 17 Jan 2006     Volume: 10 Number: 8861

Today's topics:
    Re: ExpatXS: 'Can't call method "read" on an undefined  <nomail@sorry.com>
    Re: ExpatXS: 'Can't call method "read" on an undefined  <nospam-abuse@ilyaz.org>
    Re: FAQ 3.5 How do I debug my Perl programs? <jgibson@mail.arc.nasa.gov>
    Re: FAQ 3.5 How do I debug my Perl programs? <matthew.garrish@sympatico.ca>
    Re: FAQ 3.5 How do I debug my Perl programs? <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: FAQ 3.5 How do I debug my Perl programs? <astewart1@cox.net>
    Re: FAQ 3.5 How do I debug my Perl programs? xhoster@gmail.com
    Re: Scanning file version 2.0 <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: Search Question <kigar@gmx.net>
        searching alltheweb via www::search <nospam@home.com>
    Re: searching alltheweb via www::search <ebohlman@omsdev.com>
    Re: searching alltheweb via www::search <nospam@home.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 17 Jan 2006 13:26:06 -0800
From: Arvin Portlock <nomail@sorry.com>
Subject: Re: ExpatXS: 'Can't call method "read" on an undefined value' after ca. 500 XML files
Message-Id: <dqjnde$1pbo$1@agate.berkeley.edu>

xhoster@gmail.com wrote:

> Arvin Portlock  wrote:
>
> > >>>In using ExpatXS to parse large batches of XML files
> > >>>something curious happens. After parsing something close
> > >>>to 500 files the program crashes with the error:
> > >>>
> > >>>Can't call method "read" on an undefined value at
> > >>>/xxx/perl5.8/lib/site_perl/5.8.7/sun4-solaris-thread-multi/
> > >>>XML/SAX/ExpatXS.pm line 155.
> >
> > >xhoster@gmail.com wrote:
> > >I've now tried your program with this exact version of ExpatXS.pm, and
> > >it also works for at least 10_000 files.
> >
> >So I made one change to ExpatXS.pm which worked. I explicitly
> >closed $fh here:
> >
> >sub _parse_systemid {
> >     my $self = shift;
> >     my $fh = IO::File->new(shift);
> >     $self->{ParseOptions}->{ParseFunc} = \&ParseStream;
> >     $self->{ParseOptions}->{ParseFuncParam} = $fh;
> >     $self->_parse;
> >     $fh->close;
> >}
>
>
> I think you would be better off changing the 3rd line to:
>
> my $fh = IO::File->new(shift) or die ("file open failed with !=$! and
> \@=$@");
>
> And seeing exactly what the problem is.  That might lead you to a better
> way to fix it.  (or it might not...)  (maybe croak rather than die)

The error is as expected, that no more file handles are available.
For now I'll leave the $fh->close, but I want to test it when I have
some time with some XML documents that include external entities.
Not sure how Expat deals with those internally. Perhaps it leaves
unfinished files open while it hunts down entity files, maybe it
closes them first then opens them again where it left off. The former
seems a bit faster but not as safe, e.g., lots of external entity
files = run out of file handles at some point. But in any case I
want to make sure I'm not forcing a file to be closed before Expat
is good and ready. That's why a $parser destructor seems safest
in light of not knowing enough about what's going on. I suppose
I could store the files handles in a static array variable in
_parse_systemid then loop through and close them all upon destruction.

Arvin



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

Date: Wed, 18 Jan 2006 01:18:49 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: ExpatXS: 'Can't call method "read" on an undefined value' after ca. 500 XML files
Message-Id: <dqk51p$1tbh$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Arvin Portlock 
<nomail@sorry.com>], who wrote in article <dqgvvg$10ek$1@agate.berkeley.edu>:
> sub _parse_systemid {
>      my $self = shift;
>      my $fh = IO::File->new(shift);
>      $self->{ParseOptions}->{ParseFunc} = \&ParseStream;
>      $self->{ParseOptions}->{ParseFuncParam} = $fh;
>      $self->_parse;
>      $fh->close;
> }

What happens if you apply `local' to assignments to ParseOptions?
There is a leak, and it makes sense to plug the leak as high in the
chain as possible.

What is the lifetime of $self, BTW?

Puzzled,
Ilya


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

Date: Tue, 17 Jan 2006 15:27:36 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: FAQ 3.5 How do I debug my Perl programs?
Message-Id: <170120061527364488%jgibson@mail.arc.nasa.gov>

In article <dqbvv4$ps$1@reader2.panix.com>, PerlFAQ Server
<comdog@pair.com> wrote:

> 
> 3.5: How do I debug my Perl programs?
> 

[5 good suggestions snipped]

   Use the print statement.

(Seems like facetious or obvious advice, but there are a significant
number of problems posted to clpm that could be solved with the
judicious use of the print statement, e.g. forgetting to chomp a line
read from a <>. My guess is that more programmers use the print
statement and its brethren printf and warn than use the Perl debugger.)

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Tue, 17 Jan 2006 19:06:00 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: FAQ 3.5 How do I debug my Perl programs?
Message-Id: <DDfzf.13314$xk1.278688@news20.bellglobal.com>


"Jim Gibson" <jgibson@mail.arc.nasa.gov> wrote in message 
news:170120061527364488%jgibson@mail.arc.nasa.gov...
> In article <dqbvv4$ps$1@reader2.panix.com>, PerlFAQ Server
> <comdog@pair.com> wrote:
>
>>
>> 3.5: How do I debug my Perl programs?
>>
>
> [5 good suggestions snipped]
>
>   Use the print statement.
>
> (Seems like facetious or obvious advice, but there are a significant
> number of problems posted to clpm that could be solved with the
> judicious use of the print statement, e.g. forgetting to chomp a line
> read from a <>. My guess is that more programmers use the print
> statement and its brethren printf and warn than use the Perl debugger.)
>

I agree completely with you. I tried the debugger a few times when I first 
started with Perl, found it rather useless and never went back. Strictures 
and warnings are enough to cover syntax problems and a few prints in the 
logical spots has served me well debugging the final output.

It's not a debugging technique that is particular to Perl, however, and it's 
probably not something that a programmer needs to be told in the 
documentation, hence I would assume its exclusion.

Matt 




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

Date: Tue, 17 Jan 2006 16:47:05 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: FAQ 3.5 How do I debug my Perl programs?
Message-Id: <9pf0a3xibm.ln2@goaway.wombat.san-francisco.ca.us>

On 2006-01-17, Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
> In article <dqbvv4$ps$1@reader2.panix.com>, PerlFAQ Server
><comdog@pair.com> wrote:
>
>> 
>> 3.5: How do I debug my Perl programs?
>
>    Use the print statement.

Recently I've tended to use warn instead of print.  This is helpful if
your ''normal'' output is supposed to go to stdout (which, for the most
part, mine is).

--keith


-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
see X- headers for PGP signature information



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

Date: Tue, 17 Jan 2006 17:04:24 -0800
From: Alan Stewart <astewart1@cox.net>
Subject: Re: FAQ 3.5 How do I debug my Perl programs?
Message-Id: <or4rs1t96mcne8uu1dccm6o9tk2mjjoc6u@4ax.com>

On Tue, 17 Jan 2006 19:06:00 -0500, "Matt Garrish"
<matthew.garrish@sympatico.ca> wrote:

>
>"Jim Gibson" <jgibson@mail.arc.nasa.gov> wrote in message 
>news:170120061527364488%jgibson@mail.arc.nasa.gov...
>> In article <dqbvv4$ps$1@reader2.panix.com>, PerlFAQ Server
>> <comdog@pair.com> wrote:
>>
>>>
>>> 3.5: How do I debug my Perl programs?
>>>
>>
>> [5 good suggestions snipped]
>>
>>   Use the print statement.
>>
>> (Seems like facetious or obvious advice, but there are a significant
>> number of problems posted to clpm that could be solved with the
>> judicious use of the print statement, e.g. forgetting to chomp a line
>> read from a <>. My guess is that more programmers use the print
>> statement and its brethren printf and warn than use the Perl debugger.)
>>
>
>I agree completely with you. I tried the debugger a few times when I first 
>started with Perl, found it rather useless and never went back. Strictures 

or how about Devel::ptkdb for a visual debugger . . .

>and warnings are enough to cover syntax problems and a few prints in the 
>logical spots has served me well debugging the final output.
>
>It's not a debugging technique that is particular to Perl, however, and it's 
>probably not something that a programmer needs to be told in the 
>documentation, hence I would assume its exclusion.
>
>Matt 
>

or Smart::Comments for a high powered "print" method that is Perl
unique (source filtering).

Alan


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

Date: 18 Jan 2006 01:55:48 GMT
From: xhoster@gmail.com
Subject: Re: FAQ 3.5 How do I debug my Perl programs?
Message-Id: <20060117205548.955$A8@newsreader.com>

Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
> In article <dqbvv4$ps$1@reader2.panix.com>, PerlFAQ Server
> <comdog@pair.com> wrote:
>
> >
> > 3.5: How do I debug my Perl programs?
> >
>
> [5 good suggestions snipped]
>
>    Use the print statement.

I would usually suggest warn rather than print.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 17 Jan 2006 20:45:40 +0100
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Scanning file version 2.0
Message-Id: <43cd496a$0$29206$8fcfb975@news.wanadoo.fr>

Anton van der Steen wrote:
> Hey guys,
> 
> Here is version 2.0 for scanning files.
> I have added scrollbars to the text area and a function
> to print OUT the result to a other file.
> Below you will find the script.
> 
> I have tested it with Perl 5.8.6 from ActiveState.com,
> bear this in mind.
> 
> Have fun.
> 
er, great: a GUI for grep. A few points:

> Anton van der Steen, another perl addict
> Eindhoven/The Netherlands/Europe
> 
> 
> #!/perl/bin/perl
> #Dit programma is geschreven door Anton van der Steen
> #Email adres: anton.vandersteen@chello.nl
> use Tk;
> 
you need

use strict;
use warnings;


> my $mw = new MainWindow; # Main Window
> $mw->title("Search Engine  Version 2.0  by Stone Logic Systems");
> 
> my $frm_name = $mw -> Frame() -> pack();
> 
> 
> my $lab1 = $frm_name -> Label(-text=>"Phrase :", -font => 
> '-adobe-helvetica-bold-r-normal--11-120-75-75-p-70-*
> 
> -1') -> pack();
> my $ent1 = $frm_name -> Entry(-width=>100, -borderwidth=>2
> ) -> pack();
> $ent1->configure(-font => 
> '-adobe-helvetica-bold-r-normal--11-120-75-75-p-70-*-1');
> 
> 
> my $lab2=$frm_name->Label(-text=>"Search in File :", -font => 
> '-adobe-helvetica-bold-r-normal--11-120-75-75-p-
> 
> 70-*-1')->pack();
> 
> my $ent2=$frm_name->Entry(-width=>100)->pack();
> $ent2->configure(-font => 
> '-adobe-helvetica-bold-r-normal--11-120-75-75-p-70-*-1');
> 
<snip>
Shouldn't some of this be done in config? You've hardcoded the font name 
10 times, for instance.

<snip>

> sub push_button1 {
> 
>  use Getopt::Std;
Put this at the top of the file.  Lines like

use Blah;

are executed at compile time, not runtime.

> 
>  my $name1 = $ent1 -> get();
>  my $name2 = $ent2 -> get();
>  @ARGV= ($name1, $name2);

I wouldn't use @ARGV for this. It has a special meaning (ie command-line 
arguments) in perl. Using it here doesn't hurt as such, but it's misleading.

>  #print @ARGV;
> 
>  $i=0;
> 
>  my $pattern = shift @ARGV;
> 
> 
>  foreach $file (@ARGV)
>  {
>  open (FILE, $file);

You need to check the return value of open. Here, if the open fails, the 
fact isn't reported to the user and then the tool gives misleading results.

Can you not define a file-browse dialog for specifying the filename?


>  print "The phrase $pattern is $i times found!!\n";

You've written a GUI tool, but you're printing to the console. A little odd.

> sub push_button2 {
> 
>  use Getopt::Std;
You've already done this: no need to do it again.

> 
>  my $name1 = $ent1 -> get();
>  my $name2 = $ent2 -> get();
>  @ARGV= ($name1, $name2);
> 
>  $i=0;
> 
>  my $pattern = shift @ARGV;
> 
> 
>  foreach $file (@ARGV)
>  {
>  open (FILE, $file);
>  while ($line = <FILE>)
>  {
>   if ($line =~m"$pattern")
>  {
>   $i++;
>   last if ($opt_1);
>   $txt-> insert ('end', "$line\n");
>   print "$line\n";
> 
>  }
This code looks familiar...... You've copied and pasted it from 
push_button1. You should break the common code out into another 
subroutine, that returns eg an array containing matching lines. 
push_button1 (not a very descriptive name) can then display the matching 
lines, and push_button2 can display a count.


> sub push_button4 {
> 
>  use Getopt::Std;
> 
>  my $name1 = $ent1 -> get();
>  my $name2 = $ent2 -> get();
>  my $file_out = $ent3 -> get();
> 

and again.....

Copy-and-paste is not a useful programming paradigm.

Mark


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

Date: Tue, 17 Jan 2006 20:58:05 +0100
From: "Reinhard Glauber" <kigar@gmx.net>
Subject: Re: Search Question
Message-Id: <43cd4c52$0$21022$9b4e6d93@newsread2.arcor-online.net>

DQo+ID4gDQo+ID4gYnV0IHdoYXQgbWVhbnMgKD86LipcbikNCj4gDQo+IFllcywgaG93IHJ1ZGUg
b2YgeW91LCBEci4gUnV1ZCwgdG8gbm90IHRob3JvdWdobHkgZXhwbGFpbiBldmVyeSBkZXRhaWwg
DQo+IG9mIHRoZSBleHByZXNzaW9uIHlvdSBwb3N0ZWQhIQ0KPiANCj4gLS0gDQo+IEd1bm5hciBI
amFsbWFyc3Nvbg0KPiBFbWFpbDogaHR0cDovL3d3dy5ndW5uYXIuY2MvY2dpLWJpbi9jb250YWN0
LnBsDQoNCg0KDQpzb3JyeSwgSSdtIGEgUGVybCBuZXdiaWUNCklzIHRoaXMgTmV3c2dyb3VwIGp1
c3QgZm9yIHRoZSBFbGl0ZSA/DQpTb3JyeSBpZiBJIGRpc3R1cmJlZCB5b3UgOy0pKQ==



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

Date: Tue, 17 Jan 2006 22:01:19 GMT
From: "Nospam" <nospam@home.com>
Subject: searching alltheweb via www::search
Message-Id: <POdzf.1464$mf2.439@newsfe6-win.ntli.net>

I am trying to do a search via the www::search module using alltheweb as the
search engine
however I am trying to do the search in polish, which is specified as l=pl
in the query string
however the query doesn't go through, any help would be greatly appreciated

#! Perl\bin\perl;

use WWW::Search;



my $language_code="l=pl";

$query = ``search'';

 $search = new WWW::Search('AlltheWeb', restrict => $language_code);
 $search->native_query(WWW::Search::escape_query($query));
$search->maximum_to_retrieve(100);

  while (my $result = $search->next_result()) {

$url = $result->url; $title = $result->title; $desc = $result->description;


print $result->url, "\n";


print ``<a href=$url>$title</a> $source<br>$date<br>$desc<p>\n'';

}




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

Date: 17 Jan 2006 22:25:46 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: searching alltheweb via www::search
Message-Id: <Xns974EA6E07606ebohlmanomsdevcom@130.133.1.4>

"Nospam" <nospam@home.com> wrote in
news:POdzf.1464$mf2.439@newsfe6-win.ntli.net: 

> I am trying to do a search via the www::search module using alltheweb
> as the search engine
> however I am trying to do the search in polish, which is specified as
> l=pl in the query string
> however the query doesn't go through, any help would be greatly
> appreciated 
> 
> #! Perl\bin\perl;

You *need*

use strict;
use warnings;

here!!

> 
> use WWW::Search;
> 
> 
> 
> my $language_code="l=pl";
> 
> $query = ``search'';

You're not posting your real code: that line won't compile.

> 
>  $search = new WWW::Search('AlltheWeb', restrict => $language_code);
>  $search->native_query(WWW::Search::escape_query($query));
> $search->maximum_to_retrieve(100);
> 
>   while (my $result = $search->next_result()) {
> 
> $url = $result->url; $title = $result->title; $desc =
> $result->description; 
> 
> 
> print $result->url, "\n";
> 
> 
> print ``<a href=$url>$title</a> $source<br>$date<br>$desc<p>\n'';

This line won't compile either.

> 
> }

Please read the Posting Guidelines for this group, paying particular 
attention to the parts about not retyping code and asking perl for all 
the help it can give you.


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

Date: Tue, 17 Jan 2006 23:03:11 GMT
From: "Nospam" <nospam@home.com>
Subject: Re: searching alltheweb via www::search
Message-Id: <PIezf.40051$q4.40047@newsfe2-gui.ntli.net>

I have amended the code, I am not sure of how to add the restrict value that
says l=pl : that the language is polish in .$search = new
WWW::Search('AlltheWeb', restrict => $language_code);

I am not sure if this is the right place, it does say useless use of a
constant in void context.

#! Perl\bin\perl;

use WWW::Search;
use strict;
use warnings;


my $language_code="l=pl";

my $query = "Telewizja kanal";

 $search = new WWW::Search('AlltheWeb', restrict => $language_code);
 $search->native_query(WWW::Search::escape_query($query));
$search->maximum_to_retrieve(100);

  while (my $result = $search->next_result()) {

my $url = $result->url; my $title = $result->title; my $desc =
$result->description;


print $result->url, "\n";


print "<a href=$url>$title</a> $source<br>$date<br>$desc<p>\n";

}




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

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


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