[25837] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8073 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 12 11:05:23 2005

Date: Thu, 12 May 2005 08: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, 12 May 2005     Volume: 10 Number: 8073

Today's topics:
        almost correct <hackeras@gmail.com>
        Feasibility of using Perl to strip selected html tags a <invalid@invalid.invalid>
    Re: Feasibility of using Perl to strip selected html ta <tadmc@augustmail.com>
    Re: Games.pl again <tadmc@augustmail.com>
    Re: sub in a package with parameters <zen13097@zen.co.uk>
    Re: sub in a package with parameters xhoster@gmail.com
    Re: XS: SvUPGRADE and test for lvalue (Anno Siegel)
    Re: XS: SvUPGRADE and test for lvalue <tassilo.von.parseval@rwth-aachen.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 12 May 2005 13:23:53 +0300
From: Nikos <hackeras@gmail.com>
Subject: almost correct
Message-Id: <d5varl$feg$1@nic.grnet.gr>

With this way since is more straighforward and less lines of code: Now 
the code is like this:

#=======================LOADING THE .TXT TO THE DATABASE==============
+==========

my $replace = $dbh->prepare( "REPLACE INTO games (gamename, gamedesc,
+gamecounter) VALUES (?, ?, ?)" );

open (FILE, "<../data/games/descriptions.txt") or die $!;

while (<FILE>) {
     chomp;

     if (length) {
        $replace->execute( split(/\t/, $_, 2),  0 ) or print $dbh->errs
+tr;
     }
}

close (FILE);

But the records never get updated and if i delete a row on the txt file 
but the insertion of a new row or an edit of an existing one work ok :-)


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

Date: Thu, 12 May 2005 13:26:05 GMT
From: Spartanicus <invalid@invalid.invalid>
Subject: Feasibility of using Perl to strip selected html tags and/or attributes (scripting/programming novice)
Message-Id: <lok681t5b2bbs4u6qb4vjdd5nqt831s30r@news.spartanicus.utvinternet.ie>

I'm wondering what it would take to employ Perl to strip selected  tags,
attributes, and optionally the content between those tags from html
files for a scripting and/or programming illiterate such as me.

Initially I investigated learning regexes since they are supported by my
editor (Homesite). But after skimming through Jeffrey E.F. Friedl's
"Mastering Regular Expressions" I'm inclined to think that regexes are
actually poorly suited for this task. Afaics ideal would be if the
content could be manipulated via a parser that understands html & sgml.

I didn't manage to find such a tool with a "dummy/GUI" interface. But I
am intrigued by the result of a search that suggested to me that Perl
has such a html & sgml parser and a module that seems designed
specifically for this job:
http://search.cpan.org/~ncleaton/HTML-StripScripts-0.03/StripScripts.pm

I'm looking for estimates on how much work it would be to learn how to
use Perl for this specific purpose.

-- 
Spartanicus


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

Date: Thu, 12 May 2005 09:15:09 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Feasibility of using Perl to strip selected html tags and/or attributes (scripting/programming novice)
Message-Id: <slrnd86p7d.l80.tadmc@magna.augustmail.com>

Spartanicus <invalid@invalid.invalid> wrote:

> I'm wondering what it would take to employ Perl to strip selected  tags,
> attributes, and optionally the content between those tags from html


   perldoc -q html

       How do I remove HTML from a string?


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


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

Date: Thu, 12 May 2005 07:44:30 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Games.pl again
Message-Id: <slrnd86jte.kp0.tadmc@magna.augustmail.com>

Nikos <hackeras@gmail.com> wrote:

> Tad McClellan wrote:


Please do not say I wrote stuff that I did not write.

Your repeated carelessness shows a disrespect for your audience.



> my $replace = $dbh->prepare( "REPLACE INTO games (gamename, gamedesc, 
> gamecounter) VALUES (?, ?, ?)" );

>      $replace->execute( split(/\t/, $_, 2) , 0 ) or print $dbh->errstr;


> called with 1 bind variables when 3 are needed


[ snip a bunch more of the same message]

Seeing the identical string dozen times does not help us help you,
it hurts us being able to help you.

So please don't do that.


> I cant understand it though.


In your prepare() you have 3 placeholders.

In your execute() you have only 1 value when there should be 3.

The split() must be returning a 1-element list rather than
the 3-element list you seem to be expecting.

ie. You have processed a data line with zero tabs on it.


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


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

Date: 12 May 2005 10:38:34 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: sub in a package with parameters
Message-Id: <42833229$0$30372$da0feed9@news.zen.co.uk>

