[26859] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8874 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 21 14:05:18 2006

Date: Sat, 21 Jan 2006 11:05:05 -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           Sat, 21 Jan 2006     Volume: 10 Number: 8874

Today's topics:
        amending the search result criteria for google api <nospam@home.com>
    Re: Cleaning HTML ;-) <1usa@llenroc.ude.invalid>
        crash in regex with encoding utf8 <VJBDONFBFOPG@spammotel.com>
    Re: crash in regex with encoding utf8 <flavell@ph.gla.ac.uk>
        getpwent performance <ruby@no.spam>
    Re: Matching subsets of two strings <jweeb2342@hotmail.com>
    Re: Matching subsets of two strings <1usa@llenroc.ude.invalid>
    Re: Matching subsets of two strings <jurgenex@hotmail.com>
    Re: mistake in my for <tadmc@augustmail.com>
        Simple REGEX-Question  <kigar@gmx.net>
        Using scalar instead of stream <NoSPam@NoSpam.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 21 Jan 2006 16:35:34 GMT
From: "Nospam" <nospam@home.com>
Subject: amending the search result criteria for google api
Message-Id: <qptAf.8172$mf2.6598@newsfe6-win.ntli.net>

#! Perl\bin\perl -w

# GoogleSearch.pl
# 11apr2002 - matt@interconnected.org http://interconnected.org/home/
# Demonstrates use of the doGoogleSearch method on the Google API.
# See http://www.google.com/apis/ to get your key and download the WSDL
#(which this script expects to find in its directory).

use strict;
use SOAP::Lite;

# Configuration
my $key   = "XXXXXXXXXX"; # <-- PUT YOUR KEY HERE
my $query = '"fuera"';


# Redefine how the default deserializer handles booleans.
# Workaround because the 1999 schema implementation incorrectly doesn't
# accept "true" and "false" for boolean values.
# See http://groups.yahoo.com/group/soaplite/message/895
*SOAP::XMLSchema1999::Deserializer::as_boolean =
    *SOAP::XMLSchemaSOAP1_1::Deserializer::as_boolean =
    \&SOAP::XMLSchema2001::Deserializer::as_boolean;

# Initialise with local SOAP::Lite file
my $service = SOAP::Lite
    -> service('file:c:/Perl/bin/GoogleSearch.wsdl');

my $result = $service
    -> doGoogleSearch(
                      $key,                               # key
                      $query,                             # search query
                      0,                                  # start results
this
                                                            #the field I am
#having problems
#with
                      10,                                  # max results
                      "false",                            # filter: boolean
                      "countryES",                                 #
restrict (string)
                      "false",                            # safeSearch:
boolean
                      "lang_es",                                 # lr
                      "latin1",                           # ie
                      "latin1"                            # oe
                      );

# $result is hash of the return structure. Each result is an element in the
# array keyed by 'resultElements'. See the WSDL for more details.
for($start_result=1; $start_result<2; $start_result++){

if(defined($result->{resultElements})) {

    my @results = @{$result->{resultElements}};
    my $res;
    foreach $res (@results) {
           print "adding: ", $res->{URL}, "\n";
      print  $res->{URL} . "\n";
    }

}

}

I am trying to amend the start results field into a loop, I understand that
you limited to 1000 results per day from the google api, however the prog
will not work if I amend the start results criteria to anything above 10.




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

Date: Sat, 21 Jan 2006 15:58:32 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Cleaning HTML ;-)
Message-Id: <Xns97526FB76EBF8asu1cornelledu@127.0.0.1>

"Reinhard Glauber" <kigar@gmx.net> wrote in
news:43d1fcbf$0$20788$9b4e6d93@newsread4.arcor-online.net: 

> I need to clean a HTML file, so that I get plain text.

Use a parser to parse HTML, as the answer to the FAQ recommends:

  How do I remove HTML from a string?
    The most correct way (albeit not the fastest) is to use HTML::Parser
    from CPAN.

