[24721] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6877 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 17 18:35:28 2004

Date: Tue, 17 Aug 2004 15:10:11 -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           Tue, 17 Aug 2004     Volume: 10 Number: 6877

Today's topics:
    Re: Placeholder in an sql query (Heinrich Mislik)
        pod2text and carriage-return's <DON'T_SEND_ME@TRIPE_TO_MY_IN.BOX>
    Re: Problems with proxy .. (Idan Jan)
    Re: Search/Replace in CSV files <bmb@ginger.libs.uga.edu>
        Trying to parse a variable name (Aaron)
    Re: Trying to parse a variable name <noreply@gunnar.cc>
    Re: Trying to parse a variable name <ebohlman@omsdev.com>
    Re: Trying to parse a variable name <noreply@gunnar.cc>
    Re: Trying to parse a variable name <mritty@gmail.com>
    Re: Trying to parse a variable name <noreply@gunnar.cc>
    Re: Variable in "if" statement <geenbestaandadres@lycos.nl>
        xml signatures <perl@my-header.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 17 Aug 2004 15:30:11 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: Placeholder in an sql query
Message-Id: <4122247a$0$11610$3b214f66@usenet.univie.ac.at>

In article <97314b5b.0408162143.2cd50109@posting.google.com>, dn_perl@hotmail.com says...
>
>
>I had written -
>> I want to use placeholder to escape special characters directly
>> via DBI while constructing an sql query.
>> 
>
>I am guessing now that the problem could be somehow associated with
>a specific field named 'part' in a table. Is 'part' a reserved
>word? But even that cannot be the case because without placeholder,
>the query works just fine.

What database do you use? The following is true for Oracle but may happen with other DBs as well:

If the type of a field is CHAR(n), placeholders sometimes do not work, because the driver uses VARCHAR for placeholders as default. The reason is, that comparing CHAR(n) to CHAR(m) implicit pads with blanks, whereas comparing CHAR(n) with VARCHAR doesn't pad. And constants are considerd CHAR.


Consider PART CHAR(10) has a value of 'foo       ':

WHERE part = 'foo'

will do 

'foo       ' = 'foo       '

which is true.

WHERE part = ? 

will do

'foo       ' = 'foo'

which is false.

As a workaround try padding yourself:

WHERE part = RPAD(?,10)

If yoer database does not hav RPAD, do it in perl:

$check_part = sprintf("%-10s",$check_part);

Hth

cheers

Heinrich

-- 
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140



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

Date: Tue, 17 Aug 2004 18:12:50 +0100
From: "Nath" <DON'T_SEND_ME@TRIPE_TO_MY_IN.BOX>
Subject: pod2text and carriage-return's
Message-Id: <41223c94$0$9444$afc38c87@news.ukonline.co.uk>

I am trying to use pod2text (windows) on my Perl/Tk application. I have
converted the Perl script file to Unix, but when i use pod2text it puts the
carriage-return's in the resulting text file. So when i use the application
on RedHat and access the text file it shows all the carriage-return's! Very
annoying!

Does pod2text have any option for making the resulting text file unix
friendly? or am i missing something else?

Thanks
Nathan




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

Date: 17 Aug 2004 12:25:35 -0700
From: idan.jan@gmail.com (Idan Jan)
Subject: Re: Problems with proxy ..
Message-Id: <2ca34262.0408171125.3f37a98e@posting.google.com>

Thanks for your reply Jim.


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

Date: Tue, 17 Aug 2004 14:31:50 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Search/Replace in CSV files
Message-Id: <Pine.A41.4.58.0408171425420.36068@ginger.libs.uga.edu>

On Mon, 16 Aug 2004, Brad Baxter wrote:

> my %hash;
> open F1, 'file1' or die $!;
> open F2, 'file2' or die $!;
> open F3, '>file3' or die $!;
> map $hash{ $_ } = 1, <F1>;
> map { print F3 unless $hash{ $_ } } <F2>;
> rename 'file3', 'file2' or die $!;

Okay, nobody called me on this, so I'm feeling guilty.  I wouldn't use map
this way.  Instead perhaps this:

$hash{ $_ } = 1 while <F1>;
$hash{ $_ } or print F3 while <F2>;

It isn't that I'm against using map in void context, but the above is
simply gratuitous and probably wasteful.  :-)

Regards,

Brad


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

Date: 17 Aug 2004 09:34:32 -0700
From: naunga@hotmail.com (Aaron)
Subject: Trying to parse a variable name
Message-Id: <7e5df83d.0408170730.700f3a39@posting.google.com>

Basically I'm reading a SQL predicate from an XML file. The predicate
contains a perl variable name.

