[22906] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5126 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 23 14:06:26 2003

Date: Mon, 23 Jun 2003 11:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 23 Jun 2003     Volume: 10 Number: 5126

Today's topics:
    Re: DBD, arrays, placeholders & Null's ctcgag@hotmail.com
    Re: ftp through http proxy <glex_nospam@qwest.net>
    Re: Issues grabbing UTF8 web page <flavell@mail.cern.ch>
    Re: printf no delay question <Graham.T.Wood@oracle.com>
    Re: printf no delay question <Juha.Laiho@iki.fi>
        Reading just the right amount into file... <no-email@aol.com>
    Re: Reading just the right amount into file... <bdonlan@bd-home-comp.no-ip.org>
    Re: subroutines passing by reference <mbudash@sonic.net>
    Re: subroutines passing by reference <nobull@mail.com>
        Win2K Raw Disk Access (Douglas Garstang)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 23 Jun 2003 15:55:04 GMT
From: ctcgag@hotmail.com
Subject: Re: DBD, arrays, placeholders & Null's
Message-Id: <20030623115504.652$kh@newsreader.com>

"ThePotPlants" <thepotplants@yahoo.com> wrote:
> Hi all
>
> I'm having some grief with Perl DBI/DBD::Oracle,
>
> I'm trying to insert rows using placeholders, and then multiple executes
> with an array.
>
>     $sth = $dbh->prepare("insert into TRUNC2 values (?,?,?,?,?,?,?,?)" );
>
>     ## reading | delemited rows  from a file that look like this
>      $tabrow = "|SMITH|CLERK|7902|17-DEC-80|800||20" ;
>     @inrow = split(/\|/, $inrow);
>     $sth->execute(@inrow);
>
> It works fine normally. But has a problem with trailing NULL's.
> If the string ends with a NULL, then the array seems to ignore it, and so
> I have the wrong number of elemnets in the array vs placeholders.
>
> Can anyone tell me how to force the array to accept trailing NULL's?

"perldoc -f split" can tell you.


split /PATTERN/,EXPR,LIMIT
 ...
If LIMIT is specified and positive, splits into no
more than that many fields (though it may split
into fewer).  If LIMIT is unspecified or zero,
trailing null fields are stripped (which potential
users of "pop" would do well to remember).  If
LIMIT is negative, it is treated as if an arbi-
trarily large LIMIT had been specified.


> any other suggestions or alternatives would be greatly appreciated.

use warnings, use strict, and read the fine documentation.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Mon, 23 Jun 2003 11:29:50 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: ftp through http proxy
Message-Id: <FVFJa.589$xF5.29202@news.uswest.net>

Jasmine Chan wrote:
> Read that already.  It didn't work and that's why I am pursuing the
> "HTTP_PROXY" approach !!!
> 
> 
> "J. Gleixner" <glex_nospam@qwest.net> ?????
> news:F_EJa.565$xF5.24222@news.uswest.net...
> 
>>Jasmine Chan wrote:
>>
>>>Hi,
>>>
>>>Excuse me for such a newbie question.
>>>
>>>I knew setting the "HTTP_PROXY" environment variable could cause the PPM
>>>program work over a proxy server.  I wonder if this same setting would
> 
> help
> 
>>>my other program (it utilizes the net::ftp package) that is requested to
>>>perform ftp via proxy server.
>>>
>>>Anyone know the anwser please give me a shout.
>>
>>Check the perldoc for Net::FTP
>>
>>perldoc Net::FTP
>>
>>Hint: Look for "proxy".
>>
Sorry, however since you didn't post any code we can only guess at a 
possible solution.  The Firewall attribute, according to the docs and 
the code, will proxy the FTP connection. Please post your code.



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

Date: Mon, 23 Jun 2003 18:08:30 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Issues grabbing UTF8 web page
Message-Id: <Pine.LNX.4.53.0306231754070.31161@lxplus014.cern.ch>

On Mon, Jun 23, Simon Fairey inscribed on the eternal scroll:

> I'm using 5.8 and LWP::Simple to get a page which is UTF-8 encoded
> xml. Now I am having trouble with the bullet points as my output
> encoding has to be 8859-1.

[Encoding sure seems to be a hot topic around here right now.]

> As far as I can tell a bullet is U+2022 so
> I try searching so \x{2022} but to no avail.

Did you give Perl the remotest clue that it's supposed to be treating
the bytestream as utf8 ?

> I'm also unsure as to
> whether the LWP get has converted the file or whether it is safe to
> say it is still in UTF-8 (I'm new to Unicode so you may have to bear
> with me a bit because I keep getting lost!)

It's a common problem, indeed.  Based on the way you're asking the
question, I fear that you may be somewhat at sea with how it works in
XML/HTML/XHTML/whatever, which only makes your Perl difficulties that
much harder.

> Either way I'm having trouble identifying the character and replacing
> it with the &#149; HTML entity.