See http://search.cpan.org/~gaas/HTML-Parser-3.48/, especially:

http://search.cpan.org/src/GAAS/HTML-Parser-3.48/eg/htext

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

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: Sat, 21 Jan 2006 16:59:03 +0100
From: Christian Eyrich <VJBDONFBFOPG@spammotel.com>
Subject: crash in regex with encoding utf8
Message-Id: <dqtlmp$h00$1@news1.nefonline.de>

Hello,

I'm having a problem where perl crashes while doing a regex.
The following is a very very simplified version of the original code and
without any real functionality, but it still exhibits the problem.

Two parameters trigger the crash if they're both present:
1. use encoding is set
2. a variable containing input (originally data from a database, but a
simple textfile here) is used in the regular expression

Here's my code:

#!/usr/bin/perl -w

use strict;
use encoding 'iso 8859-1';

open(INPUTFILE, "namelist_latin1.txt")
	or die "Can't open inputfile: $!";

while (<INPUTFILE>)
{
	my $text = 'Dummytext';
	$text =~ /$_/;
}

close INPUTFILE;


This crashes with Active Perl 5.8.7 on Win2K and Perl 5.8.4 on Linux. Is
there something I'm missing about use encoding?

It might be problematic to reproduce the crash with few input data or
maybe the wrong kind. I uploaded testdata here
http://chey.gmxhome.de/namelist_latin1.txt.gz (3,8 KB). It contains
umlauts and is ISO-8859-1 coded. I also get it with utf8 data (using use
open ':utf8'; and use encoding 'utf8';)

Regards,
Christian


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

Date: Sat, 21 Jan 2006 16:41:48 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: crash in regex with encoding utf8
Message-Id: <Pine.LNX.4.62.0601211622010.30341@ppepc70.ph.gla.ac.uk>

On Sat, 21 Jan 2006, Christian Eyrich wrote:

[problems if...]
> 1. use encoding is set
> 2. a variable containing input (originally data from a database, but 
> a simple textfile here) is used in the regular expression

[...]

> use encoding 'iso 8859-1';

The official form of that encoding seems to be 'iso-8859-1': some 
alternatives might be tolerated, but I'd recommend sticking to the one 
shown in the documentation examples.

> open(INPUTFILE, "namelist_latin1.txt")
> 	or die "Can't open inputfile: $!";

I'm not quite sure if this is what you really intend.  Take a look at 
http://perldoc.perl.org/encoding.html

The primary purpose of "use encoding" is to allow you to include
a particular encoding of characters /in your Perl source code/.

It may also (subject to a few ifs and buts) have the effect of 
opening STDIN and STDOUT with that encoding.

But you're not dealing with STDIN or STDOUT here.  If you want your 
data file (INPUTFILE) to be opened for that encoding, you need to 
say so when you open it - or use the appropriate form of binmode().

does that help?


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

Date: Sat, 21 Jan 2006 19:25:54 +0100
From: Michal Kwiatkowski <ruby@no.spam>
Subject: getpwent performance
Message-Id: <dqtu9l$358$1@news.onet.pl>

Hi,

Please look at the following code:

sub get_current_uids {
    my(@uids, $uid);
    setpwent;
    push @uids, $uid while defined($uid = (getpwent)[2]);
    endpwent;
    return @uids;
}

&get_current_uids;

On systems with considerably large /etc/shadow and /etc/passwd files
(about 10.000 entries) it takes very long time to execute. Stracing it
shows really long loop of intructions quoted below:

