[16562] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3974 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 10 11:05:32 2000

Date: Thu, 10 Aug 2000 08:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965919914-v9-i3974@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 10 Aug 2000     Volume: 9 Number: 3974

Today's topics:
    Re: "more" with perl <elephant@squirrelgroup.com>
    Re: "more" with perl <nickco3@yahoo.co.uk>
        ANNOUNCE: Quantum::Superpositions 1.02 (Damian Conway)
    Re: Cant figure this out. <pavel@gingerall.cz>
    Re: Cant figure this out. <bart.lateur@skynet.be>
    Re: CGI / Pearl Interfacing w/ Dos Program Question vagabond_nomad@my-deja.com
    Re: CGI / Pearl Interfacing w/ Dos Program Question <jbroz@transarc.com>
    Re: CGI.pm not passing ampersands properly <flavell@mail.cern.ch>
    Re: CGI/Pearl Interfacing w/ DOS Program Question vagabond_nomad@my-deja.com
    Re: CGI/Pearl Interfacing w/ DOS Program Question <mjcarman@home.com>
    Re: cleaning shell screen <amonotod@netscape.net>
    Re: Convert URLs to links (Keith Calvert Ivey)
        Date convert bakhshek@essilor.fr
        DBI question from a Newbie - handling Nulls gavin_gibson@my-deja.com
        Decrypt program sankarmukh@my-deja.com
    Re: Difference between a .cgi file and a .pl file? <flavell@mail.cern.ch>
        Example in FAQ (Andreas Zielke)
    Re: Example in FAQ <aqumsieh@hyperchip.com>
        Exporting variables from packages <daniel@blackomega.com>
    Re: Exporting variables from packages <bart.lateur@skynet.be>
    Re: GREP - type of script... <bart.lateur@skynet.be>
    Re: help for Insert rows into table by DBI (Rafael Garcia-Suarez)
    Re: help w/ regular expression <kolibrie@southernvirginia.edu>
    Re: Help with quotewords troylachinski@my-deja.com
    Re: Help with quotewords <elephant@squirrelgroup.com>
        IO::File and file handles <hotrock@freenetname.co.uk>
    Re: IO::File and file handles <bart.lateur@skynet.be>
    Re: Large-File Reformatting Problem (Regexp gurus, et a (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 10 Aug 2000 10:26:16 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: "more" with perl
Message-Id: <MPG.13fd20a8c197b54498968f@localhost>

Javier Hijas wrote ..
>how can I display paged information with Perl?

just write a loop that outputs a line at a time .. but have it pause 
after X lines where X = the number of lines in a screen (get it from the 
environment - or guess it - or ask the user for it)

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Thu, 10 Aug 2000 14:26:02 +0100
From: Nick Condon <nickco3@yahoo.co.uk>
Subject: Re: "more" with perl
Message-Id: <3992AD6A.B60460BF@yahoo.co.uk>

Javier Hijas wrote:

> how can I display paged information with Perl?

Pipe it to more?:
 perl script | more

or in your script:
open (STDOUT, "| more") or warn "Can't run more: $!\n";



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

Date: 10 Aug 2000 00:20:24 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: ANNOUNCE: Quantum::Superpositions 1.02
Message-Id: <sp55gm30n4t103@corp.supernews.com>
Keywords: perl, module, release

==============================================================================
              Release of version 1.02 of Quantum::Superpositions
==============================================================================


NAME
    Quantum::Superpositions - QM-like superpositions for Perl

DESCRIPTION

    The Quantum::Superpositions module provides a new scalar data
    structure: the superposition. In a metaphor drawn from quantum
    mechanics, superpositions store a collection of values by overlaying
    them in parallel superimposed states within a single scalar
    variable. Which allows for cool stuff like:

        use Quantum::Superpositions;

        if ($x == any($a, $b, $c) { ...  }

        while ($nextval < all(@thresholds) { ... }

        $max = any(@value) < all(@values);

AUTHOR
    Damian Conway (damian@conway.org)

COPYRIGHT
    Copyright (c) 1997-2000, Damian Conway. All Rights Reserved. This module
    is free software. It may be used, redistributed and/or modified under
    the terms of the Perl Artistic License (see
    http://www.perl.com/perl/misc/Artistic.html)


==============================================================================

CHANGES IN VERSION 1.02


	- Fixed 5.6.0 compatibility

	- Added ability to superimpose subroutine references.


==============================================================================

AVAILABILITY

Quantum::Superpositions has been uploaded to the CPAN
and is also available from:

	http://www.csse.monash.edu.au/~damian/CPAN/Quantum-Superpositions.tar.gz

==============================================================================




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

Date: Thu, 10 Aug 2000 10:02:04 +0200
From: Pavel Hlavnicka <pavel@gingerall.cz>
Subject: Re: Cant figure this out.
Message-Id: <3992617C.5080404@gingerall.cz>

This RE solves the puzzle:

$c="a"; #or another character

s/$c[^$c]*$//


psycho wrote:

> Easily put, need to be able to cut the last part of a scarlar at
> a determind character.  There would be more then of these
> characters, but the last one and all data after that character
> is to be deleted.
> 
> 
> -----------------------------------------------------------
> 
> Got questions?  Get answers over the phone at Keen.com.
> Up to 100 minutes free!
> http://www.keen.com
> 
> 



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

Date: Thu, 10 Aug 2000 13:10:56 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Cant figure this out.
Message-Id: <4ea5pso5fgtgbekumsjosqr9erbr1dskj5@4ax.com>

Uri Guttman wrote:

>why the assigment? just use s///
>
>	$var =~ s/(.*)#/$1/ ;

	^var =~ s/(.*)#.*/$1/;

You don't want to delete just that character.

-- 
	Bart.


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

Date: Thu, 10 Aug 2000 12:27:08 GMT
From: vagabond_nomad@my-deja.com
Subject: Re: CGI / Pearl Interfacing w/ Dos Program Question
Message-Id: <8mu72p$fdv$1@nnrp1.deja.com>


> And, finally, don't bug the regulars on comp.lang.perl.misc with
> questions about cgi.  Post those to
> comp.infosystems.www.authoring.cgi.
>
> Jon (also a newbie)
>

Jon, I'm glad you brought this up.  I've already tried to connect to the
site you listed but am unable.  I've tried both as a regular url to an
HTTP site, and also as news:comp.infosystems.www.authoring.cgi.  When as
a news site, I am prompted for a username and password.  If you can tell
me how to access this site, I'd be more than happy to check it out as
well.

Lastly, if this is a site about Perl, then why can't I ask people
questions about CGI?  From my understanding, they are both closely
related.

Peace.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 10 Aug 2000 15:21:58 +0100
From: "Joe_Broz@transarc.com" <jbroz@transarc.com>
Subject: Re: CGI / Pearl Interfacing w/ Dos Program Question
Message-Id: <3992BA86.BAC96CF0@transarc.com>

vagabond_nomad@my-deja.com wrote:
> 
> I am very, very, very new to CGI / Pearl, so I apologize in advance for my
> vast ignorance on this subject.  My task is to find a way interface a CGI
> program with a DOS program sitting on a UNIX server.  Here are the specifics:
> 

"a DOS program sitting on a UNIX server" ?? What do you mean?

It's perl not what you've written.


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

Date: Thu, 10 Aug 2000 13:09:45 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI.pm not passing ampersands properly
Message-Id: <Pine.GHP.4.21.0008101232060.2283-100000@hpplus03.cern.ch>

On Thu, 10 Aug 2000, Keith Calvert Ivey wrote:

> The WebDragon <nospam@nospam.com> wrote:
> 
> >Officially the word is that & should be written as &amp; not %26 
> >according to the html 4.0 spec and previous. Any HTML Validator will 
> >properly report this. (cf. iCab <http://www.icab.de/>, or the w3 
> >validator at <http://validator.w3.org/>

(I'm attempting to clarify this, but if I seem to be flogging a dead
camel, just ignore me...)

> I wasn't suggesting that the & should be written as %26.

No, certainly the user should not do that themselves when typing into
a form's text input field (nor for that matter into a URL dialog
window etc.).
 
>  I was
> saying that the browser would convert it to %26 before sending
> the data to the server. 

Absolutely.

> You are correct that & in the value of
> the VALUE attribute of an INPUT tag -- or anywhere else in an
                                            ^^^^^^^^
> HTML document -- should be represented as &amp; 

Almost...

If you're trying to include an ampersand as data in an HREF, then you
still want URL-encoding.  For example if you want to mimic the effect
of this form:

<form action="http://some.host/cgi-bin/some-script">
<input name=msg value="Mom&amp;Pop">
                          ^^^^^
<input name=reg value="yes">
</form>

, which corresponds to the user typing "Mom&Pop" into the input field,
then you need an HREF like this:

href="http://some.host/cgi-bin/some-script?msg=Mom%26Pop&amp;reg=yes"
                                                  ^^^

(monospaced font needed for viewing this posting!).

cheers  (which is why I advocated remaining calm and working carefully
through the _appropriate_ rules for each specific situation ;-)



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

Date: Thu, 10 Aug 2000 12:38:56 GMT
From: vagabond_nomad@my-deja.com
Subject: Re: CGI/Pearl Interfacing w/ DOS Program Question
Message-Id: <8mu7p1$fsb$1@nnrp1.deja.com>


> The last couple of steps, at least, are easy. You want the CGI.pm
> module. You can find it at CPAN if you don't have it installed
> already.
> It has all the functionality you should need for the web side of your
> interface. Between it's documentation and the FAQ, you should be able
> to
> figure that part out.
>

Thanks for all your suggestions, Michael.  You've been really cool.
With regard to CPAN, I assume you mean www.CPAN.com?  Thanks again.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 10 Aug 2000 08:11:04 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: CGI/Pearl Interfacing w/ DOS Program Question
Message-Id: <3992A9E8.14D14586@home.com>

vagabond_nomad@my-deja.com wrote:
> 
> With regard to CPAN, I assume you mean www.CPAN.com?

Not quite: www.cpan.org

> Thanks again.

You're welcome.

-mjc


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

Date: Thu, 10 Aug 2000 13:49:51 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: cleaning shell screen
Message-Id: <8mubts$j68$1@nnrp1.deja.com>

In article <399700f3.4277923@news.newsguy.com>,
  kcivey@cpcug.org (Keith Calvert Ivey) wrote:
> amonotod <amonotod@netscape.net> wrote:
<snip some of my code that Keith didn't like>
> Not particularly.  I happen to be on Windows 95 at the moment.
> You might want to consult perlvar to find out about $^O.
>
Point taken.  How's this?

#!perl -w
use strict;
my %oscls = ("MSWin32", "cls", "solaris", "clear");
print "clearing the screen...\n";
sleep 5;
foreach my $oskey (keys %oscls) {
  $_ = $^O;
  if (m/$oskey/) {
    system "$oscls{$oskey}\n";
    print "$^O...\n";
    print "\nThere now, isn't that nice?\n";
    exit;
  }
}
print "Hmmmm, no match for $^O, but don't cry, just add it in.\n";
exit;

> --
> Keith C. Ivey <kcivey@cpcug.org>
> Washington, DC
>

amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 10 Aug 2000 11:29:06 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Convert URLs to links
Message-Id: <39a5902f.40951288@news.newsguy.com>

"Fernando" <fm@via-rs.net> wrote:

>$corpo =~ s!(\b(http://|www\.)[\w./]+\w)!<a href=$1>$1</a>!gi;
>
>I used the \b (I learned today about that thing) to avoid the "xwww" or
>"xhttp".
>[\w./]+ to the core of the link.
>\w to the last character of the link.

For a quick-and-dirty solution, using \S for the core of the URL
and [\w/] for the end would work better.  Your regex stops the
URL at lots of characters that are perfectly okay (for example,
-%?=&) and it cuts off trailing slashes.  Of course, even with
my suggested revisions, it will fail with some URLs, but
anything will if you're excluding following punctuation (which
seems to be the reasonable thing to do for this job, since few
URLs actually end in .,; etc.).

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Thu, 10 Aug 2000 13:54:52 GMT
From: bakhshek@essilor.fr
Subject: Date convert
Message-Id: <8muc79$jha$1@nnrp1.deja.com>

Bonjour,

Est-ce que quelqu'un sait si il y a un module en perl(V 5.6) qui permet
de savoir
le temps écoule entre deux date.

Mon Jul 24 20:12:28 METDST 2000
Mon Jul 24 23:51:53 METDST 2000
---------------------------------------------
	     3:39:25

Si non comment faire pour enlever la partie fractionnaire de mon $tt:

sub foo
{
	(local $h, $m, $s, $tt) = 0;

	$tt = 13165;
	$tt %= 3600;
	$tt ==> 3.65694444444444;   # comment faire pour n'avoir que 3
}

Merci
a+


Cordialement(Best)


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 10 Aug 2000 13:09:02 GMT
From: gavin_gibson@my-deja.com
Subject: DBI question from a Newbie - handling Nulls
Message-Id: <8mu9ha$h7s$1@nnrp1.deja.com>

Dear All,

I'm fairly new to Perl and very new to DBI (I'm running on Ingres) so
please excuse me. I'm trying to move data from a table called
bill_details in one database to a table called bill details, which is
exactly the same structure, in a second database. I'm failing because
some of the fields in each table are NULL values, which the DBI is
objecting to. It seems that Perl is holding the 'null' values in a
'format' my sql doesn't like. I'm wondering if anyone can give me some
advice on how to get my null values into an acceptable format for my
sql? Many thanks in advance.

Gavin

The Background & Code....

I have executed $DBSc which returns several rows from bill_details in
database1 which will be inserted into bill_details in database2(number
of columns to values match)however some of the values returned are
NULLs. If I get rid of the nulls it all works but unfortunately I can't
do that in the Production DB.

my $BILL_DETAILS=$DBSc->fetchall_arrayref();

my $DBHd=DBI->connect("dbi:Ingres:gibson_db");
my $DBSd=$DBHd->prepare("
insert into bill_details
(account_no,uid,trans_code,status_cd,equip_uid,service_c
d,pay_code,pay_total_uid,reverse_ar_uid,trans_group_uid,tariff_code,tari
ff_sx,ta
riff_ver,tariff_qty,trans_amount,alloc_amount,trans_dt,trans_effect_dt,b
ill_uid,
gl11_income_code,gl11_update_st,daybook_cd,bill_run_uid,create_user,arch
ive_yn,r
eason_code,vat_type,vat_amount,receipt_batch_no,update_count,batch_uid,c
heque_no
,credit_card_no)
values
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
);
foreach $line(@$BILL_DETAILS){
        $DBSd->execute(@$line);
}


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 10 Aug 2000 14:38:54 GMT
From: sankarmukh@my-deja.com
Subject: Decrypt program
Message-Id: <8muept$lj0$1@nnrp1.deja.com>

I copied the decrypt subroutine from a FAQ:
But this is giving me syntax error. What is wrong here?
Any advice is appreciated.

**************************************************************

#!/usr/local/bin/perl -w
$crypted=crypt(smuk_012,"cm");
print "$crypted";
print "\n";
&decrypt;
sub decrypt {
            $crypted = shift;
            local $" = "";
            foreach $x[0] ("\x00" .. "\xFF") {
            foreach $x[1] ("\x00" .. "\xFF") {
            foreach $x[2] ("\x00" .. "\xFF") {
            foreach $x[3] ("\x00" .. "\xFF") {
            foreach $x[4] ("\x00" .. "\xFF") {
            foreach $x[5] ("\x00" .. "\xFF") {
            foreach $x[6] ("\x00" .. "\xFF") {
            foreach $x[7] ("\x00" .. "\xFF") {
                return "@x" if $crypted eq crypt "@x", $crypted;
            }}}}}}}}
        }
print "\n";
print "$crypted";
~
~
"crypt_san.pl" 21 lines, 669 characters
devwk77:/u/ctssmuk> crypt_san.pl
syntax error at crypt_san.pl line 9, near "$x["
syntax error at crypt_san.pl line 18, near "}}"
Execution of crypt_san.pl aborted due to compilation errors.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 10 Aug 2000 12:29:06 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Difference between a .cgi file and a .pl file?
Message-Id: <Pine.GHP.4.21.0008101214070.2283-100000@hpplus03.cern.ch>

On Thu, 10 Aug 2000, Tim Hammerquist wrote:

> > The use of filename extensions to denote the nature of the file
> > content is itself only _by convention_.  Some OSes have other
> > mechanisms for doing that, like content-type fields in a file
> > directory entry and so on.
> 
> Which OSes are these, I'm curious?

Well, there's the Mac.  And the Apollo was also like this, if my
memory isn't playing tricks (although it also had some kind of
compatibility mode with regular unix).  I don't doubt there are others
I'm not aware of.  

> I left Win32 because of it's extension associations, 

I wasn't for a moment trying to promote the idea that anyone should
change their OS for this specific reason...  just a an in-principle
and otherwise throwaway remark.

There are huge numbers of OSes, past and present, that I know almost
nothing about (LynxOS, Plan9...).

cheers



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

Date: 10 Aug 2000 14:03:07 GMT
From: azielke@hotmail.com (Andreas Zielke)
Subject: Example in FAQ
Message-Id: <8F8CAB1C9andreaszielkesdmde@127.0.0.1>

Hi,

I just studied the FAQ (Part 4) and found an answer that I don't under-
stand.
Initially I was wondering about how to remove duplicate array elements,
one of the possible answers in the FAQ is:

undef %saw;
@saw{@in} = ();
@out = sort keys %saw;  # remove sort if undesired

What I don't understand is the second line - I know it does something
like

foreach (@in) {
    	$saw{$_} = 'whatever';
}

but I've never seen something like @somehash{@somearray} = @somelist;
Could anyone point out some documentation (I own the german translation of 
the camel-book, but couldn't find anything on the topic...) or just explain 
the mechanism behind it?

Thanks,
  Andreas


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

Date: Thu, 10 Aug 2000 14:16:50 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Example in FAQ
Message-Id: <7ag0odcib1.fsf@merlin.hyperchip.com>


azielke@hotmail.com (Andreas Zielke) writes:

> @saw{@in} = ();
> @out = sort keys %saw;  # remove sort if undesired
> 
> What I don't understand is the second line - I know it does something
> like
> 
> foreach (@in) {
>     	$saw{$_} = 'whatever';
> }
> 
> but I've never seen something like @somehash{@somearray} = @somelist;

It is called a 'hash slice'.

Check this out:
	http://www.sysarch.com/~uri/perl/tutorials/hash_slices.txt

--Ala


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

Date: Thu, 10 Aug 2000 13:02:46 +0100
From: "Daniel Foster" <daniel@blackomega.com>
Subject: Exporting variables from packages
Message-Id: <8mu5l5$toa$1@news5.svr.pol.co.uk>

I'm trying to export a variable from a package I've written
(modularisation of code and all) like this...

package importme;

BEGIN {
 use CGI;
 use CGI::Carp qw(fatalsToBrowser);

 use Exporter();
 @ISA = qw(Exporter);
 @EXPORT = qw($co);

 $co = new CGI;
}
 ...

and the in the script I'm trying to import it into...

 ...
use importme;
 ...
print $co->header();
 ...

But I get a message about the being the only use of main::co, implying
to my (admittedly pretty inexperienced at perl) eyes that $co hasn't
been exported.  Is this the case, and if so how do I fix it?  This is
taken pretty much exactly from the Perl Black Book by the way, one
which I've found to be very good.

---
If Bill Gates had a nickel for every time Windows crashed...
 ..oh wait, he does.

Daniel Foster - daniel@blackomega.com





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

Date: Thu, 10 Aug 2000 13:23:02 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Exporting variables from packages
Message-Id: <vka5ps01i8ictb14d49rlrobn56n6hf0qm@4ax.com>

Daniel Foster wrote:

>I'm trying to export a variable from a package I've written
>(modularisation of code and all) like this...
>
>package importme;
>
>BEGIN {
> use CGI;
> use CGI::Carp qw(fatalsToBrowser);
> use Exporter();
> @ISA = qw(Exporter);
> @EXPORT = qw($co);
> $co = new CGI;
>}

Unless you're doing something else in that module that requires it,
there's no use for the BEGIN block. That code will be ran when your
script is compiled, thanks to the "use".

>and the in the script I'm trying to import it into...
>
>...
>use importme;
>...
>print $co->header();
>...
>
>But I get a message about the being the only use of main::co, implying
>to my (admittedly pretty inexperienced at perl) eyes that $co hasn't
>been exported.

Nope. It works for me. What version are you using? I think it must be an
older one. I'm using Perl 5.6. I think that is just a superfluous
warning, saying that $co is used only once *in that script*. It workls
ubnder "use strict", so it *must* be exported. Also, try printing $co
instead of $co->header. I dare bet that you'll still get the warning,
and an output that a bit looks like "CGI=HASH(0x8b35f90)".

Just use $co more than once.

-- 
	Bart.


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

Date: Thu, 10 Aug 2000 10:30:17 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: GREP - type of script...
Message-Id: <8m05ps0entbl9skkba1frpdoppiu5ghhj4@4ax.com>

Scott Barlow wrote:

>Thanks for both of the help - but I actually want to change
>not the file name or make a backup of the actual file, but I
>want to change a string variable that is found within the file
>itself.
>
>So, if foo.txt has the following parameters:
>---------------------
>test, hello
>rest, bye-bye
>test, I'm back
>----------------------
>
>Then, I'd like to find the string "test" and change it
>to "whatever" within the particular "foo.txt", producing the
>results:
>---------------------
>whatever, hello
>rest, bye-bye
>whatever, I'm back
>----------------------

Like I said. The command line:

	perl -pi.bak -e "s/^test(?=,)/whatever/" foo.txt

will rename foo.txt to foo.bak, and make a new, modified version for
foo.txt. (On Unix, replace the quotes with single quotes.)

The backup is a side effect. I'm not sure about newer evolutions, but
last time I looked, you couldn't use the -i (modify file itself) option
without making a backup.

Alternatively, load the whole file in memory, substitute every line, and
save it back. A lot more work. I'm too lazy.

-- 
	Bart.


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

Date: Thu, 10 Aug 2000 10:09:39 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: help for Insert rows into table by DBI
Message-Id: <slrn8p5051.n7e.rgarciasuarez@rafael.kazibao.net>

Lucas Tsoi wrote in comp.lang.perl.misc:
>Hi all,
>
>I met some problems about DBI calling mySQL.
>
>When either of elements(element1, element2, element3, element4, element5)
>has
>the character liked ' or ", the error message "Cannot update database
>payment"
>would be returned.
>
>I guess the problem is from the qq interpolation, but I don't know how to
>solve it.
>
>
>----------------------------------------------------------------------------
>$dbpayment = DBI->connect("DBI:mysql:table1","root","passwd") or
>Error($dbpayment->errstr);
>
>  $dbrow = $dbpayment->do(qq(
>   INSERT INTO payment2 (element, element, element, element)
>   VALUES ('$DATA{element1}', '$DATA{element2}', '$DATA{element3}',
>'$DATA{element4}')  ));

Don't do that. Do:
  $dbrow = $dbpayment->do(qq(
   INSERT INTO payment2 (element, element, element, element)
   VALUES (?,?,?,?)),
   undef,
   $DATA{'element1'},
   $DATA{'element2'},
   $DATA{'element3'},
   $DATA{'element4'},
  );
This properly quotes the values.
If this doesn't work, the problems has another cause.
In your error message, print $DBI::errstr : this is the native and
human-readable error message returned by your DBD driver (in this case,
MySQL).

-- 
Rafael Garcia-Suarez


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

Date: 10 Aug 2000 14:16:56 GMT
From: <kolibrie@southernvirginia.edu>
Subject: Re: help w/ regular expression
Message-Id: <8mudgo$svi$1@bob.news.rcn.net>

It is easy to strip out everything except numbers:

  my $string = '213-555-4321';
  $string =~ s/\D//g;

$string now contains only: 2135554321

If you want to return the original string if it contains other stuff (except
for 'fn=', '-', '(' ,')' ), you might do something like this:

  my $string = 'fn=(213) 555-4321';
  if ($string =~ m/^(?:fn=)?[\d\-()\s]/) {
      $string =~ s/\D//g;
  }

$string will still contain: 2135554321
However, if we set $string = '213-555-4321 phones are ringing', then $string
will come out unchanged.

kolibrie


Sam Carleton <w00dy@my-deja.com> wrote:
> hay folks, I am new to perl, been a C/C++ programmer for 5 year now.  I
> am trying to take a basic C CGI script I wrote a while back and turn it
> into a perl CGI program.  The main thing it did was parse a string for
> me.  Well, I thought I would use regular expression engine to that for
> me, but my task is a bit complex.  I was wondering if someone could show
> me the best way to do it.  Here is the task:

> I have a string that is suppost to contain a phone number.  I need the
> phone number in pure number's.  The string could contain anything,
> though.  If the string is indead a phone number I need it return in a
> string of pure numbers.  If it is anything else I need the orginial
> string returned.  Examples:

> 213-555-4321         -> 2135554321
> 213) 555-54321       -> 2135554321
>   213 555 4321       -> 2135554321
> 2135554321           -> 2135554321
> 213   555   4321     -> 2135554321

> fn=213-555-4321         -> 2135554321
> fn=(213) 555-4321       -> 2135554321
> fn=213 555 4321         -> 2135554321
> fn=2135554321           -> 2135554321
> fn=213   555   4321     -> 2135554321

> This is a string              -> This is a string
> 432 cars are going            -> 432 cars are going
> 213-555-4321 phones are ringing -> 213-555-4321 phones are ringing

> Can someone enlighen me as to how I would write a sub that either
> returned back the compact phone number or the original string?

> Sam



> Sent via Deja.com http://www.deja.com/
> Before you buy.


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

Date: Thu, 10 Aug 2000 13:24:54 GMT
From: troylachinski@my-deja.com
Subject: Re: Help with quotewords
Message-Id: <8muaf0$i29$1@nnrp1.deja.com>

I am working on a data conversion program.  The following code works
properly EXCEPT when $plu_descriptor contains a single quote (').  When
this is the case all variables are empty.  Here is the entire program.
(this is not what I am trying to accomplish but actually a stipped down
section of code to track down this problem).


print "PLU file name: ";
chomp($infilename = <STDIN>);
print "SER-65 file name: ";
chomp($outfilename = <STDIN>);
open(OLD,$infilename) ||
	die "cannot open $infilename for reading: $!";
## optional test for overwrite...
die "will not overwrite $outfilename" if -e $outfilename;
open(NEW,">$outfilename") ||
	die "cannot create $outfilename: $!";
$cnt = 0;
$cnt2 = 0;
use Text::ParseWords;
while(<OLD>) { # read a line from file IN into $_
	$cnt++; 		# count the number of lines
	($plu_number, $dept, $plu_descriptor, $nothing1,
		$price1) = quotewords(",",0,$_);
		$plu_descriptor =~ s/^'(([^'\\]|\\[\\'])*)'//;


		print NEW "$plu_number - $dept - $plu_descriptor -
$nothing1 -  $price1";

		$cnt2++;
	}

close(NEW);
close(OLD) || die "close: $!";
print "$cnt2 of $cnt lines converted\n";

SAMPLE DATA FROM DATA SOURCE:
736,PUBS,zzORS CAPTIVATING CLAMS,0,1
737,PUBS,zzOR'S GOLDEN YEARS,0,12.95
738,PUBS,zzOR'S TASTY MUSSELS,0,0.25
739,PUBS,zzOR WA CAMPGROUND DRCTRY oop,0,4.95
740,PUBS,OVERLAND MIGRATIONS,0,7.95

737 and 738 fill all of the variables with nothing.  I spent a great
deal of time searching this newsgroup last night searching for answers
but still am puzzled.

Thanks in advance for the help!



> what difference could the value of $plu_descriptor make when you're
> overriding it with the value of quotewords ?
>
> methinks that you might not be showing the relevant code .. you'll
need
> to show more details
>
> --
>   jason -- elephant@squirrelgroup.com --
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 10 Aug 2000 13:56:43 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Help with quotewords
Message-Id: <MPG.13fd520339e096a1989690@localhost>

troylachinski@my-deja.com wrote ..
>I am working on a data conversion program.  The following code works
>properly EXCEPT when $plu_descriptor contains a single quote (').  When
>this is the case all variables are empty.  Here is the entire program.
>(this is not what I am trying to accomplish but actually a stipped down
>section of code to track down this problem).

ok .. so what you really meant is that when the third field in the input 
contains a single quote then it doesn't work

and that's kind of obvious .. that's one of the things that quotewords 
does .. it uses a quotation marks as field delimiters so that the 
separator can be included within a field

re-read the documentation .. I think you might just want the built-in 
split function rather than Text::ParseWords::quotewords

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Thu, 10 Aug 2000 12:48:04 +0100
From: "david frost" <hotrock@freenetname.co.uk>
Subject: IO::File and file handles
Message-Id: <8mu85p$i1m$1@gxsn.com>

Hi everyone,

I have myself a problem.  I need to convert a file handle( passed to a mason
script by apache) into an IO::File.

This is because i need to use $file->getline() rather than <$file>.

Any help on this is much apreciated.

Cheers

dave




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

Date: Thu, 10 Aug 2000 14:08:00 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: IO::File and file handles
Message-Id: <jpd5psgfqq9cajaoh3nf8mvbnfemuh0hht@4ax.com>

david frost wrote:

>I have myself a problem.  I need to convert a file handle( passed to a mason
>script by apache) into an IO::File.
>
>This is because i need to use $file->getline() rather than <$file>.

What kind of filehandle is it? I don't know Mason intimitely. But I
assume that you can always duplicate the handle.

	use IO::File;
	$duped = new IO::File "<&" . fileno($file);

-- 
	Bart.


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

Date: 10 Aug 2000 13:37:44 GMT
From: mgjv@martien.heliotrope.home (Martien Verbruggen)
Subject: Re: Large-File Reformatting Problem (Regexp gurus, et al.)
Message-Id: <slrn8p5buv.cb0.mgjv@martien.heliotrope.home>

On Wed, 9 Aug 2000 10:33:47 -0400, Christopher J. Mackie
	<cjmackie@princeton.edu> wrote:
> 
> The proper format is a number of lines of text (1 to approx. 280k
> lines ending in single newlines) separated by exactly one blank line
> (i.e., '\n\n').  The errors consist only of excess whitespace between
> the texts (an unknown and presumably variable number of extra
> newlines, plus, perhaps, some whitespace interspersed-with and/or
> bracketing the newlines).  I have to remove the excess whitespace and
> newlines, leaving only '\n\n', and without removing any of the
> legitimate, line-ending newlines in the interior of the texts.

\begin{heresy}

Hmm. I might be missing something, but I'd probably try to do this with
awk.. not perl.

# cat foo.awk
BEGIN { RS = "[\t ]*\n[\t \n]*\n[\t ]*"; ORS = "\n\n" }
    { print }
# nawk -f foo.awk textfile

If I understand your question correctly, you want to split out the
'records' in the file and output them again with two newlines between
them? And the current record separator is any sequence of two or more
newlines, with any amount of whitespace (which I assumed to be tabs and
space, regex can be adapted appropriately) between and around them? The
above should do that.

\end{heresy}

\begin[inherited]{heresy}

If I interpreted it correctly, then this is one of the things that awk
probably is better at. :) It allows RS to be a regexp.

\end{heresy}

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In a world without fences, who needs
Commercial Dynamics Pty. Ltd.   | Gates?
NSW, Australia                  | 


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3974
**************************************


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