There is no such "HTML entity".  Numerical character references (which
is what &#number; references are properly called) are defined to refer
to Unicode code points, and the range 127 to 159 decimal inclusive in
Unicode consists of control characters, none of which are used in
practice.   As you've already noticed, the code point for the bullet
is up at x2022.

> I'm obviously missing something but I'm at a loss as to what it is,
> character sets and Unicode are turning my brain to jelly at the moment
> :-(

That realisation usually precedes enlightenment, so there's hope for
you yet :-)

If your XML document is supposed to be coded in iso-8859-1, then your
only valid way to represent the bullet character is as its proper
numerical character reference, &#x2022; or (quick reference to
read-reckoner...) &#8226;

As usual, a minimal script that we could run for ourselves and that
exhibited the symptoms that you're complaining of would short-cut a
panoply of possible misunderstandings based on your possibly confused
description of what you're aiming at.  Since you say it references a
utf-8 -encoded document, you better put that on an accessible web
server somewhere (if it isn't already), and tell us its URL (trying to
include it in a news posting is just _too_ fraught with potential
difficulties).


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

Date: Mon, 23 Jun 2003 17:59:58 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: printf no delay question
Message-Id: <3EF7320E.BCA4CC93@oracle.com>

This is a multi-part message in MIME format.
--------------72015AF0933FD2D47E465C17
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

cedric wrote:

> When I run printf like this:
> #---------------------------------------------
> printf "Run a very long subrouting ...";
> &verylongsub();
> printf " Done!\n";
> #---------------------------------------------
> It will print two lines simultaneity:
> <SNIP>

> but I want: Run a very long subrouting ...(some time)Done!

unbuffer your output by setting
$|=1;
before your first printf.

Graham

--------------72015AF0933FD2D47E465C17
Content-Type: text/x-vcard; charset=UTF-8;
 name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
 filename="Graham.T.Wood.vcf"

begin:vcard 
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.Wood@oracle.com
fn:Graham Wood
end:vcard

--------------72015AF0933FD2D47E465C17--



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

Date: Mon, 23 Jun 2003 17:22:00 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: printf no delay question
Message-Id: <bd7co3$cra$1@ichaos.ichaos-int>

"cedric" <xilir_news@163.com> said:
>    When I run printf like this:
>#---------------------------------------------
>printf "Run a very long subrouting ...";
>&verylongsub();
>printf " Done!\n";
>#---------------------------------------------
>It will print two lines simultaneity:
>Run a very long subrouting ...Done!
>but I want:
>Run a very long subrouting ...(some time)Done!

You're seeing the effect of output buffering. Things get printed out
only when there is a full line to print out. As a solution, disable
output buffering for the first print:

{
    local $|=1;
    printf "Run a very long subrouting ...";
}
&verylongsub();
printf " Done!\n";

Btw, do you have a specific reason to call the verylongsub() with the
ampersand? (see "perldoc perlsub" for explanation where using the &
makes a difference)
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: Mon, 23 Jun 2003 12:38:49 -0500
From: "J. Smith" <no-email@aol.com>
Subject: Reading just the right amount into file...
Message-Id: <vfeep8d7dmeq19@corp.supernews.com>

Hello perl people.

I've been racking my brain over this for about three days now.
I finally decided to ask for help.

I have one big binary file.
In this file I've "glued" the data from multiple files.
I have a record for each file on where to seek, and how much to read to
"extract" that particular file.

Example:
seek(BINARY, $pos,  0);
read(BINARY, $data, $bytes);
 ...

My problem is that if any particular file is fairly large, it really eats up
the memory.
I'm looking for a way to get to the file position that I need, then read,
maybe 5000 bytes at a time until I reach $bytes.

I've tried many ways, and I've ended up with many different results, but not
the expexted result.

Thanks.




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

Date: Mon, 23 Jun 2003 13:54:40 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: Reading just the right amount into file...
Message-Id: <pan.2003.06.23.17.54.40.87645@bd-home-comp.no-ip.org>

On Mon, 23 Jun 2003 12:38:49 -0500, J. Smith wrote:

> Hello perl people.
> 
> I've been racking my brain over this for about three days now.
> I finally decided to ask for help.
> 
> I have one big binary file.
> In this file I've "glued" the data from multiple files.
> I have a record for each file on where to seek, and how much to read to
> "extract" that particular file.
> 
> Example:
> seek(BINARY, $pos,  0);
> read(BINARY, $data, $bytes);
> ...
> 
> My problem is that if any particular file is fairly large, it really eats up
> the memory.
> I'm looking for a way to get to the file position that I need, then read,
> maybe 5000 bytes at a time until I reach $bytes.
> 
> I've tried many ways, and I've ended up with many different results, but not
> the expexted result.