I have a sub called parseValue that takes a literal string and then
returns the value.

Now, if I pass in a qq{} or ' ' quoted string it works fine, but when
I pass in the value from the XML file it doesn't work.

I should get the following output:

PARSED STRING: ENGINE_ID = 1
PARSED STRING: ENGINE_ID = 1

But I get the following:

PARSED STRING: ENGINE_ID = 1
PARSED STRING: ENGINE_ID = &parseValue($engine_id)

What the heck is going on?

I've included the code and the XML file below.

#!/usr/bin/perl

use XML::Simple;
use Data::Dumper;

$engine_id = 1;

sub parseValue
{
        my $value = shift;

        $value =~ s/\$(\w+)/${$1}/;

        return $value;
}

print "PARSED VALUE: ",&parseValue('$engine_id'),"\n";

sub BySequence
{
        $transforms->{Transform}->{$a}->{Sequence} <=> 
$transforms->{Transform}->{$b}->{Sequence}
}

$transforms = XMLin("test.xml",forcearray => ["Transform"]);

foreach $transform (sort BySequence keys %{$transforms->{Transform}})
{
        %transform = %{$transforms->{Transform}->{$transform}};

        $delete_predicate = $transform{DeletePredicate};

        print "$delete_predicate\n";
        $delete_predicate =~ s/(\$\w+)/&parseValue($1)/g;
        print "$delete_predicate\n";

        %transform = ();
}

<?xml version="1.0" ?>
<Transforms>
        <Transform Sequence="1" name="Planned Order">
                <DeletePredicate>ENGINE_ID =
$engine_id</DeletePredicate>
        </Transform>
</Transforms>


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

Date: Tue, 17 Aug 2004 19:15:21 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Trying to parse a variable name
Message-Id: <2oesn4Fa2edpU1@uni-berlin.de>

[ Did not reply to the defunct group comp.lang.perl. ]

Aaron wrote:
> I have a sub called parseValue that takes a literal string and then
> returns the value.

<snip>

> sub parseValue
> {
>         my $value = shift;
>         $value =~ s/\$(\w+)/${$1}/;
>         return $value;
> }

Then you don't have strictures enabled, and you are in the business of 
symbolic references. :(  There are better methods to achive the same
thing, such as plain replacements based on a set of keys/values in a
hash.

> when I pass in the value from the XML file it doesn't work.

<snip>

Is it this line you are talking about?

>         $delete_predicate =~ s/(\$\w+)/&parseValue($1)/g;

Then you may want to check the Perl FAQ:

     perldoc -q "expand function calls"

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


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

Date: 17 Aug 2004 20:10:47 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: Trying to parse a variable name
Message-Id: <Xns95489B417DE88ebohlmanomsdevcom@130.133.1.4>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in news:2oesn4Fa2edpU1@uni-
berlin.de:

> Is it this line you are talking about?
> 
>>         $delete_predicate =~ s/(\$\w+)/&parseValue($1)/g;
> 
> Then you may want to check the Perl FAQ:
> 
>      perldoc -q "expand function calls"

Actually, I think a visit to "quotes and quote-like operators" in perlop, 
specifically the description of the s operator, would be more in order.  I 
wouldn't look too kindly on any code that uses one of the methods from that 
particular FAQ in the replacement part of an s.

Oh, and I'd also recommend the OP read the posting guidelines, particularly 
the parts about letting perl give you all the help it can and about posting 
actual code (the original post mentioned output that contained literal 
strings not present in the posted code).


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

Date: Tue, 17 Aug 2004 22:23:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Trying to parse a variable name
Message-Id: <2of7oaFa4qplU1@uni-berlin.de>

Eric Bohlman wrote:
> Gunnar Hjalmarsson wrote:
>> Is it this line you are talking about?
>> 
>>>        $delete_predicate =~ s/(\$\w+)/&parseValue($1)/g;
>> 
>> Then you may want to check the Perl FAQ:
>> 
>>     perldoc -q "expand function calls"
> 
> Actually, I think a visit to "quotes and quote-like operators" in
> perlop, specifically the description of the s operator, would be
> more in order.

Yeah, I should have mentioned that, too.

> I wouldn't look too kindly on any code that uses one of the methods
> from that particular FAQ in the replacement part of an s.

Now I'm not following you. Actually, it only mentions one method. Why
would you object to

     s/to_be_replaced/@{ [ somefunction() ] }/

?

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


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

Date: Tue, 17 Aug 2004 16:25:45 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Trying to parse a variable name
Message-Id: <20040817162427.I2996@barbara.cs.rpi.edu>

On Tue, 17 Aug 2004, Gunnar Hjalmarsson wrote:

> Eric Bohlman wrote:
> > Gunnar Hjalmarsson wrote:
> >> Is it this line you are talking about?
> >>
> >>>        $delete_predicate =~ s/(\$\w+)/&parseValue($1)/g;
> >>
> >> Then you may want to check the Perl FAQ:
> >>
> >>     perldoc -q "expand function calls"
> >
> > Actually, I think a visit to "quotes and quote-like operators" in
> > perlop, specifically the description of the s operator, would be
> > more in order.
>
> Yeah, I should have mentioned that, too.
>
> > I wouldn't look too kindly on any code that uses one of the methods
> > from that particular FAQ in the replacement part of an s.
>
> Now I'm not following you. Actually, it only mentions one method. Why
> would you object to
>
>      s/to_be_replaced/@{ [ somefunction() ] }/

I'd object to that because 1) it's ugly, 2) it's non-intuitive, 3) there's
a 'better' (more standard?) way.