On Thu, 12 May 2005 10:07:31 +0200, Roman <rbcs@gmx.net> wrote:
> 
>  sub ReadParameter {
>     my($none, $file, $categorie, $parameter) = @_;

>      my( $ReadConfigFile) = RWToDatasotre->ReadParameter(
>  $MainApplicationfile, $testcategorie, $testparameter);

>  Why do I have to have to define one more parameter in the package then
>  defined in the streing where i call the string?


If ReadParameter is a class method, rather than an instance method
(i.e. it needs no direct reference to any object of the RWToDatasotre
package, as it appears in your case), then you can define it like this:

 sub ReadParameter {
        my( $file, $categorie, $parameter) = @_;
	...

and call it like this:

    RWToDatasotre::ReadParameter( $MainApplicationfile,
				  $testcategorie, $testparameter );

                 ^^
		 Note!

If, on the other hand, it requires access to an object of the
RWToDatasotre class, you would define it something like:

 sub ReadParameter {
	my( $self, $file, $categorie, $parameter) = @_;
	,,,


and call it like this:
    $RWToDatasotre_obj->ReadParameter( $MainApplicationfile,
				  $testcategorie, $testparameter );

     ^^^
     this 'object' goes into the $self variable


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

Date: 12 May 2005 14:56:45 GMT
From: xhoster@gmail.com
Subject: Re: sub in a package with parameters
Message-Id: <20050512105645.861$CP@newsreader.com>

Roman <rbcs@gmx.net> wrote:

> _______________________________________________________________________
> package RWToDatasotre;
 ...
> sub ReadParameter {
>    my($none, $file, $categorie, $parameter) = @_;
 ...

>
>     my( $ReadConfigFile) = RWToDatasotre->ReadParameter(
> $MainApplicationfile, $testcategorie, $testparameter);
> _______________________________________________________________________
>
> Why do I have to have to define one more parameter in the package then
> defined in the streing where i call the string?

You don't, it is just that one of the paramaters looks funny.

RWToDatasotre->ReadParameter($MApp,   $cat,    $para);
^parm1^                      ^parm2^  ^parm3^  ^parm4^


That is how OO works.


Xho

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


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

Date: 12 May 2005 10:19:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: XS: SvUPGRADE and test for lvalue
Message-Id: <d5vait$6ru$1@mamenchi.zrz.TU-Berlin.DE>

Wolfram Humann  <w.n.humann.removethis@agilent.com> wrote in comp.lang.perl.misc:
> This XS code can be found in many CPAN modules (e.g. Zlib.xs):
> 
> if (!SvUPGRADE(buf, SVt_PV))
>      croak("cannot use buf argument as lvalue");
> 
> It is used before sending "SV * buf" to a C function that will fill buf 
> with some string. I wanted to use the same in my code but just could not 
> get it to "carp" even if I passed numeric or string constants to buf. 
> When I say
> 
> if (SvREADONLY(buf))
>      croak("cannot use buf argument as lvalue");
> 
> instead (and "SvUPGRADE" separately), the test works as expected. I 
> looked at sv_upgrade in sv.c and found two "return TRUE;" statements but 
> no way for the function to return FALSE.

You are right.  sv_upgrade() croaks itself under some circumstances,
but when it returns, it returns true.

> Did sv_upgrade change at some point, so that the test used above does 
> not work anymore? Any insights?

That is probably what happened.  It must have returned false at some
time in the past.  These days, if( !SvUPGRADE(...) ) must be considered
cargo cult.

Anno


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

Date: Thu, 12 May 2005 16:33:56 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: XS: SvUPGRADE and test for lvalue
Message-Id: <slrnd86qak.296.tassilo.von.parseval@localhost.localdomain>

Also sprach Wolfram Humann:

> This XS code can be found in many CPAN modules (e.g. Zlib.xs):
>
> if (!SvUPGRADE(buf, SVt_PV))
>      croak("cannot use buf argument as lvalue");
>
> It is used before sending "SV * buf" to a C function that will fill buf 
> with some string. I wanted to use the same in my code but just could not 
> get it to "carp" even if I passed numeric or string constants to buf. 

The piece of code you quoted is nonsense in two ways. First of all,
SvUPGRADE (although being a macro) is documented to have a return type
of 'void', according to perlapi.pod. 

Secondly, SvUPGRADE() has nothing to do with the readonlyness of a
variable.  It merely turns one SV into a more complex SV, not touching
the readonly-flag.

> When I say
>
> if (SvREADONLY(buf))
>      croak("cannot use buf argument as lvalue");
>
> instead (and "SvUPGRADE" separately), the test works as expected. I 
> looked at sv_upgrade in sv.c and found two "return TRUE;" statements but 
> no way for the function to return FALSE.
>
> Did sv_upgrade change at some point, so that the test used above does 
> not work anymore? Any insights?

Not that I am aware of. Note that sv_upgrade will actually croak when it
was unable to upgrade an SV.

Tassilo
-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);


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

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


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