seek(BINARY, $pos, SEEK_SET) or die "$!\n";
while($bytes){
  my $len = ($bytes > 5000) ? 5000 : $bytes;
  $bytes -= $len;
  read(BINARY, $data, $len) or die "$!\n";
  &dosomething($data);
}
-- 
Freenet distribution not available
Disc space -- the final frontier!



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

Date: Mon, 23 Jun 2003 15:51:41 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: subroutines passing by reference
Message-Id: <mbudash-7FC1FC.08514023062003@typhoon.sonic.net>

In article <3a9c1232.0306230739.2dfa5246@posting.google.com>,
 maximuszen@optonline.net (Max) wrote:

> The following code works fine:
> 
> my @fields = qw (LastName FirstName MiddleName TypeOfProvider
> LicenseNo Institution Title UserID Email CellPhone FAX OfficePhone
> StreetAddress
> City Country PostalCode Password);
> my $fields = join (', ', @fields);
> my $places = join(', ', ('?') x @fields );
> my $sql = "INSERT into $table ($fields) values ($places)";
> my $sth = $dbh -> prepare_cached ($sql);
> $sth -> execute(@FormData{@fields});
> 
> The variables look like this:
> 
> $sql=
> INSERT into providers (LastName, FirstName, MiddleName,
> TypeOfProvider, LicenseNo, Institution, Title, UserID, Email,
> CellPhone, FAX, OfficePhone, StreetAddress, City, Country, PostalCode,
> Password) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
> 
> I now have been trying to convert this into a subroutine... but I
> can't seem to figure out the format of the last line
> "FormData{@fields}" using passing by reference. I got everything
> else... Here is the subroutine...
> 
> 
> insert ($database,$table,\@fields,\%FormData);
> sub insert ($$\@\%) {
> 	my ($database,$table,$refArrayFields,$refHashValues) = @_;
> 	use DBI;
> 	print $database," ",$table,"<BR>";
> 	my $host="localhost"; my $user="root"; my $password="";
> 	$dbh=DBI->connect("DBI:mysql:database=$database:$host",$user);
> 	$fields = join (', ', @{$refArrayFields});
> 	my $places = join(', ', ('?') x @{$refArrayFields});
> 	my $sql = "INSERT into $table ($fields) values ($places)";
> 	print $fields,"<BR>",$places,"<BR>",$sql;"<BR>";
> 	print ${$refHashValues}{$fields},"#";
> 	my $sth = $dbh -> prepare_cached ($sql);
> 	$sth -> execute(@{$refHashValues});
> 
> 
> Its this last line... @{$refHashValues} doesn't work it just prints
> out blank... Help.
> 
> Max

   $sth -> execute(@{$refHashValues}{@{$refArrayFields}});

hth-


-- 
Michael Budash


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

Date: 23 Jun 2003 17:46:47 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: subroutines passing by reference
Message-Id: <u9of0ooi6g.fsf@wcl-l.bham.ac.uk>

maximuszen@optonline.net (Max) writes:

> insert ($database,$table,\@fields,\%FormData);
  [...]
> sub insert ($$\@\%) {
> 	my ($database,$table,$refArrayFields,$refHashValues) = @_;

You have misunderstood what \ means in prototypes.

It means mens that you want the \ in the call to be assumed.

So you should remove either the prototype or the slashes in the call.

If you decide you want to have a prototype it must precede the call.
Otherwise it won't work.  Perl would have warned you about this if
you'd let it.

  insert ($database,$table,\@fields,\%FormData);
  ...
  sub insert {
 	my ($database,$table,$refArrayFields,$refHashValues) = @_;

 ...OR...

  sub insert ($$\@\%);
  ...
  insert ($database,$table,@fields,%FormData);
  ...
  sub insert ($$\@\%) {
  	my ($database,$table,$refArrayFields,$refHashValues) = @_;


> 	$sth -> execute(@{$refHashValues});

> Its this last line... @{$refHashValues} doesn't work it just prints
> out blank... Help.

Are you sure?

A DBI statement execute() should not print anything.   

Attempting to dereference a hash reference as an ARRAY should generate
a "Not an ARRAY reference" error.

> The following code works fine:
> $sth -> execute(@FormData{@fields});

>I now have been trying to convert this into a subroutine... but I
>can't seem to figure out the format of the last line
>"FormData{@fields}" using passing by reference

> $sth -> execute(@{$refHashValues});

You mean:

  $sth -> execute(@$refHashValues{@$refArrayFields});

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 23 Jun 2003 11:04:44 -0700
From: doug@pobox.com (Douglas Garstang)
Subject: Win2K Raw Disk Access
Message-Id: <10d46bdc.0306231004.6dceb81c@posting.google.com>

All,

Does anyone know how the following could be implemented in Win2K? 

sysopen (F,$device, O_RDONLY)

Works fine under Solaris and Linux with a device file. On Win2K I have
a raw disk device, \\.\physicaldrive2. I can't use that as a device
name though. I've also tried using drive letters and other variations.

Thanks.
Doug


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5126
***************************************


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