s/to_be_replaced/somefunction()/e

But that's just me.

Paul Lalli


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

Date: Tue, 17 Aug 2004 22:38:28 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Trying to parse a variable name
Message-Id: <2of8kiFa6jqmU1@uni-berlin.de>

Paul Lalli wrote:
> Gunnar Hjalmarsson wrote:
>> 
>> Why would you object to
>> 
>>     s/to_be_replaced/@{ [ somefunction() ] }/
> 
> I'd object to that because 1) it's ugly, 2) it's non-intuitive, 3)
> there's a 'better' (more standard?) way.
> 
> s/to_be_replaced/somefunction()/e

Well, in that simple case, I would have done so, too.

But let's assume that the return value from the function is only a
part of the replacement string:

     s/to_be_replaced/start @{ [ somefunction() ] } end/

     s/to_be_replaced/'start ' . somefunction() . ' end'/e

Which is best is no longer *that* obvious, is it? ;-)

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


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

Date: Tue, 17 Aug 2004 20:59:21 +0200
From: "JJ" <geenbestaandadres@lycos.nl>
Subject: Re: Variable in "if" statement
Message-Id: <4122559d$0$62368$5fc3050@dreader2.news.tiscali.nl>

if($Name ne ""){
statements;
}


Vincent



"blnukem" <bill@hotmail.com> schreef in bericht
news:TqmUc.20778$vc4.4943718@news4.srv.hcvlny.cv.net...
> Hi all
>
> I have this sub routine for sending email from my web site but it seems to
> have a  problem that I cant seem to figure out on the line that reads :
>
> if($Name){
>     print MAIL "$Name: $Value \n";
>     }
>
> Now I thought that this should only print if $Name has a value, it print
all
> the time cant figure it out.
>
>
> CODE:
>
> sub SendMail {
>
> $FORM{'SendersName'} = lc($FORM{'SendersName'});
> $FORM{'SendersName'} =~ s/([\w']+)/\u\L$1/g;
> $FORM{'SendersEmail'} = lc($FORM{'SendersEmail'});
>
> open (MAIL, "|$MailProg -t") or die("Can't open $MailProg!\n");
> print MAIL "From: $FORM{'SendersName'}\n";
> print MAIL "To: $Admin \n";
> print MAIL "Subject: $FORM{'Subject'}\n";
>
> print MAIL "Senders Name: $FORM{'SendersName'}\n";
> print MAIL "Senders E-Mail: $FORM{'SendersEmail'}\n";
> print MAIL "Senders Message: $FORM{'Message'}\n";
>
> foreach $Pair (@Pairs) {
>   ($Name, $Value) = split(/=/, $Pair);
>   $Name =~ tr/+/ /;
>   $Name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>   $Value =~ tr/+/ /;
>   $Value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>   $FORM{$Name} = $Value;
>
> next if (($Name eq "SendersEmail")||($Name eq "Subject")||($Name eq
> "Message")
> ||($Name eq "SendersName"));
>
>     if($Name){
>     print MAIL "$Name: $Value \n";
>     }
>  }
>
> close (MAIL);
>
>    exit;
> }
>
>
> Thanks in advance
> Blnukem
>
>




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

Date: Tue, 17 Aug 2004 23:59:28 +0200
From: Matija Papec <perl@my-header.org>
Subject: xml signatures
Message-Id: <l0v4i09dr1deb1ep247d2gskj3o97evv1k@4ax.com>


I would like to do xml signing and verifying and after spending some time at
cpan I found nice xml modules, but neither of them has ability to handle
signatures. Please slap me with some docs; TIA!



-- 
Matija


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

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


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