Re: escaping regex to do math on backreferences

2009-04-13 Thread Gunnar Hjalmarsson

Chas. Owens wrote:

On Sun, Apr 12, 2009 at 21:58, Gunnar Hjalmarsson nore...@gunnar.cc wrote:

Chas. Owens wrote:

my @rank = qw/ 2 3 4 5 6 7 8 9 10 J Q K A /;

   my @rank = qw/A 2 3 4 5 6 7 8 9 10 J Q K A /;
--^

snip

That depends on who you play with.


Ok.


Also, if you make that change you need to check the for loop as well:

for my $i (0 .. 10) {


Actually no.

$ perl -wle '
@rank = qw/A 2 3 4 5 6 7 8 9 10 J Q K A/;
print map $_.[cdhs], @rank[10..10+4];
'
Use of uninitialized value $_ in concatenation (.) or string at -e line 3.
J[cdhs]Q[cdhs]K[cdhs]A[cdhs][cdhs]
$

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

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: escaping regex to do math on backreferences

2009-04-13 Thread Chas. Owens
On Mon, Apr 13, 2009 at 06:12, Gunnar Hjalmarsson nore...@gunnar.cc wrote:
snip
 Also, if you make that change you need to check the for loop as well:

 for my $i (0 .. 10) {

 Actually no.

 $ perl -wle '
 @rank = qw/A 2 3 4 5 6 7 8 9 10 J Q K A/;
 print map $_.[cdhs], @rank[10..10+4];
 '
 Use of uninitialized value $_ in concatenation (.) or string at -e line 3.
snip

Ahha, my original had the same off-by-one error.  How did I miss that?

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: escaping regex to do math on backreferences

2009-04-12 Thread Gunnar Hjalmarsson

Andrew Fithian wrote:

I have a program that needs to find straights in a hand of cards.


Only straights?

The hand is a string with no whitespace sorted by the cards' ranks, 
eg 9d10cJhQsKd. How can I identify if that hand contains a straight 
with a single regex?


Why on earth would you want to do that?


Is that even possible?


I doubt it.

I suggest you check out the Games::Poker::HandEvaluator module at CPAN.

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

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: escaping regex to do math on backreferences

2009-04-12 Thread Chas. Owens
On Sun, Apr 12, 2009 at 18:34, Andrew Fithian afit...@gmail.com wrote:
 Hello everyone,
 I have a program that needs to find straights in a hand of cards. The hand
 is a string with no whitespace sorted by the cards' ranks, eg 9d10cJhQsKd.
 How can I identify if that hand contains a straight with a single regex? Is
 that even possible?
 Is there a way to escape the regex and do addition on a backreference to get
 something like /(\d+)[cdhs]\1+1[cdhs]\1+2/?
 Thanks,
 -Andrew


It is easier to just build it:

#!/usr/bin/perl

use strict;
use warnings;

my @rank = qw/ 2 3 4 5 6 7 8 9 10 J Q K A /;
my @hands;
for my $i (0 .. 9) {
push @hands, join '', map  { $_ . [cdhs] } @rank[$i .. $i+4];
}

my $re = join '|', @hands;
$re = qr/^$re$/;

for my $s (qw/ 9d10cJhQsKd 8c10cJhQsKd /) {
print $s , $s =~ /$re/ ? is : isn't,  a straight\n;
}


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: escaping regex to do math on backreferences

2009-04-12 Thread Gunnar Hjalmarsson

Chas. Owens wrote:


my @rank = qw/ 2 3 4 5 6 7 8 9 10 J Q K A /;


my @rank = qw/A 2 3 4 5 6 7 8 9 10 J Q K A /;
--^

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

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: escaping regex to do math on backreferences

2009-04-12 Thread Chas. Owens
On Sun, Apr 12, 2009 at 21:58, Gunnar Hjalmarsson nore...@gunnar.cc wrote:
 Chas. Owens wrote:

 my @rank = qw/ 2 3 4 5 6 7 8 9 10 J Q K A /;

    my @rank = qw/A 2 3 4 5 6 7 8 9 10 J Q K A /;
 --^
snip

That depends on who you play with.   Also, if you make that change you
need to check the for loop as well:

for my $i (0 .. 10) {

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Escaping a plus sign

2006-05-31 Thread Ken Lehman
Is it the if ($MGMTCMNT =~ /$MGMTNM/) part that is tripping you up? I
believe you could change it to if ($MGMTCMNT =~ /\Q$MGMTNM\E/) if you
need to keep the regular expression. Another idea might be to change it
to 
if ( ($start = index($MGMTCMNT, $MGMTNM ())  0) {




-Original Message-
From: Paul Nowosielski 
Sent: Tuesday, May 30, 2006 4:13 PM
To: beginners@perl.org
Subject: Escaping a plus sign

Dear All,

I have a perl script that runs nightly. It create a data feed. The
script will 
die if the is a + sign in the fields its parsing.

Here is the snippet:

while (($PKEY, $MGMTCMNT, $manager_id, $MGMTNM, $UPDATE1, $UPDATE2) = 
$sth-fetchrow_array) {
$comment = ;
if ($MGMTCMNT =~ /$MGMTNM/) {
$len = length($MGMTNM);
$start = index($MGMTCMNT, $MGMTNM ();
$start += $len + 2;
$end = index($MGMTCMNT, ), $start) - $start;
$comment = substr($MGMTCMNT, $start, $end);
}
if ($UPDATE1  $artisttime || $UPDATE2  $artisttime ) {
print (ARTMGRFILE $PKEY\t$manager_id\t$comment\n);
}
}

Here is the error message:

Quantifier follows nothing in regex; marked by -- HERE in m/+ -- HERE
1 
Public Relations/ at /srv/www/htdocs/admin/utilities/aeg/manart.pl line
102.

In this error the problem file had the text +1 Public Relations;

Is there a way to escape this character so in the future it won't kill
the 
script?

Thank you,
-- 
Paul Nowosielski



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




 


This email and any attachments have been scanned for known viruses using 
multiple scanners.
We believe that this email and any attachments are virus free, however the 
recipient must 
take full responsibility for virus checking. This email message is intended for 
the named 
recipient only. It may be privileged and/or confidential. If you are not the 
intended named
recipient of this email then you should not copy it or use it for any purpose, 
nor disclose
its contents to any other person. You should contact Misys Banking Systems so 
that we can 
take appropriate action at no cost to yourself.



www.misys.com 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping a plus sign

2006-05-31 Thread Dr.Ruud
Paul Nowosielski schreef:

 The
 script will die if the is a + sign in the fields its parsing.

  perldoc -f quotemeta

-- 
Affijn, Ruud

Gewoon is een tijger.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping a plus sign

2006-05-30 Thread Anthony Ettinger

should probably escape the + sign with \+

$field =~ s/\+/\\+/g;


On 5/30/06, Paul Nowosielski [EMAIL PROTECTED] wrote:

Dear All,

I have a perl script that runs nightly. It create a data feed. The script will
die if the is a + sign in the fields its parsing.

Here is the snippet:

while (($PKEY, $MGMTCMNT, $manager_id, $MGMTNM, $UPDATE1, $UPDATE2) =
$sth-fetchrow_array) {
$comment = ;
if ($MGMTCMNT =~ /$MGMTNM/) {
$len = length($MGMTNM);
$start = index($MGMTCMNT, $MGMTNM ();
$start += $len + 2;
$end = index($MGMTCMNT, ), $start) - $start;
$comment = substr($MGMTCMNT, $start, $end);
}
if ($UPDATE1  $artisttime || $UPDATE2  $artisttime ) {
print (ARTMGRFILE $PKEY\t$manager_id\t$comment\n);
}
}

Here is the error message:

Quantifier follows nothing in regex; marked by -- HERE in m/+ -- HERE 1
Public Relations/ at /srv/www/htdocs/admin/utilities/aeg/manart.pl line 102.

In this error the problem file had the text +1 Public Relations;

Is there a way to escape this character so in the future it won't kill the
script?

Thank you,
--
Paul Nowosielski



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response






--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping a plus sign

2006-05-30 Thread Paul Nowosielski
So would this be the correct solution:

while (($PKEY, $MGMTCMNT, $manager_id, $MGMTNM, $UPDATE1, $UPDATE2) = 
$sth-fetchrow_array) {
$comment = ;

# added to escape  the plus sign
$MGMTCMNT = ~ s/\+/\\+/g;
$MGMTNM = ~ s/\+/\\+/g;

if ($MGMTCMNT =~ /$MGMTNM/) {
$len = length($MGMTNM);
$start = index($MGMTCMNT, $MGMTNM ();
$start += $len + 2;
$end = index($MGMTCMNT, ), $start) - $start;
$comment = substr($MGMTCMNT, $start, $end);
}
if ($UPDATE1  $artisttime || $UPDATE2  $artisttime ) {
print (ARTMGRFILE $PKEY\t$manager_id\t$comment\n);
}
}

On Tuesday 30 May 2006 14:23, Anthony Ettinger wrote:
 should probably escape the + sign with \+

 $field =~ s/\+/\\+/g;

 On 5/30/06, Paul Nowosielski [EMAIL PROTECTED] wrote:
  Dear All,
 
  I have a perl script that runs nightly. It create a data feed. The script
  will die if the is a + sign in the fields its parsing.
 
  Here is the snippet:
 
  while (($PKEY, $MGMTCMNT, $manager_id, $MGMTNM, $UPDATE1, $UPDATE2) =
  $sth-fetchrow_array) {
  $comment = ;
  if ($MGMTCMNT =~ /$MGMTNM/) {
  $len = length($MGMTNM);
  $start = index($MGMTCMNT, $MGMTNM ();
  $start += $len + 2;
  $end = index($MGMTCMNT, ), $start) - $start;
  $comment = substr($MGMTCMNT, $start, $end);
  }
  if ($UPDATE1  $artisttime || $UPDATE2  $artisttime ) {
  print (ARTMGRFILE $PKEY\t$manager_id\t$comment\n);
  }
  }
 
  Here is the error message:
 
  Quantifier follows nothing in regex; marked by -- HERE in m/+ -- HERE 1
  Public Relations/ at /srv/www/htdocs/admin/utilities/aeg/manart.pl line
  102.
 
  In this error the problem file had the text +1 Public Relations;
 
  Is there a way to escape this character so in the future it won't kill
  the script?
 
  Thank you,
  --
  Paul Nowosielski
 
 
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/ http://learn.perl.org/first-response

-- 
Paul Nowosielski
Webmaster
office: 303.440.0666 ext 219
cel: 303.827.4257


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping a plus sign

2006-05-30 Thread John W. Krahn
Paul Nowosielski wrote:
 Dear All,

Hello,

 I have a perl script that runs nightly. It create a data feed. The script 
 will 
 die if the is a + sign in the fields its parsing.
 
 Here is the snippet:
 
 while (($PKEY, $MGMTCMNT, $manager_id, $MGMTNM, $UPDATE1, $UPDATE2) = 
 $sth-fetchrow_array) {
 $comment = ;
 if ($MGMTCMNT =~ /$MGMTNM/) {
 $len = length($MGMTNM);
 $start = index($MGMTCMNT, $MGMTNM ();
 $start += $len + 2;
 $end = index($MGMTCMNT, ), $start) - $start;
 $comment = substr($MGMTCMNT, $start, $end);
 }
 if ($UPDATE1  $artisttime || $UPDATE2  $artisttime ) {
 print (ARTMGRFILE $PKEY\t$manager_id\t$comment\n);
 }
 }
 
 Here is the error message:
 
 Quantifier follows nothing in regex; marked by -- HERE in m/+ -- HERE 1 
 Public Relations/ at /srv/www/htdocs/admin/utilities/aeg/manart.pl line 102.
 
 In this error the problem file had the text +1 Public Relations;
 
 Is there a way to escape this character so in the future it won't kill the 
 script?

Yes, you can use the quotemeta escape sequence.  Just change:

 if ($MGMTCMNT =~ /$MGMTNM/) {

To:

 if ($MGMTCMNT =~ /\Q$MGMTNM/) {



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping large chunk of text for insertion into mysql

2006-02-01 Thread John Doe
Kevin Old am Mittwoch, 1. Februar 2006 13.44:
 Hello everyone,

 I have a large chunk of data that I need to insert into a text or blob
 field in mysql.  I've tried all the usually escaping it, but nothing
 seems to work.  I'm even using dbh-quote as I thought it might help.

 Here's my code:

 my $sth = $dbh-prepare(insert into nascar_media values(
 personal_characteristics ) (?));
 $sth-execute( $dbh-quote($vals[13]) );

 Not that it really helps, here's the DBD::mysql error returned:

 DBD::mysql::st execute failed: You have an error in your SQL syntax;
 check the manual that corresponds to your MySQL server version for the
 right syntax to use near '('\'Married: Arlene. Children: Amy
 (10/14/72), Twins Rachel and Heather (10/31/7' at line 1 at ./nm4.pl
 line 181.

The first single quote in the error msg is from the msg itself. The error 
occurs at the '('. So, your mysql syntax is wrong, independently from the 
inserted value. Just thest the statement at the mysal cmdline.

Then, when using placeholders, quote() is not necessary; it's done 
automagically.

I did not test it, but try the following (also note the missing field name 
'personal_characteristics') - it is assumed that the table only consists of 
one field.

$dbh-prepare( 'insert into nascar_media values (?)' );
$sth-execute( $vals[13] );

Check 
man DBI
http://dev.mysql.com/

hth,
joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping with tr

2005-09-02 Thread Bernard van de Koppel
Hi,

Thanks for the warning.
As far as the specs are, a semicolon is not allowed as data in the datastream 
(yet)  (of an electronic banking backend application).
Some files however don't use the doublequote combined with the semicolon, but 
just the semicolon to identify fields.

So far the semicolon is probably the best way to split the data.

So the question is more like, howmuch time to put in an possible change from 
some side in the future.

Bernard

On Tuesday 30 August 2005 23:40, Scott Taylor wrote:
 Wiggins d'Anconia said:
  Scott Taylor wrote:

 I did not.

 Hi,
 
 How can I get all the  characters out of a csv file.
 
 Input looks like
 bla bla;bla bla;bla bla
 
 and it has to look like
 bla bla;bla bla; bla bla
 
 I tried $text=~ tr(#\##);
 but perl keeps complaining about Might be a runaway multi-line ;;
 
  On a more serious note. Simply removing *all* double quotes can be a
  dangerous proposition unless your data really does look like bla bla
  which I somewhat doubt. Usually a delimited file like this will quote
  specific fields because they may contain the delimiter, in this case a
  semi-colon. Are you sure bla bla can't be blah; blah blah, and then
  in the future need to still be delimited by the semi-colon?
 
  Just checking...

 It is not uncommon to find CSV output in the format he describes.  Often I
 need to remove all the quotes out of simple data streams like that.

 --
 Scott

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping with tr

2005-08-30 Thread Eric Walker
On Tuesday 30 August 2005 04:16 pm, Bernard van de Koppel wrote:
 bla bla;bla bla;bla bla

cat test.file | sed 's/\//g'  editedfile
-- 
Eric Walker
EDA/CAD Engineer
Work: 208-368-2573

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping with tr

2005-08-30 Thread JupiterHost.Net



Eric Walker wrote:

On Tuesday 30 August 2005 04:16 pm, Bernard van de Koppel wrote:


bla bla;bla bla;bla bla



cat test.file | sed 's/\//g'  editedfile


Good solution for sed list and if you like redirtecting from a pipe and 
using multiple program when unnecessary (do you also where mits over 
your gloves which are themselves over liners???) :)


perl -pi -e 's/\//g;' my.csv

There are other options you can specify to make the orig and edited file 
different as well, but I'll leave that as an excersize for you :)


HTH :)

Lee.M - JupiterHost.Net

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping with tr

2005-08-30 Thread Wiggins d'Anconia
Eric Walker wrote:
 On Tuesday 30 August 2005 04:16 pm, Bernard van de Koppel wrote:
 
bla bla;bla bla;bla bla
 
 
 cat test.file | sed 's/\//g'  editedfile

Quick someone get the can of UUoC Be Gone ... ;-)

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping with tr

2005-08-30 Thread Bernard van de Koppel
Eric,

thanks for the response.

After some fideling, I found a solution.
$text=~ tr/\042/ /;

Thanks.
On Tuesday 30 August 2005 22:20, Eric Walker wrote:
 On Tuesday 30 August 2005 04:16 pm, Bernard van de Koppel wrote:
  bla bla;bla bla;bla bla

 cat test.file | sed 's/\//g'  editedfile
 --
 Eric Walker
 EDA/CAD Engineer
 Work: 208-368-2573

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping with tr

2005-08-30 Thread Scott Taylor


Bernard van de Koppel said:
 Hi,

 How can I get all the  characters out of a csv file.

 Input looks like
 bla bla;bla bla;bla bla

 and it has to look like
 bla bla;bla bla; bla bla

 I tried $text=~ tr(#\##);
 but perl keeps complaining about Might be a runaway multi-line ;;
starting on the line with tr.

Try to use $text=~s///g;

--
Scott


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping with tr

2005-08-30 Thread Wiggins d'Anconia
Scott Taylor wrote:

Hi,

How can I get all the  characters out of a csv file.

Input looks like
bla bla;bla bla;bla bla

and it has to look like
bla bla;bla bla; bla bla

I tried $text=~ tr(#\##);
but perl keeps complaining about Might be a runaway multi-line ;;
 


On a more serious note. Simply removing *all* double quotes can be a
dangerous proposition unless your data really does look like bla bla
which I somewhat doubt. Usually a delimited file like this will quote
specific fields because they may contain the delimiter, in this case a
semi-colon. Are you sure bla bla can't be blah; blah blah, and then
in the future need to still be delimited by the semi-colon?

Just checking...

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping with tr

2005-08-30 Thread Scott Taylor

Wiggins d'Anconia said:
 Scott Taylor wrote:

I did not.

Hi,

How can I get all the  characters out of a csv file.

Input looks like
bla bla;bla bla;bla bla

and it has to look like
bla bla;bla bla; bla bla

I tried $text=~ tr(#\##);
but perl keeps complaining about Might be a runaway multi-line ;;



 On a more serious note. Simply removing *all* double quotes can be a
 dangerous proposition unless your data really does look like bla bla
 which I somewhat doubt. Usually a delimited file like this will quote
 specific fields because they may contain the delimiter, in this case a
 semi-colon. Are you sure bla bla can't be blah; blah blah, and then
 in the future need to still be delimited by the semi-colon?

 Just checking...

It is not uncommon to find CSV output in the format he describes.  Often I
need to remove all the quotes out of simple data streams like that.

--
Scott

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping with tr

2005-08-30 Thread Bernard van de Koppel
Hi,

Thanks, this works great.

Bernard
On Tuesday 30 August 2005 23:23, Scott Taylor wrote:
  Hi,
 
  How can I get all the  characters out of a csv file.
 
  Input looks like
  bla bla;bla bla;bla bla
 
  and it has to look like
  bla bla;bla bla; bla bla
 
  I tried $text=~ tr(#\##);
  but perl keeps complaining about Might be a runaway multi-line ;;

 starting on the line with tr.

 Try to use $text=~s///g;

 --
 Scott

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping with tr

2005-08-30 Thread John W. Krahn
Bernard van de Koppel wrote:
 Hi,

Hello,

 How can I get all the  characters out of a csv file.
 
 Input looks like
 bla bla;bla bla;bla bla
 
 and it has to look like
 bla bla;bla bla; bla bla
 
 I tried $text=~ tr(#\##);

$text =~ tr///d;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: escaping values (DBD::mysql)

2005-08-01 Thread Jeff 'japhy' Pinyan

On Jul 31, Octavian Rasnita said:


select ... limit 0,30;

but I cannot use:

$sth = $dbh-prepare(select ... limit ?,?);
$sth-execute(0, 30);

... because DBI replaces the values entered with '0' and '30' and the query
won't be valid.


No, you probably can't do that because your SQL engine doesn't allow 
placeholders in LIMIT.  All you need to do is make sure the values are 
non-negative integers, and you can write


  $sth = $dbh-prepare(select ... limit $start, $length);

If you need to escape things, you $dbh-quote(...).

--
Jeff japhy Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: escaping @

2005-07-19 Thread Charles Farinella
On Mon, 2005-07-18 at 11:53, Wiggins d'Anconia wrote:

I had to add a 'chomp' and make sure the line endings in my file were
correct, but this worked and I learned something useful as well.

Thank you.  :-)

--charlie

 Only do things in the loop that must be done in the loop. Reconnecting,
 repreparing, and disconnecting from the DB is a lot of unnecessary work.
 
 perldoc DBI
 
 
 --Untested--
 #!/usr/bin/perl -w
 
 use strict;
 use DBI;
 use DBD::Pg;
 
 my $infile = $ARGV[0];
 
 # no reason to reconnect for every line
 my $dbh = DBI-connect(dbi:Pg:dbname=*, *, *) || die;
 
 # statement should only be prepared once
 # note use of placeholder ? character
 my $sth = $dbh-prepare(UPDATE table SET email = '' WHERE email = ? )
 || die;
 
 open INFILE, $infile or die Can't open file for reading: $!;
 while ( INFILE ) {
$sth-execute( $_ );
 }
 close INFILE;
 
 $sth-finish;
 $dbh-disconnect;
-- 
Charles Farinella 
Appropriate Solutions, Inc. (www.AppropriateSolutions.com)
[EMAIL PROTECTED]
603.924.6079


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: escaping @

2005-07-18 Thread Moon, John
Subject: escaping @

I'm sure this is very simple and I am overlooking something.  I want to
read a list of bad email addresses from a file and remove them from my
database.  

If I print $_, the email addresses are correct, if I try to remove them
from the db I get errors on just the characters before the @.

Here is what I have:

==
#!/usr/bin/perl -w

use strict;
use DBI;
use DBD::Pg;

my $infile = $ARGV[0];


open( INFILE, $infile );
while( INFILE ) {
my $dbh = DBI-connect(dbi:Pg:dbname=*, *, *) || die;

#s/\@/\\@/;
#print $_;

my $sth = $dbh-prepare(UPDATE
table
SET
email = ''
WHERE
email = $_ ) || die;

$sth-execute;

finish $sth;
$dbh-disconnect;
}

close( INFILE );
==

Please try...

snip
open( INFILE, $infile ); 
my $dbh = DBI-connect(dbi:Pg:dbname=*, *, *) || die; 
my $sth = $dbh-prepare(q{UPDATE table 
SET email = '' WHERE email = ? }) || die;
while( INFILE ) {
$sth-execute($_);
...
/snip

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: escaping @

2005-07-18 Thread Wiggins d'Anconia
Charles Farinella wrote:
 I'm sure this is very simple and I am overlooking something.  I want to
 read a list of bad email addresses from a file and remove them from my
 database.  
 
 If I print $_, the email addresses are correct, if I try to remove them
 from the db I get errors on just the characters before the @.


Are you sure those errors aren't coming from the DB?

 Here is what I have:
 
 ==
 #!/usr/bin/perl -w
 
 use strict;
 use DBI;
 use DBD::Pg;
 
 my $infile = $ARGV[0];
 
 
 open( INFILE, $infile );
 while( INFILE ) {
 my $dbh = DBI-connect(dbi:Pg:dbname=*, *, *) || die;
 
 #s/\@/\\@/;
 #print $_;
 
 my $sth = $dbh-prepare(UPDATE
 table
 SET
 email = ''
 WHERE
 email = $_ ) || die;

The above value needs to be quoted for the DB not Perl. But it would be
much more efficient to use placeholders and move your statement
preparation outside of the loop and then provide the e-mail address to
the execute. This will take care of your quoting problems and be more
efficient.

 
 $sth-execute;
 
 finish $sth;
 $dbh-disconnect;
 }
 
 close( INFILE );
 ==
 

Only do things in the loop that must be done in the loop. Reconnecting,
repreparing, and disconnecting from the DB is a lot of unnecessary work.

perldoc DBI


--Untested--
#!/usr/bin/perl -w

use strict;
use DBI;
use DBD::Pg;

my $infile = $ARGV[0];

# no reason to reconnect for every line
my $dbh = DBI-connect(dbi:Pg:dbname=*, *, *) || die;

# statement should only be prepared once
# note use of placeholder ? character
my $sth = $dbh-prepare(UPDATE table SET email = '' WHERE email = ? )
|| die;

open INFILE, $infile or die Can't open file for reading: $!;
while ( INFILE ) {
   $sth-execute( $_ );
}
close INFILE;

$sth-finish;
$dbh-disconnect;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: escaping @

2005-07-18 Thread Charles Farinella
On Mon, 2005-07-18 at 11:53, Wiggins d'Anconia wrote:
 Charles Farinella wrote:
  I'm sure this is very simple and I am overlooking something.  I want to
  read a list of bad email addresses from a file and remove them from my
  database.  
  
  If I print $_, the email addresses are correct, if I try to remove them
  from the db I get errors on just the characters before the @.
 
 
 Are you sure those errors aren't coming from the DB?

I'm getting this:
==
DBD::Pg::st execute failed: ERROR:  column mmartins does not exist at
delBadEmail.pl line 23, INFILE line 378.
==

If I put the address, '[EMAIL PROTECTED]' in the script, that works
fine.

If I insert the '\' in front of @ in $_ it throws this:
==
DBD::Pg::st execute failed: ERROR:  syntax error at or near \ at
character
127 at delBadEmail.pl line 23, INFILE line 378 (#7)
==

I'm confused as to what it wants.  :-(

The solution John Moon sent me didn't work, it send me a bound variable
error.

  Here is what I have:
  
  ==
  #!/usr/bin/perl -w
  
  use strict;
  use DBI;
  use DBD::Pg;
  
  my $infile = $ARGV[0];
  
  
  open( INFILE, $infile );
  while( INFILE ) {
  my $dbh = DBI-connect(dbi:Pg:dbname=*, *, *) || die;
  
  #s/\@/\\@/;
  #print $_;
  
  my $sth = $dbh-prepare(UPDATE
  table
  SET
  email = ''
  WHERE
  email = $_ ) || die;
 
 The above value needs to be quoted for the DB not Perl. But it would be
 much more efficient to use placeholders and move your statement
 preparation outside of the loop and then provide the e-mail address to
 the execute. This will take care of your quoting problems and be more
 efficient.
 
  
  $sth-execute;
  
  finish $sth;
  $dbh-disconnect;
  }
  
  close( INFILE );
  ==
  
 
 Only do things in the loop that must be done in the loop. Reconnecting,
 repreparing, and disconnecting from the DB is a lot of unnecessary work.
 
 perldoc DBI
 
 
 --Untested--
 #!/usr/bin/perl -w
 
 use strict;
 use DBI;
 use DBD::Pg;
 
 my $infile = $ARGV[0];
 
 # no reason to reconnect for every line
 my $dbh = DBI-connect(dbi:Pg:dbname=*, *, *) || die;
 
 # statement should only be prepared once
 # note use of placeholder ? character
 my $sth = $dbh-prepare(UPDATE table SET email = '' WHERE email = ? )
 || die;
 
 open INFILE, $infile or die Can't open file for reading: $!;
 while ( INFILE ) {
$sth-execute( $_ );
 }
 close INFILE;
 
 $sth-finish;
 $dbh-disconnect;
-- 
Charles Farinella 
Appropriate Solutions, Inc. (www.AppropriateSolutions.com)
[EMAIL PROTECTED]
603.924.6079


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: escaping @

2005-07-18 Thread Wiggins d'Anconia
Charles Farinella wrote:
 On Mon, 2005-07-18 at 11:53, Wiggins d'Anconia wrote:
 
Charles Farinella wrote:

I'm sure this is very simple and I am overlooking something.  I want to
read a list of bad email addresses from a file and remove them from my
database.  

If I print $_, the email addresses are correct, if I try to remove them
from the db I get errors on just the characters before the @.


Are you sure those errors aren't coming from the DB?
 
 
 I'm getting this:
 ==
 DBD::Pg::st execute failed: ERROR:  column mmartins does not exist at
 delBadEmail.pl line 23, INFILE line 378.
 ==
 
 If I put the address, '[EMAIL PROTECTED]' in the script, that works
 fine.
 
 If I insert the '\' in front of @ in $_ it throws this:
 ==
 DBD::Pg::st execute failed: ERROR:  syntax error at or near \ at
 character
 127 at delBadEmail.pl line 23, INFILE line 378 (#7)
 ==
 
 I'm confused as to what it wants.  :-(


That is because the value is not quoted.

 The solution John Moon sent me didn't work, it send me a bound variable
 error.
 

Did you try the one I sent below?  What were the errors?  What exactly
was the bound variable error?  Remember, we can't see what you are seeing.

http://danconia.org

--Untested--
#!/usr/bin/perl -w

use strict;
use DBI;
use DBD::Pg;

my $infile = $ARGV[0];

# no reason to reconnect for every line
my $dbh = DBI-connect(dbi:Pg:dbname=*, *, *) || die;

# statement should only be prepared once
# note use of placeholder ? character
my $sth = $dbh-prepare(UPDATE table SET email = '' WHERE email = ? )
|| die;

open INFILE, $infile or die Can't open file for reading: $!;
while ( INFILE ) {
   $sth-execute( $_ );
}
close INFILE;

$sth-finish;
$dbh-disconnect;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: escaping @

2005-07-18 Thread Wiggins d'Anconia
Lawrence Statton wrote:
On Mon, 2005-07-18 at 11:53, Wiggins d'Anconia wrote:

Charles Farinella wrote:

I'm sure this is very simple and I am overlooking something.  I want to
read a list of bad email addresses from a file and remove them from my
database.  

If I print $_, the email addresses are correct, if I try to remove them
from the db I get errors on just the characters before the @.


Are you sure those errors aren't coming from the DB?
 
 
 Use placeholder constants.  Like this
 
 - cut here -
 #!/usr/bin/perl
 use strict;
 use warnings; 
 use Data::Dumper;
 
 use DBI;
 
 our $DBH = DBI-connect( 'dbi:Pg:dbname=test', undef , undef ); 
 
 die no database unless $DBH; 
 
 while (DATA)
 {
 chomp;
 $DBH-do( qq {
   DELETE FROM email
   WHERE address = ?
   } , {} , $_ ) or print $DBH-errstr; 
 }


Careful with such advice, switching a statement from an update where you
set an empty string is *significantly* different than switching to a
delete. I even resisted the urge to switch the setting to '' to a NULL
as that technically may not fit with his data model.

Obviously from my other posts I agree about using placeholders, though I
don't agree with using a 'do' in a loop. TMTOWTDI.

http://danconia.org

 __DATA__
 Evil Spacey [EMAIL PROTECTED]
 - cut here -
 
 
 If you absolutely refuse to do this (and be prepared to suffer a life
 of SQL injection if you do so refuse) then at LEAST call $dbh-quote()
 on strings before you hand them off to DBI.
 
 
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: escaping in CGI.pm

2005-06-24 Thread Joshua Colson
Scott,

You're trying to use an ampersand in your URL. Ampersands are special
characters in URLs so you must escape it if you want it to be passed as
the actual character instead of carrying the special meaning.

See http://www.december.com/html/spec/esccodes.html

On Fri, 2005-06-24 at 12:51 -0700, Scott Taylor wrote:
 Grr... Arg...
 
 Hello all,
 
 I'm working on my first Perl/CGI database app and run into a bit of a snag:
 
 http://myserver/lseid.cgi?LeaseOPID=ADT89theCmd=EditIt
 
replace the preceding line with:

http://myserver/lseid.cgi?LeaseOPID=A%26DT89theCmd=EditIt

 this line finds the right data however, everything after the  in the
 LeaseOPID ($row-{leaseopid}) ADT89 gets truncated in this form line:
 textfield(-name='LeaseOPID',
   -value=$row-{leaseopid},
   -size=8,
   -maxlength=8),p,\nName: ,
 

-- 
Joshua Colson [EMAIL PROTECTED]
Sr. Systems Administrator
Giant Industries, Inc
P: (480) 585-8714
F: (480) 502-6641


signature.asc
Description: This is a digitally signed message part


Re: escaping in CGI.pm

2005-06-24 Thread Scott Taylor

Joshua Colson said:
 Scott,

 You're trying to use an ampersand in your URL. Ampersands are special
 characters in URLs so you must escape it if you want it to be passed as
 the actual character instead of carrying the special meaning.

 See http://www.december.com/html/spec/esccodes.html

As I said, I know that much, just how to do it using the CGI.pm or maybe
some other module maybe?

--
Scott

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: escaping in CGI.pm

2005-06-24 Thread Wiggins d'Anconia
Scott Taylor wrote:
 Joshua Colson said:
 
Scott,

You're trying to use an ampersand in your URL. Ampersands are special
characters in URLs so you must escape it if you want it to be passed as
the actual character instead of carrying the special meaning.

See http://www.december.com/html/spec/esccodes.html
 
 
 As I said, I know that much, just how to do it using the CGI.pm or maybe
 some other module maybe?
 
 --
 Scott
 

The common module provided for this task is URI::Escape, it is commonly
installed or available from CPAN.  Just to prevent you from needing to
look you will probably eventually need HTML::Entities too.

Good luck,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Escaping quotes in variable content

2004-05-12 Thread jon

 print form name=\test\ action=\http://www.somewhere.com\;\n;
 printinput type=\text\ name=\frage_text\ size=\100\
 value=\$frage_text\ /\n;
 print /form\n;

This wasn't really the question, but... 
If you have to write html within perl, use qq( ) instead of .
It's a lot easier to read, and much less error prone.

ie,
print qq(
form name=test action=http://www.somewhere.com;
input type=text name=frage_text size=100 value=$frage_text /
/form
);



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Escaping quotes in variable content

2004-05-12 Thread Edvaldo Barbosa Guimar�es
Try $frage_text =~ s/\/\\/g; I think it will work better this way. 

Edvaldo Guimarães
Marketing Support - Latin America
UGS PLM Solutions Brasil
An EDS Company
Tel.: +55-11-4224-7153
Fax: +55-11-4224-7107


-Original Message-
From: Ash Singh [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 11, 2004 11:44 AM
To: 'Jan Eden'; Perl Lists
Subject: RE: Escaping quotes in variable content


Try this:
input type=\text\ name=\frage_text\ size=\100\ value=\$frage_text\



-Original Message-
From: Jan Eden [mailto:[EMAIL PROTECTED]
Sent: 11 May 2004 03:59 PM
To: Perl Lists
Subject: Escaping quotes in variable content

Hi all,

how can I escape quotes within a variable's content? I use the following
directive to fill an HTML form:

input type=text name=frage_text size=100 value=$frage_text /


Unfortunately, if $frage_text contains a double quote, the browser will stop
displaying the string at that point.

I tried to escape the quotes in a Perl way

$frage_text =~ s//\\/g;

but that did not help.

 Any suggestion is appreciated.

 Thanks,

 Jan
--
Common sense is what tells you that the world is flat.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping quotes in variable content

2004-05-11 Thread David Dorward
On 11 May 2004, at 14:58, Jan Eden wrote:
how can I escape quotes within a variable's content? I use the 
following directive to fill an HTML form:
input type=text name=frage_text size=100 value=$frage_text /
Unfortunately, if $frage_text contains a double quote, the browser 
will stop displaying the string at that point.
I tried to escape the quotes in a Perl way
$frage_text =~ s//\\/g;
In HTML characters are 'escaped' by converting them to entities. 
entityName; Quote marks are quot;

You probably want to use escapeHTML() from the CGI module.

--
David Dorward
 http://dorward.me.uk/
http://blog.dorward.me.uk/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Escaping quotes in variable content

2004-05-11 Thread Jan Eden
Hi David,

David Dorward wrote on 11.05.2004:

On 11 May 2004, at 14:58, Jan Eden wrote:
how can I escape quotes within a variable's content? I use the
following directive to fill an HTML form: input type=text
name=frage_text size=100 value=$frage_text / Unfortunately,
if $frage_text contains a double quote, the browser will stop
displaying the string at that point. I tried to escape the quotes
in a Perl way $frage_text =~ s//\\/g;

In HTML characters are 'escaped' by converting them to entities.
entityName; Quote marks are quot;

You probably want to use escapeHTML() from the CGI module.

Doh. I have been working on the script for several hours now and forgot the most 
simple things about HTML.

Thanks,

Jan
-- 
Common sense is what tells you that the world is flat.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Escaping quotes in variable content

2004-05-11 Thread Ash Singh


Try this:
input type=\text\ name=\frage_text\ size=\100\ value=\$frage_text\



-Original Message-
From: Jan Eden [mailto:[EMAIL PROTECTED] 
Sent: 11 May 2004 03:59 PM
To: Perl Lists
Subject: Escaping quotes in variable content

Hi all,

how can I escape quotes within a variable's content? I use the following
directive to fill an HTML form:

input type=text name=frage_text size=100 value=$frage_text /


Unfortunately, if $frage_text contains a double quote, the browser will stop
displaying the string at that point.

I tried to escape the quotes in a Perl way

$frage_text =~ s//\\/g;

but that did not help.
 
 Any suggestion is appreciated.
 
 Thanks,
 
 Jan
-- 
Common sense is what tells you that the world is flat.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Escaping quotes in variable content

2004-05-11 Thread Ash Singh
This is better, replace the quotes with nothing and then build your input
tag.

#!/usr/bin/perl

use CGI;
use strict;

my $cgi = new CGI; print $cgi-header;
my $query = CGI::new();

my $frage_text= \Hello World\;

$frage_text =~ s///g;

print form name=\test\ action=\http://www.somewhere.com\;\n;
printinput type=\text\ name=\frage_text\ size=\100\
value=\$frage_text\ /\n;
print /form\n;

I hope this helps 
Regards Ash.



-Original Message-
From: Jan Eden [mailto:[EMAIL PROTECTED] 
Sent: 11 May 2004 04:21 PM
To: David Dorward; Perl Lists
Subject: Re: Escaping quotes in variable content

Hi David,

David Dorward wrote on 11.05.2004:

On 11 May 2004, at 14:58, Jan Eden wrote:
how can I escape quotes within a variable's content? I use the
following directive to fill an HTML form: input type=text
name=frage_text size=100 value=$frage_text / Unfortunately,
if $frage_text contains a double quote, the browser will stop
displaying the string at that point. I tried to escape the quotes
in a Perl way $frage_text =~ s//\\/g;

In HTML characters are 'escaped' by converting them to entities.
entityName; Quote marks are quot;

You probably want to use escapeHTML() from the CGI module.

Doh. I have been working on the script for several hours now and forgot the
most simple things about HTML.

Thanks,

Jan
-- 
Common sense is what tells you that the world is flat.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Escaping quotes in variable content

2004-05-11 Thread Wiggins d Anconia
Please bottom post...

 This is better, replace the quotes with nothing and then build your input
 tag.
 

Better?  You have destroyed the data.  Stay away from my information
with your substituitions.

[snip code that should not be used in production]

 
 I hope this helps 

Anyone reading the archive, please don't do this.  escapeHTML or
HTML::Entities should do very well.

http://danconia.org

 
 
 -Original Message-
 From: Jan Eden [mailto:[EMAIL PROTECTED] 
 Sent: 11 May 2004 04:21 PM
 To: David Dorward; Perl Lists
 Subject: Re: Escaping quotes in variable content
 
 Hi David,
 
 David Dorward wrote on 11.05.2004:
 
 On 11 May 2004, at 14:58, Jan Eden wrote:
 how can I escape quotes within a variable's content? I use the
 following directive to fill an HTML form: input type=text
 name=frage_text size=100 value=$frage_text / Unfortunately,
 if $frage_text contains a double quote, the browser will stop
 displaying the string at that point. I tried to escape the quotes
 in a Perl way $frage_text =~ s//\\/g;
 
 In HTML characters are 'escaped' by converting them to entities.
 entityName; Quote marks are quot;
 
 You probably want to use escapeHTML() from the CGI module.
 
 Doh. I have been working on the script for several hours now and
forgot the
 most simple things about HTML.
 
 Thanks,
 
 Jan



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Escaping quotes in variable content

2004-05-11 Thread Jan Eden
[EMAIL PROTECTED] wrote on 11.05.2004:

 print form name=\test\ action=\http://www.somewhere.com\;\n;
 printinput type=\text\ name=\frage_text\ size=\100\
 value=\$frage_text\ /\n;
 print /form\n;

This wasn't really the question, but... 
If you have to write html within perl, use qq( ) instead of .
It's a lot easier to read, and much less error prone.

ie,
print qq(
form name=test action=http://www.somewhere.com;
input type=text name=frage_text size=100 value=$frage_text /
/form
);


I did use qq{} quoting within the Perl script in the first place. My problem was 
related to quoting within a double-quoted HTML attribute, e.g.

input value=This quot;personquot; /

Thanks,

Jan
-- 
Either this man is dead or my watch has stopped. - Groucho Marx

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Escaping

2004-04-08 Thread James Edward Gray II
On Apr 8, 2004, at 4:30 PM, [EMAIL PROTECTED] wrote:

Is there any quick way of parsing a string like:
This,Is,A,String,\,,With,A,Comma
Into a list
(This, Is, A, String, ,, With, A, Comma)
Basically, how can I split it by commas, except when it is escaped.
How about:

my @fields = split m/(?!\\),/, 'This,Is,A,String,\\,,With,A,Comma';
print join('~', @fields), \n;
That's a negative lookbehind assertion in the regex I fed split().

If you made the original string format, you might consider using the 
CSV file format instead.  Then you can even use modules to do all the 
tricky stuff.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Escaping

2003-08-08 Thread Kristofer Hoch
Marcus,
  You are going to have to URL escape it.  Review URI::Escape...
http://theoryx5.uwinnipeg.ca/CPAN/data/URI/URI/Escape.html

Thanks,
Kristofer

=
-BEGIN GEEK CODE BLOCK-
Version: 3.12
GIT d s+:++ a C++ UL++ US+ P+++ L++ 
W+++ w PS PE t++ b+ G e r+++ z
--END GEEK CODE BLOCK--

__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Escaping Ampersands in XML

2003-01-16 Thread Jenda Krynicky
From: Ben Siders [EMAIL PROTECTED]
 I've got a real easy one here (in theory).  I have some XML files that
 were generated by a program, but generated imperfectly.  There's some
 naked ampersands that need to be converted to amp;.  I need a regexp
 that will detect them and change them.  Sounds easy enough.
 
 The pattern I want to match is an ampersand that is NOT immediately
 followed by a few characters and then a semicolon.  Any ideas?
 
 This is the best I've come up with so far.  It should match an
 ampersand whose following characters, up to five, are not semicolons. 
 I don't feel that this is a great solution.  I'm hoping the community
 can think of a better one.
 
 $line =~ s/\[^;]{,5}/\amp;/g;
 
 I'm hoping that'll match something like:  tagBlah data /tag,
 but NOT match tagBlah amp;/tag.
 
 I'm not sure if I'm on the right track here.  I also can't match other
 escaped characters such as: tagCopyright copy; 2003/tag.

For something similar I use this (I have it inside a module):

use HTML::Entities;
sub PolishHTML {
my $str = shift;
if ($AllowXHTML) {
$str =~ 
s{(.*?)(\w+;|#\d+;|\w[\w\d]*(?:\s+\w[\w\d]*(?:\s*=\s*(?:[^ 
'\s]+|(?:'[^']*')+|(?:[^]*)+))?)*\s*/?|/\w[\w\d]*|$)}
 {HTML::Entities::encode($1, '^\r\n\t !\#\$%\\'-;=?-
~').$2}gem;
} else {
$str =~ 
s{(.*?)(\w+;|#\d+;|\w[\w\d]*(?:\s+\w[\w\d]*(?:\s*=\s*(?:[^ 
'\s]+|(?:'[^']*')+|(?:[^]*)+))?)*\s*|/\w[\w\d]*|$)}
 {HTML::Entities::encode($1, '^\r\n\t !\#\$%\\'-;=?-
~').$2}gem;
}
return $str;
}

It escapes the ,  and  that doesn't seem to belong to HTML 
entities or tags.
If you would use this over the XML you would want to set the 
$AllowXHTML (or just use the first branch).


If all you want is to process the ampersand you may want something 
like this:

$line =~ s/(?!\w+;|#\d+;)/amp;/g;


Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Escaping Ampersands in XML

2003-01-16 Thread Jenda Krynicky
 Toby Stuart wrote:
 Try this one:
 
   s/(?!\w+;)/amp;/g

Problem is that this will break things like
#64;

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Escaping Ampersands in XML

2003-01-16 Thread Rob Dixon
Jenda Krynicky wrote:
 Toby Stuart wrote:
 Try this one:

  s/(?!\w+;)/amp;/g

 Problem is that this will break things like
 #64;


Why not just:

s/(?!amp;)/amp;/g

i.e. change every ampersand that isn't followed by 'amp;' into amp;

Rob





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Escaping Ampersands in XML

2003-01-15 Thread Toby Stuart


 -Original Message-
 From: Ben Siders [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, January 16, 2003 7:38 AM
 To: Perl
 Subject: Escaping Ampersands in XML
 
 
 I've got a real easy one here (in theory).  I have some XML 
 files that 
 were generated by a program, but generated imperfectly.  There's some 
 naked ampersands that need to be converted to amp;.  I need a regexp 
 that will detect them and change them.  Sounds easy enough.
 
 The pattern I want to match is an ampersand that is NOT immediately 
 followed by a few characters and then a semicolon.  Any ideas?
 
 This is the best I've come up with so far.  It should match 
 an ampersand 
 whose following characters, up to five, are not semicolons.  I don't 
 feel that this is a great solution.  I'm hoping the community 
 can think 
 of a better one.
 
 $line =~ s/\[^;]{,5}/\amp;/g;

Try this one:

  s/(?!\w+;)/amp;/g



 
 I'm hoping that'll match something like:  tagBlah data 
 /tag, but 
 NOT match tagBlah amp;/tag.
 
 I'm not sure if I'm on the right track here.  I also can't 
 match other 
 escaped characters such as: tagCopyright copy; 2003/tag.
 
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Escaping characters

2002-06-04 Thread Felix Geerinckx

on Tue, 04 Jun 2002 17:14:54 GMT, Barry Jones wrote:

 Hi,
  I'm trying to do a patter match for everything contained within
 {{ stuff }}.  Now I've gotten this to work just fine with ** stuff **,
 ^^ and a several others, but I can't get curly braces to work and I have
 no idea why.  I've tried escaping them with \ and not doing and what
 have you but it just won't work.
 [...]
 $body =~ s/\{\{(.*?)\}\}/\b\$1\\/b\/g;

$body = It {{works}} for {{me}};
$body =~ s/{{(.*?)}}/b$1\/b/g;
print $body; # prints It bworks/b for bme/b

The escape chars on {} are not necessary.
 
What is your input, and how do you expert your output to look like?

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Escaping characters

2002-06-04 Thread Bob Showalter



 -Original Message-
 From: Barry Jones [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, June 04, 2002 1:15 PM
 To: Beginners @ Perl (E-mail)
 Subject: Escaping characters
 
 
 Hi,
   I'm trying to do a patter match for everything contained within
 {{ stuff }}.  Now I've gotten this to work just fine with ** stuff **,
 ^^ and a several others, but I can't get curly braces to work 
 and I have
 no idea why.  I've tried escaping them with \ and not doing and what
 have you but it just won't work.  Here's the code, maybe you 
 can help me
 out.  Note: the bold tags are just there while I'm testing 
 it, not what
 it's going to be used for.
 
  $body =~ s/\{\{(.*?)\}\}/\b\$1\\/b\/g;

Hmm, works fine for me:

   $body = Hello {{bold}} world!\n;
   $body =~ s/\{\{(.*?)\}\}/\b\$1\\/b\/g;
   print $body;

Prints: Hello bbold/b world!

(n.b. you don't need to escape the  and )

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Escaping characters

2002-06-04 Thread Barry Jones

Thanks.  It turns out that wasn't my problem at all.  I had a \n
character midway through and I didn't know about /gs for those
characters.  It was the data, not the code.

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 04, 2002 2:54 PM
To: Barry Jones; Beginners @ Perl (E-mail)
Subject: RE: Escaping characters




 -Original Message-
 From: Barry Jones [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, June 04, 2002 1:15 PM
 To: Beginners @ Perl (E-mail)
 Subject: Escaping characters
 
 
 Hi,
   I'm trying to do a patter match for everything contained within
 {{ stuff }}.  Now I've gotten this to work just fine with ** stuff **,
 ^^ and a several others, but I can't get curly braces to work 
 and I have
 no idea why.  I've tried escaping them with \ and not doing and what
 have you but it just won't work.  Here's the code, maybe you 
 can help me
 out.  Note: the bold tags are just there while I'm testing 
 it, not what
 it's going to be used for.
 
  $body =~ s/\{\{(.*?)\}\}/\b\$1\\/b\/g;

Hmm, works fine for me:

   $body = Hello {{bold}} world!\n;
   $body =~ s/\{\{(.*?)\}\}/\b\$1\\/b\/g;
   print $body;

Prints: Hello bbold/b world!

(n.b. you don't need to escape the  and )

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Escaping HTML tags

2002-03-23 Thread root


I'll gotta stop sending  over-caffinated emails...wow, -w works...






Scott Wahlstrom wrote:

 Severe newbie that would RTFM if I would have brought it home and i'm not asking the 
right monestary search strings so i humbly ask for your help...

 i'll go get going on a fresh pot of coffee...anyhew - snippet away...

 #!/perl

 

 open(OUTPUT, /www/html/toc.html);

 print (OUTPUT htmlheadtitleTOC - Operations Center/title
 meta http-equiv=Content-Type content=text/html; 
charset=iso-8859-1/head
 body bgcolor=#FF text=#00div align=centerh1Terrabyte 
Operations Center
 /h1table width=89% border=0 height=474tr bordercolor=#00
 td width=50% height=53div align=centerbNodes Responding to ICMP 
Queries/b
 /div/tdtd width=50% height=53div align=centerbUnresponsive 
Nodes/b/div
 /td/trtr bordercolor=#00td width=50%font size=-1;

 foreach $good_node (@good_nodes){
 chomp($good_node);
 print (OUTPUT, p$good_node\/p;
 }

 print (OUTPUT, \/font\/tdtd width=50%font size=-1;

 foreach $bad_node (@bad_nodes) {
 chomp($bad_node);
 print (OUTPUT, p$bad_node\/p;
 }

 print (OUTPUT, \/font\/td\/tr\/tablep align=left\/pp 
align=left\/p
 hr width=80%p align=centerMonitoring $counter 
nodes.\/p\/div\/body\/html);

 Thanx,

 -sunny


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Escaping HTML tags

2002-03-23 Thread bob ackerman

easiest i would think is here-doc.
I like:

open (OUTP, hdtst) or die no can open\n;
print OUTP HEHE;
abc def
ghi jkl
HEHE


On Saturday, March 23, 2002, at 08:15  PM, Scott Wahlstrom wrote:


 Severe newbie that would RTFM if I would have brought it home and i'm not 
 asking the right monestary search strings so i humbly ask for your help..
 .

 i'll go get going on a fresh pot of coffee...anyhew - snippet away...

 #!/perl

 

 open(OUTPUT, /www/html/toc.html);

 print (OUTPUT htmlheadtitleTOC - Operations Center/title
   meta http-equiv=Content-Type content=text/html; 
 charset=iso-8859-1/head
   body bgcolor=#FF text=#00div 
 align=centerh1Terrabyte Operations Center
   /h1table width=89% border=0 height=474tr 
 bordercolor=#00
   td width=50% height=53div align=centerbNodes Responding 
 to ICMP Queries/b
   /div/tdtd width=50% height=53div 
 align=centerbUnresponsive Nodes/b/div
   /td/trtr bordercolor=#00td width=50%font size=-1;

   foreach $good_node (@good_nodes){
   chomp($good_node);
   print (OUTPUT, p$good_node\/p;
   }

   print (OUTPUT, \/font\/tdtd width=50%font size=-1;

   foreach $bad_node (@bad_nodes) {
   chomp($bad_node);
   print (OUTPUT, p$bad_node\/p;
   }

   print (OUTPUT, \/font\/td\/tr\/tablep align=left\/pp 
 align=left\/p
   hr width=80%p align=centerMonitoring $counter 
 nodes.\/p\/div\/body\/html);

 Thanx,

 -sunny


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Escaping special characters for regular expressions

2002-02-28 Thread eric-perl

On Wed, 27 Feb 2002, W  P wrote:
 I have a CGI script which takes two strings. It searches for the first
 string in a file, replacing it with the second one.  This file isn't
 really important, more for fun, so I'm not too worried about people
 deleting the whole file if they actually type out the contents as the
 first string.  However, I would like for things like . and \w to
 search for those string literals, rather than for any character or any
 word character, respectively.  Is there some function or capability
 which escapes all special characters in a string before it is passed
 to a regular expression?

To escape the '\w' just preprend another '\'.
To escape the '.' just prepent it with '\'.

e.g., $x =~ /\\w/ searches for a single back-slash followed by w.
  $x =~ /\./ searches for a single period.

-- 
Eric P.
Los Gatos, CA


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Escaping special characters for regular expressions

2002-02-28 Thread W P

i don't want to just escape those characters.  they were merely examples.  i
was hoping maybe there was some built-in way to escape ALL the characters
that mean anything to regular expressions.  it just seemed like a lot of
work to put a \ before all the characters that regular expressions recognize
as having special meanings.  so i guess you're saying that i have to escape
them all separately by myself?



 To escape the '\w' just preprend another '\'.
 To escape the '.' just prepent it with '\'.

 e.g., $x =~ /\\w/ searches for a single back-slash followed by w.
   $x =~ /\./ searches for a single period.

 --
 Eric P.
 Los Gatos, CA



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Escaping special characters for regular expressions

2002-02-28 Thread Curtis Poe

--- W  P [EMAIL PROTECTED] wrote:
 i don't want to just escape those characters.  they were merely examples.  i
 was hoping maybe there was some built-in way to escape ALL the characters
 that mean anything to regular expressions.

Well, technically, *all* characters mean something to a regex.  I assume that you want 
to escape
metacharacters which transform the behavior of the regular expressions.

perldoc -f quotemeta

quotemeta will escape all non-word characters (prepend them with a backslash) which 
should match
your needs.  If that's too general, start looking at qr// and related functions.

Cheers,
Curtis Ovid Poe

=
Ovid on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A

__
Do You Yahoo!?
Yahoo! Greetings - Send FREE e-cards for every occasion!
http://greetings.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Escaping special characters for regular expressions

2002-02-28 Thread Rob Roudebush


 Wouldn't single quotes do the trick?
  Curtis Poe [EMAIL PROTECTED] wrote: --- W P wrote:
 i don't want to just escape those characters. they were merely examples. i
 was hoping maybe there was some built-in way to escape ALL the characters
 that mean anything to regular expressions.

Well, technically, *all* characters mean something to a regex. I assume that you want 
to escape
metacharacters which transform the behavior of the regular expressions.

perldoc -f quotemeta

quotemeta will escape all non-word characters (prepend them with a backslash) which 
should match
your needs. If that's too general, start looking at qr// and related functions.

Cheers,
Curtis Ovid Poe

=
Ovid on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A

__
Do You Yahoo!?
Yahoo! Greetings - Send FREE e-cards for every occasion!
http://greetings.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
Do You Yahoo!?
Yahoo! Greetings - Send FREE e-cards for every occasion!


RE: escaping v$session

2001-06-25 Thread Stephen Neu

Try 'v$session' instead of v$session
The single quote doesn't interpolate variables like the double-quote.

From perldoc perlop

Customary  Interpolates

''  no

  yes

``  yes

qw{}no

//  yes

 
:-Original Message-
:From: Yacketta, Ronald [mailto:[EMAIL PROTECTED]]
:Sent: Monday, June 25, 2001 10:45 AM
:To: Beginners (E-mail)
:Subject: escaping v$session
:
:
:Folks,
:
:I am trying to get some stats from a oracle DB (cant use DBI, 
:dont ask why)
:I need to escape out v$session, but cant seem to find the 
:right magic :(
:I have tried
:v\$session and get the ugly so such table or view
:
:Ron
:



RE: escaping v$session

2001-06-25 Thread Yacketta, Ronald



 -Original Message-
 From: Stephen Neu [mailto:[EMAIL PROTECTED]]
 Sent: Monday, June 25, 2001 12:04 PM
 To: Perl Beginners (E-mail)
 Subject: RE: escaping v$session
 
 
 Try 'v$session' instead of v$session
 The single quote doesn't interpolate variables like the double-quote.

this is what I am trying todo

@active = qx(
sqlplus -S $RTDUSER/$RTDPASS\@$RTD_ORACLE_SID -!
select count(distinct(process)) ACTIVE from --- v$session ---
where last_call_et  60 and
process in (select ltrim(rtrim(to_char(process_id) )) from session_list);
quit
!
);

I have tried v\$session and get
ORA-00903: invalid table name
'v$session' gives
Global symbol $session requires explicit package name at betadiag.pl line
238.
Execution of betadiag.pl aborted due to compilation errors.
and 'v\$sessions gives the same as v\$session

so, what is the magic to this madness?

Ron



RE: escaping v$session

2001-06-25 Thread Stephen Neu

:@active = qx(
:sqlplus -S $RTDUSER/$RTDPASS\@$RTD_ORACLE_SID -!
:select count(distinct(process)) ACTIVE from --- v$session ---
:where last_call_et  60 and
:process in (select ltrim(rtrim(to_char(process_id) )) from 
:session_list);
:quit
:!
:);

Ok, so you're using qx(foo), which is the same (appx.) as `foo`, (with
backticks).  According to the perlop doc...

Customary  GenericMeaningInterpolates
`` qx{}   Commandyes (unless '' is delimiter)

When you use qx(), (pardon me if you already know this), you are telling
Perl that you want to use parentheses instead of backticks to delimit your
command.

my @gotback = `foo`; #stores output from foo
   # in @gotback
my @output  = qx(foo); #does the same thing
 # with @output

You can use whatever you want with qx.  ^^, (), {}, [], whatever.
Evidently, if you use single quotes, qx'foo', it will run your 'foo' without
trying to translate $session into a value from a variable called $session.

@active = qx' #not '(' ---
sqlplus -S $RTDUSER/$RTDPASS\@$RTD_ORACLE_SID -!
select count(distinct(process)) ACTIVE from v$session
where last_call_et  60 and
process in (select ltrim(rtrim(to_char(process_id) )) from session_list);
quit
!
'; #not ')' ---

...and I think that's what you want. Correct me if I'm wrong. :-)



RE: escaping v$session

2001-06-25 Thread Chas Owens

On 25 Jun 2001 12:15:15 -0400, Yacketta, Ronald wrote:
snip /
 this is what I am trying todo
 
 @active = qx(
 sqlplus -S $RTDUSER/$RTDPASS\@$RTD_ORACLE_SID -!
 select count(distinct(process)) ACTIVE from --- v$session ---
 where last_call_et  60 and
 process in (select ltrim(rtrim(to_char(process_id) )) from session_list);
 quit
 !
 );
snip /

How about:

{
my $temp = 
sqlplus -S $RTDUSER/$RTDPASS\@$RTD_ORACLE_SID -!
select count(distinct(process)) ACTIVE from  . 'v$session' . 
where last_call_et  60 and
process in (select ltrim(rtrim(to_char(process_id))) from session_list);
quit
!
);

@active = `$temp`;
}
 
--
Today is Sweetmorn, the 30th day of Confusion in the YOLD 3167
All Hail Discordia!





RE: escaping v$session

2001-06-25 Thread Stephen Neu

:@active = qx(
:sqlplus -S $RTDUSER/$RTDPASS\@$RTD_ORACLE_SID -!
:select count(distinct(process)) ACTIVE from --- v$session ---
:where last_call_et  60 and
:process in (select ltrim(rtrim(to_char(process_id) )) from 
:session_list);
:quit
:!
:);

Oh... Didn't see the other variables you were trying to interpolate... oops.
Mine won't work. :-)




RE: escaping v$session

2001-06-25 Thread Chas Owens

On 25 Jun 2001 12:57:39 -0400, Yacketta, Ronald wrote:
 This one was really close :)
 I had to change
  select count(distinct(process)) ACTIVE from  . 'v$session' . 
 
 to
  select count(distinct(process)) ACTIVE from  . 'v\$session' . 
 
 and it worked!
 
 Thanxs everyone!
 
 Ron
 

What version of Perl are you using?  I was certain the 'v$session' would
not interpolate.  Have I failed to understand how quoting works in Perl?
can someone tell me where my understanding has failed?  

--
Today is Sweetmorn, the 30th day of Confusion in the YOLD 3167
Hail Eris!





Re: escaping v$session

2001-06-25 Thread Chas Owens

On 25 Jun 2001 09:47:08 -0800, Michael Fowler wrote:
 On Mon, Jun 25, 2001 at 01:09:51PM -0400, Chas Owens wrote:
  On 25 Jun 2001 12:57:39 -0400, Yacketta, Ronald wrote:
select count(distinct(process)) ACTIVE from  . 'v$session' . 
 
select count(distinct(process)) ACTIVE from  . 'v\$session' . 
  
  What version of Perl are you using?  I was certain the 'v$session' would
  not interpolate.  Have I failed to understand how quoting works in Perl?
  can someone tell me where my understanding has failed?  
 
 It hasn't, 'v$session' won't be interpolated by Perl; this is the way
 interpolation (or non-interpolation) has worked in Perl from at least perl
 4.  My guess is the database itself is interpolating the variable.
 
 
 Michael
 --
 Administrator  www.shoebox.net
 Programmer, System Administrator   www.gallanttech.com
 --

Well if that is the case then the original code should work 
if you add an additional \\ to it:

@active = qx(
sqlplus -S $RTDUSER/$RTDPASS\@$RTD_ORACLE_SID -!
select count(distinct(process)) ACTIVE from v\\\$session
where last_call_et  60 and
process in (select ltrim(rtrim(to_char(process_id) )) from 
session_list);
quit
!

--
Today is Sweetmorn, the 30th day of Confusion in the YOLD 3167
All Hail Discordia!





Re: escaping v$session

2001-06-25 Thread Michael Fowler

On Mon, Jun 25, 2001 at 02:09:59PM -0400, Chas Owens wrote:
 @active = qx(
 sqlplus -S $RTDUSER/$RTDPASS\@$RTD_ORACLE_SID -!
 select count(distinct(process)) ACTIVE from v\\\$session
 where last_call_et  60 and
 process in (select ltrim(rtrim(to_char(process_id) )) from 
 session_list);
 quit
 !

Oh, I wasn't aware this was going through the shell (I hadn't been paying
attention to the discussion).  That's what's doing the interpolation of
$session.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--



Re: escaping v$session

2001-06-25 Thread Michael Fowler

On Mon, Jun 25, 2001 at 02:24:21PM -0400, Chas Owens wrote:
 Let me see if I have this straight:
 
 Perl was ignoring $session because of the \ and then passing the output
 to the shell (stripping the \).

Yes.

 
 The shell saw $session so it tried to replace it with the enviromental
 variable $session (which was empty) so Oracle saw:

No, it tried to replace it with the variable $session.  Shells have normal
variables as well as environmental ones.


 select count(distinct(process)) ACTIVE from v
 where last_call_et  60 and
 process in (select ltrim(rtrim(to_char(process_id) )) from 
 session_list);

Yes.

 
 Hence the error.  If this is the case then using v\\\$session should
 result in:
 
 Perl outputs v\$session
 Shell outputs v$session
 Oracle sees what it expects.

Yes, though passes would be a better term than outputs.


This type of thing always makes me wish for a list form of qx//, akin to the
list forms of exec and system.  Something along the lines of:

list_qx(sqlplus, 'select count ... v$session ...');

Of course, you can get the equivalent in a variety of ways, but nothing
quite beats a core function (be it builtin, or in a core module).
 

Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--