open("/etc/shadow", O_RDONLY)           = 4
fcntl64(4, F_GETFD)                     = 0
fcntl64(4, F_SETFD, FD_CLOEXEC)         = 0
_llseek(4, 0, [0], SEEK_CUR)            = 0
fstat64(4, {st_mode=S_IFREG|0640, st_size=1538953, ...}) = 0
fstat64(4, {st_mode=S_IFREG|0640, st_size=1538953, ...}) = 0
mmap2(NULL, 131072, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb7d09000
read(4, "root:$1$uUu3dni5$qztZJWVijz2SQGv"..., 131072) = 131072
close(4)                                = 0
munmap(0xb7d09000, 131072)              = 0
open("/etc/shadow", O_RDONLY)           = 4
fcntl64(4, F_GETFD)                     = 0
    etc.....

It seems as getpwent opens "/etc/shadow" each time it is called. Is this
really needed? In fact, subroutine get_current_uids is part of adduser
script, so this bug affects lots of users.

mk
-- 
 . o .       >>  http://joker.linuxstuff.pl  <<
 . . o   It's easier to get forgiveness for being wrong
 o o o   than forgiveness for being right.


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

Date: 21 Jan 2006 15:32:56 -0000
From: Jim Weeb <jweeb2342@hotmail.com>
Subject: Re: Matching subsets of two strings
Message-Id: <64NQ053Y38738.9812037037@reece.net.au>

In article <I7fAf.213$jO3.168@trnddc07>
"Jürgen Exner" <jurgenex@hotmail.com> wrote:
>
> Jim Weeb wrote:
> > In article <dqqcdq$i40$1@mamenchi.zrz.TU-Berlin.DE>
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> >> See the faq "How do I compute the difference of two arrays? ..."
> >> (perldoc -q difference).
> >
> > Thanks, that appears to tell me the differences (although I'm n
> > ot quite sure what values it puts in what arrays, I'll have to
> > run it and find out). That's a slightly different problem than I
> > have - I want to know which elements of array2 ARE present in
> > array1.
>
> Dude,
>
> did you actually _read_ even just the full title of that FAQ?
> Like the part that Anno marked with the ellipsis?

Yes, however the bit marked is about differences. After another 
read I noticed the bit about intersection (and then it struck 
what intersection meant).

Unfortunately after plumbing in that code it appears not to work 
for me. Obviously a problem somewhere, perhaps I failed to 
declare one of the variables (use strict) - do I have to declare 
both %count and $count?

I will keep plodding along, then ask again if I can't make it 
work.





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

Date: Sat, 21 Jan 2006 15:40:21 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Matching subsets of two strings
Message-Id: <Xns97526CA26E5D1asu1cornelledu@127.0.0.1>

Jim Weeb <jweeb2342@hotmail.com> wrote in news:64NQ053Y38738.9812037037
@reece.net.au:

> In article <I7fAf.213$jO3.168@trnddc07>
> "Jürgen Exner" <jurgenex@hotmail.com> wrote:
>>
>> Jim Weeb wrote:
>> > In article <dqqcdq$i40$1@mamenchi.zrz.TU-Berlin.DE>
>> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>> >> See the faq "How do I compute the difference of two arrays? ..."
>> >> (perldoc -q difference).
>> >
>> > Thanks, that appears to tell me the differences

 ...

>> did you actually _read_ even just the full title of that FAQ?

 ...

> Unfortunately after plumbing in that code it appears not to work 
> for me. Obviously a problem somewhere

Obviously.

> I will keep plodding along, then ask again if I can't make it 
> work.

Or, as the guidelines suggest, you can post a short, self-contained 
script that we can run, and which demonstrates the problem you are 
having, so others can help you.

Sinan

PS: Why do you have X-No-Archive set?

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

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: Sat, 21 Jan 2006 15:41:43 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Matching subsets of two strings
Message-Id: <XCsAf.2734$jd5.848@trnddc02>

Jim Weeb wrote:
> In article <I7fAf.213$jO3.168@trnddc07>
> "Jürgen Exner" <jurgenex@hotmail.com> wrote:
>>
>> Jim Weeb wrote:
>>> In article <dqqcdq$i40$1@mamenchi.zrz.TU-Berlin.DE>
>>> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>>>> See the faq "How do I compute the difference of two arrays? ..."
>>>> (perldoc -q difference).
>>>
>>> Thanks, that appears to tell me the differences (although I'm n
>>> ot quite sure what values it puts in what arrays, I'll have to
>>> run it and find out). That's a slightly different problem than I
>>> have - I want to know which elements of array2 ARE present in
>>> array1.
>>
>> Dude,
>>
>> did you actually _read_ even just the full title of that FAQ?
>> Like the part that Anno marked with the ellipsis?
>
> Yes, however the bit marked is about differences. After another
> read I noticed the bit about intersection (and then it struck
> what intersection meant).

My appologies. It wasn't clear from your reply that you did.

> Unfortunately after plumbing in that code it appears not to work
> for me.

Unfortunately "does not work" is completely useless as a description of what 
is happening.

> Obviously a problem somewhere, perhaps I failed to
> declare one of the variables (use strict) - do I have to declare
> both %count and $count?

The actual error message should tell you what is wrong.
If you don't understand the message then just post it here and ask.
Of course with the relevant snippet of the code.

Or rather post a minimal, self-contained sample script, that other people 
can just copy and paste and run themself.

jue 




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

Date: Sat, 21 Jan 2006 07:29:52 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: mistake in my for
Message-Id: <slrndt4dqg.il3.tadmc@magna.augustmail.com>

Glenn Jackman <xx087@freenet.carleton.ca> wrote:
> At 2006-01-20 03:30PM, Olaf "El BLanco" <winter@yahoo.co.uk> wrote:
>>  
>>  
>>  for ($a=0; $a<$max; print "\t$a", $a++) {}
>>  // OK, print 1 2 3 4 5 ... max
>>  
>>  But
>>  
>>  for ($a=0; $a<$max; $a++, print "\t$a") {}
>>  
>>  // print 00 11 22 33 44... max-1max-1 ?
> 
> You've got that backwards.  
> 
> Beware of the comma operator versus calling print with 2 arguments.  


Right.

So just to be clear:

In the 1st one above the comma is a "list separator", so print()
has 2 arguments to print.

In the 2nd one the comma is a "comma operator", it evaluates its
left operand and discards the result, then evaluates the right
operand, so print() has 1 argument to print.


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


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

Date: Sat, 21 Jan 2006 12:39:04 +0100
From: "Reinhard Glauber" <kigar@gmx.net>
Subject: Simple REGEX-Question 
Message-Id: <43d21d54$0$20772$9b4e6d93@newsread4.arcor-online.net>

DQpvaywgSSBoYXZlIHJlYWQgdGhlIHBlcmxkb2MgYWJvdXQgcmVnZXggYnV0IEkgZG9uJ3QgdW5k
ZXJzdGFuZCAobWF5YmUgYmVjYXVzZSBJJ20gR2VybWFuIDstKSApDQp0aGUgdGhpbmcgd2l0aCB0
aGUgaW50ZXJyb2dhdGlvbiBtYXJrICAgDQoNCkkgc2VhcmNoIGZvciAnTfxuY2hlbicgaW4gYSBz
dHJpbmcgYW5kIHdhbnQgYWxzbyB0aGUgNCBsaW5lcyBiZWZvcmUuDQoNCkkgd2FzIHRvbGQgdG8g
dXNlOg0KDQokaHRtbCA9fiAvKC4qXG4pKD86Lipcbil7NH0uKk38bmNoZW4gLzsgICANCg0KDQpi
dXQgd2h5IG5vdCBzaW1wbGUgc2F5Og0KDQokaHRtbCA9fiAvKC4qXG4pezR9LipN/G5jaGVuIC87
ICAgDQoNCnRoYW5rcw==



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

Date: Sat, 21 Jan 2006 07:19:19 -0500
From: "Daniel Kaplan" <NoSPam@NoSpam.com>
Subject: Using scalar instead of stream
Message-Id: <1137845956.119450@nntp.acecape.com>

If a module asks for a readable filehandle (input stream) as below, surely 
there is a way to use a scalar instead?

The module is looking for an email message, which I already have loaded into 
one string?

$entity = $parser->parse(\*STDIN) or die "parse failed\n";

Thanks




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

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


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