[22360] in Perl-Users-Digest
Perl-Users Digest, Issue: 4581 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 18 18:06:23 2003
Date: Tue, 18 Feb 2003 15:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 18 Feb 2003 Volume: 10 Number: 4581
Today's topics:
Re: Date module (Tad McClellan)
How do I install a new module in an ActiveState install <geoff.news6@alphaworks.co.uk>
Re: How do I install a new module in an ActiveState ins <usenet@dwall.fastmail.fm>
Re: Malformed UTF-8 character <goldbb2@earthlink.net>
Re: Malformed UTF-8 character <flavell@mail.cern.ch>
Re: Memory problem with persistent DBI connection <goldbb2@earthlink.net>
Need Help with Pattern Matching <PleaseDontThrowSpam@Me.com>
Re: Need Help with Pattern Matching <goldbb2@earthlink.net>
newbie logfile processing question (Matt Baran)
Re: newbie logfile processing question (Anno Siegel)
Re: parsing string with whitespace <krahnj@acm.org>
Re: Perl & VB without activeperl on Windows?? <noemail@nowhere.net>
Re: Perl & VB without activeperl on Windows?? <noemail@nowhere.net>
Re: Regular Expression Noob <tore@aursand.no>
Re: Returning the field list from DBI <goldbb2@earthlink.net>
Re: Returning the field list from DBI <cpryce@pryce.net>
Re: Socket command <dwilga-MUNGE@mtholyoke.edu>
Subroutine does not 'see' parameter passed to it (george)
Re: Subroutine does not 'see' parameter passed to it (Anno Siegel)
Re: Subroutine does not 'see' parameter passed to it <noreply@gunnar.cc>
Unsuccesful "Print" <PleaseDontThrowSpam@Me.com>
Re: Unsuccesful "Print" (Walter Roberson)
Re: use DBI; (g)
Re: Using different hashes. <usenet@dwall.fastmail.fm>
Re: Where is DB_File in redhat 8.0? <bobx@linuxmail.org>
Re: Where is DB_File in redhat 8.0? <dwilga-MUNGE@mtholyoke.edu>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 18 Feb 2003 10:38:04 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Date module
Message-Id: <slrnb54obc.3jt.tadmc@magna.augustmail.com>
Kevin <kevin_mudd@adp.com> wrote:
> Is there an existing Date module where I can get the number of days in
> the current month?
Date::Calc::Days_in_Month()
Did you overlook it when you checked CPAN before posting?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 18 Feb 2003 22:14:33 -0000
From: "Geoff Soper" <geoff.news6@alphaworks.co.uk>
Subject: How do I install a new module in an ActiveState installation
Message-Id: <3e52b04a$0$371$cc9e4d1f@news.dial.pipex.com>
I'm using an ActiveState installation of Perl running on a Win XP PC. How do
I install and use a module that isn't currently installed. In this case I
want to use Crypt::BlowFish in a script. I've tried simply creating a
directory named Crypt in C:\Perl\lib\ and putting BlowFish.pm in it but this
didn't work. I've put use Crypt::Blowfish; in the file I'm trying to
execute.
The error I'm getting is:
Can't locate object method "bootstrap" via package "Crypt::Blowfish" at
C:/Perl/lib/Crypt/Blowfish.pm line 20.
Any suggestions gratefully received!
Geoff
------------------------------
Date: Tue, 18 Feb 2003 22:54:19 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: How do I install a new module in an ActiveState installation
Message-Id: <Xns9326B6242B49Bdkwwashere@216.168.3.30>
Geoff Soper <geoff.news6@alphaworks.co.uk> wrote on 18 Feb 2003:
> I'm using an ActiveState installation of Perl running on a Win XP
> PC. How do I install and use a module that isn't currently
> installed. In this case I want to use Crypt::BlowFish in a script.
> I've tried simply creating a directory named Crypt in C:\Perl\lib\
> and putting BlowFish.pm in it but this didn't work. I've put use
> Crypt::Blowfish; in the file I'm trying to execute.
Read the docs for PPM, the Perl Package Manager that Activestate uses.
Activestate Docs -> Table of Contents -> ActivePerl Components -> PPM
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: Tue, 18 Feb 2003 15:38:01 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Malformed UTF-8 character
Message-Id: <3E5299A9.798A4C0@earthlink.net>
Bernie Cosell wrote:
>
> Benjamin Goldberg <goldbb2@earthlink.net> wrote:
>
> Your summary of UTF-8 problems is fairly disturbing [mostly because
> virtually none of the stuff we deal with actually _uses_ UTF-8
When you try each of:
perl -Mopen=OUT,:utf8 -e "print chr(225)"
perl -Mopen=OUT,:raw -e "print chr(225)"
If the :utf8 version prints out an accented letter a, then you *are*
using utf8... you just don't realize it.
> and it seems that that will break a *bunch* of stuff.
In a way, it's no worse than the issue of CLRF being the line terminator
on windows, and LF being the line terminator on *nix, and CR being the
line terminator on macintosh. If you move a file from one platform to
another, you *must* change the line terminator, if the file is text, but
need to leave the file alone if it's binary.
The new problem you're having is that some files were copied from one
system to another, but the translation of those files from latin1 to
utf8 for the text files wasn't made.
> } Redhat 8.0 has $ENV{LANG} equal to "en_US.utf8", which perl
> } interprets to mean that all text-mode filehandles are utf8.
> }
> } The way to work around the so-called "problem," is to do the same
> } thing you would do to prevent CRLF <=> "\n" conversion on windows.
> } That is: binmode() any handle which contains binary data, but leave
> } handles with text data alone. And if your source code has strings
> } with their high bits set, make sure that the appropriate 'use
> } encoding qw(...)' is done.
>
> UGH!! Would it work just to fix $ENV{LANG}?
Yes. That would be cheating, though.
Also, since $ENV{LANG} is examined only when perl starts up, not at each
open(), you have to have it set in the shell which starts perl. Unless
you use /bin/env on your shebang line:
#!/bin/env LANG= perl
Another alternative to changing $ENV{LANG} (which, after all, would have
an effect on *all* programs which examine it, not just on perl), you
could set the PERL5OPT environment variable to '-Mopen=:raw' ... but
this will only effect filehandles, not embeded data whose high bits are
set.
> } > I've tried "no utf8;" and "use bytes;" in the scripts but the
> } > problem seems to be with the modules called.
> }
> } The "use utf8" pragma has an effect similar to "use encoding
> } qw(utf8);", and "no utf8" pragma has an effect similar to "use
> } encoding qw(latin1)".
> }
> } Using either of "no utf8" or "use encoding qw(latin1)" would solve
> } the problems coming from Date/Manip.pm (but you have to put it *in*
> } Date/Manip.pm).
Another alternative would be to go through the directory tree, find
those files which contain latin1 data, and then modify those modules to
translate the latin1 to utf8. IMHO, this is the best solution, since it
doesn't require any changes to any of the code... and it should fix
*everything*, as far as I know.
It's possible that in the future, installing a module using CPAN.pm will
automatically perform this type of translation. In fact, without such a
translation, it's fair to say that the installation was broken.
> Whew... this is pretty unworkable for most of us [I certainly can't go
> and edit-by-hand to change bunches of Perl modules to have 'no utf8'].
Hmm... instead of doing by-hand changes, consider doing:
find /path/to/perl/lib -name '*.pm' | xargs \
perl -Mopen=IN,:raw,OUT,:utf8 -i.bak -pe1
[untested]
This globally changes all the data in the files to utf8.
Actually, you'd be safer doing:
find /path/to/perl/lib -name '*.pm' | xargs \
grep -l '[\x80-\xFF]' > names.txt
# examine names.txt by hand, remove those
# file names which you don't want changed.
xargs < names.txt \
perl -Mopen=IN,:raw,OUT,:utf8 -i.bak -pe1
You may need to change the grep line to get that character range thingy
to work right. Hmm..
find /path/to/perl/lib -name '*.pm' | xargs \
grep -l `perl -e 'print "[\x80-\xFF]"'` > names.txt
[Bleh, that's evil, but I suppose that it might work]
[all code here is untested]
> I think that for many of us, to make all this work we'll probably need
> some [relatively simple?] global way to turn off the UTF8 stuff...
From the shell:
LANG=
export LANG
But this is fairly heavy-handed. What happens if you need to read from
a "real" text file, and it contains utf8 data? By setting
$LANG=en_US.utf8, Redhat8 is claiming that *all* of it's system
utilities are utf8 aware, and will produce utf8 data unless told not to.
Do you want to be unable to read normal text files properly, just
because the module installation program goofed?
> } These problems are due to Data/Manip.pm containing strings with
> } have thier high-bits set in them -- they are valid ISO-8859-1
> } strings, but they are invalid utf8.
> }
> } You can correct the problem by adding:
> }
> } use encoding "latin1";
> }
> } At the top of Data/Manip.pm. (Well, actually, anywere before sub
> } Date_Init_Portuguese should be ok).
>
> Is there a way to "correct" the problem for those of us who have
> read-only .pm libraries? It seems bizarre [and certainly feels like
> something is broken at a low-level] to have to do 'binmode' on *text*
> files.
Well, I guess that "binmode" is sortof a misnomer, but the perl
developers chose to overload that function for the purpose of adding and
removing encoding layers.
Furthermore, since Redhat8 defines text to be utf8, you're actually
doing binmode() on a file which DOES NOT contain "real text" ... it
contains funky latin1 data. (Well, it's funky to redhat, anyway, even
if the rest of the english-speaking world uses latin1)
> [and that'll make for interesting portability problems: on
> windows systems you do 'binmode' on binary files, on "modern" unix
> systems you have to do 'binmode' on *text* files. Groan...:o)
No, actually -- if the file contains the Operating System's definition
of "text", then you *don't* have to use binmode.
If you have a file which contains utf8 text, and the Operatin System's
definition of text is utf8, then you don't need binmode.
If you have a file which contains latin1 text, and the Operatin System's
definition of text is latin1, then you don't need binmode.
But if the Operating System's definition of text is utf8, and a file
contains latin1 text, or vice versa, then binmode is needed.
The problem arises because the module author wrote on a system where the
operating system's definiton of text is latin1, and put latin1 data into
the file. This was only ok until the module was moved off of his system
and onto yours. Either an explicit binmode should have been done, or
else the data ought to have been translated.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Tue, 18 Feb 2003 22:04:11 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Malformed UTF-8 character
Message-Id: <Pine.LNX.4.53.0302182156270.8504@lxplus081.cern.ch>
On Tue, Feb 18, Benjamin Goldberg inscribed on the eternal scroll:
> Furthermore, since Redhat8 defines text to be utf8, you're actually
> doing binmode() on a file which DOES NOT contain "real text" ... it
> contains funky latin1 data.
Indeed under some sets of rules for reading utf-8, you'd have to give
up as soon as you find an invalid utf-8 sequence. This is a security
measure.
------------------------------
Date: Tue, 18 Feb 2003 15:59:39 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Memory problem with persistent DBI connection
Message-Id: <3E529EBB.61A59E3E@earthlink.net>
DJ wrote:
>
> Hello!
>
> I am coding a small watchdog daemon that monitors a couple of ports.
> It reads the list of hosts and the port to connect to from a Postgres
> database. The daemon uses a persistent connection to the databases.
> There are just two SELECTs and a couple of INSERTs and UPDATEs,
> depending on the state of the monitored ports.
>
> The problem is that the daemon process accumulates memory over time. I
> ran the daemon for three days and the process got as big as 50 MB. I
> don't understand where the memory is used. Although the database
> connection is persistent I use finish() and commit() in order to flush
> the buffers.
The only time you need finish() is if you have a SELECT statement, and
you read *part*, but not all of the data, and you don't want the rest of
the data. It has no effect if you've read all of the data from a
statement handle.
And commit() doesn't effect buffering.
> Does anyone have any idea how to trace this problem or how to make
> sure that the process doesn't grow?
Add 'use strict' to your program, then declare all of your variables
with the smallest possible scope.
Don't use nested anonymous subroutines.
Try and avoid string eval.
Use lexical filehandles, and close() and undef() them when you're done
using them.
If possible, use sql statements with placeholders, instead of
interpolating data -- this way, you can prepare them ahead of time, and
avoid having to re-prepare them. This will speed up your program for
sure, and *may* avoid a memory leak.
If you show us your code, we can give more specific advice.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Tue, 18 Feb 2003 22:10:50 -0000
From: "Mikey" <PleaseDontThrowSpam@Me.com>
Subject: Need Help with Pattern Matching
Message-Id: <b2uaum$fi3$1@wisteria.csv.warwick.ac.uk>
Hi,
I've found the following site particularly useful so far, but am now stuck.
http://www.wdvl.com/Authoring/Languages/Perl/PerlfortheWeb/perlintro2_table1
.html
I'm trying to sort the following data by Height:
(this data resides in store.dat, each field separated by a space)
DOB Cash Name Height
12.01.1963 100 John Smith 5.11
27.02.1955 200 Jimmy Dolan Andrews 5.8
16.03.1977 400 Johnny Barrosh 5.4
09.01.1987 200 Steve McHooter 5.5
01.02.1983 100 Blaro Van Daronimo 4.4
I can't work out a correct pattern matching line which will successfully
separate these fields.
To sort the data I currently have:
.......{
......
open (DATA, store.dat or die $!;
while (<DATA>) {
push (@data_rows, $_);
}
close (DATA);
@sorted_data = sort make_sort (@data_rows); # Call the sorting routine
foreach (@sorted_data) {
print "$_\n"; # Print the stored data array
}
}
sub make_sort {
my ($a) = (split(/\|/, $a))[3]; # This split needs changing
my ($b) = (split(/\|/, $b))[3]; # This split needs changing
$a <=> $b;
}
This works successfully on fields separated by | but I can't adapt it for my
new data as shown above.
Can someone please help?
I'm having particular trouble because the name field can be one or more
words.
Thank-you very much if you can help me,
Mikey
PS. Sorry for the cross post, I think I got the wrong newsgroup
------------------------------
Date: Tue, 18 Feb 2003 17:45:19 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Need Help with Pattern Matching
Message-Id: <3E52B77F.4086D47C@earthlink.net>
Mikey wrote:
[snip]
> I'm trying to sort the following data by Height:
> (this data resides in store.dat, each field separated by a space)
>
> DOB Cash Name Height
>
> 12.01.1963 100 John Smith 5.11
> 27.02.1955 200 Jimmy Dolan Andrews 5.8
> 16.03.1977 400 Johnny Barrosh 5.4
> 09.01.1987 200 Steve McHooter 5.5
> 01.02.1983 100 Blaro Van Daronimo 4.4
>
> I can't work out a correct pattern matching line which will
> successfully separate these fields.
The problem is that the fields are seperated by spaces, and the Name
field has a variable number of embeded spaces.
Thus, you can't just split on spaces and get the 4th element after
splitting.
However... the height field is always the *last* field when splitting on
whitespace, even if the number of fields before it vary. So, you can do
the following:
open( FH, "<", "store.dat" ) or die $!;
print sort {
(split(' ', $a))[-1] <=> (split(' ', $b))[-1]
} <FH>;
__END__
Note that for large files, this repeated splitting is innefficient...
One may get faster results with:
open( FH, "<", "store.dat" ) or die $!;
print $_->[0] for
sort { $a->[1] <=> $b->[1] }
map [ $_, /(\S+)$/ ],
<FH>; # read the data in.
__END__
This the 'Schwartzian-Transform', a commonly used optomization when
sorting data with perl.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: 18 Feb 2003 12:09:08 -0800
From: perl@nodata.com (Matt Baran)
Subject: newbie logfile processing question
Message-Id: <c6c293ef.0302181209.61a5df53@posting.google.com>
I have a file that looks something like the following:
Feb 12 00:00:17 server01 daemon[4251]: Connect: 127.0.0.1->127.0.0.1
Feb 12 00:00:17 server01 daemon[4251]: Auth: 127.0.0.1->127.0.0.1
user="Username1" passwd="VV.oq6x" server="someotherserver" port="1111"
status="ok"
Feb 12 00:00:20 server01 daemon[4250]: Close: 127.0.0.1->127.0.0.1
user="Username2" received=36740 sent=181968
Feb 12 00:00:21 server01 daemon[428]: Close: 192.168.1.2->192.168.1.3
user="Username3" received=3586 sent=25272
Feb 12 00:00:21 server01 daemon[4251]: Close: 127.0.0.1->127.0.0.1
user="Username1" received=36457 sent=200464
Feb 12 00:00:21 server01 daemonn[4255]: Connect: 127.0.0.1->127.0.0.1
Feb 12 00:00:22 server01 daemon[4255]: Auth: 127.0.0.1->127.0.0.1
user="Username1" passwd="VV.oq6x" server="someotherserver" port="1111"
status="ok"
Feb 12 00:00:22 server01 daemon[4255]: Close: 127.0.0.1->127.0.0.1
user="Username1" received=38 sent=285
Feb 12 00:00:29 server01 daemon[4259]: Connect:
192.168.1.2->192.168.1.3
Feb 12 00:00:29 server01 daemon[4259]: Closing NULL session:
192.168.1.2->192.168.1.3 username=(null)
Feb 12 00:00:30 server01 daemon[4262]: Connect:
192.168.1.2->192.168.1.3
Feb 12 00:00:30 server01 daemon[4262]: Closing NULL session:
192.168.1.2->192.168.1.3 username=(null)
Feb 12 00:00:34 server01 daemon[4269]: Connect: 127.0.0.1->127.0.0.1
What I want to do is process just the lines containing Auth, and
capture the timestamp, username, and password from those lines into a
CSV file.
I'm very new to perl and I've managed to babystep to the point where I
can grab just the lines I want, but I can't seem to grasp how to get
the information I want from those lines and add that to a separate
file.
Any help would be greatly appreciated.
-Matt Baran
------------------------------
Date: 18 Feb 2003 20:18:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: newbie logfile processing question
Message-Id: <b2u4dv$glc$1@mamenchi.zrz.TU-Berlin.DE>
Matt Baran <perl@nodata.com> wrote in comp.lang.perl.misc:
> I have a file that looks something like the following:
[data mostly snipped]
> Feb 12 00:00:17 server01 daemon[4251]: Auth: 127.0.0.1->127.0.0.1
> user="Username1" passwd="VV.oq6x" server="someotherserver" port="1111"
> status="ok"
>
> What I want to do is process just the lines containing Auth, and
> capture the timestamp, username, and password from those lines into a
> CSV file.
>
> I'm very new to perl and I've managed to babystep to the point where I
> can grab just the lines I want, but I can't seem to grasp how to get
> the information I want from those lines and add that to a separate
> file.
Splitting the line on white space wuold be a good start. See
perldoc -f split.
Anno
------------------------------
Date: Tue, 18 Feb 2003 19:31:41 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: parsing string with whitespace
Message-Id: <3E5289D2.913EDEC@acm.org>
"Eric J. Roode" wrote:
>
> thomas_rp@hotmail.com (Thomas Abraham) wrote in
> news:5cf0e3b0.0302172008.67b146a2@posting.google.com:
> >
> > How can I convert the following string:
> >
> > spacespacespaceHellospacespaceWorld!spacespacespacespace
> >
> > into an array that contains the following elements
> >
> > item[0] = spacespacespace
> > item[1] = Hello
> > item[2] = spacespace
> > item[3] = World!
> > item[4] = spacespacespacespace
> >
> > where space stands for whitespace? Please note that I *need* the
> > number spaces (not trim it).
>
> @item = split /(\s+)/, $your_string;
That gives you an extra undefined element at the beginning of the array.
$ perl -le'$string = " Hello World! ";print ">$_<" for split /(\s+)/, $string'
><
> <
>Hello<
> <
>World!<
> <
However using /(\S+)/ will work:
$ perl -le'$string = " Hello World! ";print ">$_<" for split /(\S+)/, $string'
> <
>Hello<
> <
>World!<
> <
John
--
use Perl;
program
fulfillment
------------------------------
Date: 18 Feb 2003 18:41:03 GMT
From: nobody <noemail@nowhere.net>
Subject: Re: Perl & VB without activeperl on Windows??
Message-Id: <Xns93268B86129D3abccbaabc@129.250.170.81>
>>> ... is there something I can do to allow my vb and perl
>>> program to work together on a windows machine without activeperl??!!
>> You could use ActiveState's PerlApp utility to make your Perl
>> script into an .exe. (It's part of their Perl Dev. Kit (PDK), costs
>> $).
>
> Or take a look at PAR.pm on CPAN.
Sounds cool! Esp. "pp".
------------------------------
Date: 18 Feb 2003 19:51:31 GMT
From: nobody <noemail@nowhere.net>
Subject: Re: Perl & VB without activeperl on Windows??
Message-Id: <Xns93269777FF4D0abccbaabc@129.250.170.99>
>>>> ... is there something I can do to allow my vb and perl program to
>>>> work together on a windows machine without activeperl??!!
>>> You could use ActiveState's PerlApp utility to make your Perl
>>> script into an .exe. ...
>> Or take a look at PAR.pm on CPAN.
> Sounds cool! Esp. "pp".
(replying to myself)
But it still needs core Perl on the target machine. :(
------------------------------
Date: Tue, 18 Feb 2003 23:30:10 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Regular Expression Noob
Message-Id: <pan.2003.02.18.22.08.34.120088@aursand.no>
On Tue, 18 Feb 2003 18:04:11 +0000, Abigail wrote:
>> my @ani_list = $string =~ /ANI\=(\d+)/g; # untested
> Why did you escape the equal sign?
Because he wanted someone else to actually test his code? :)
--
Tore Aursand - tore@aursand.no - http://www.aursand.no/
------------------------------
Date: Tue, 18 Feb 2003 15:43:23 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Returning the field list from DBI
Message-Id: <3E529AEB.56EC1900@earthlink.net>
Jason Singleton wrote:
>
> Well I think the subject says it all here :) but basically I just need
> to know the fields returned from a query when I don't name them eg
> using *
@{ $sth->{NAME} }, I think.
> Also how do I change the read position in the returned data? I don't
> want to return all records to the user at once I want it to display
> the returned data in pages like a search engine.
There's two possible ways, both of which require support from the SQL
driver.
One is to use a LIMIT clause; this is the prefered way.
The other is to use the ->func method on the statement handle, to tell
the driver that you want to skip forward some number of records. I'm
not sure what databases, if any, have this kind of functionality.
There's sortof a third way -- simply read and discard as many records as
you want to skip. This is innefficient, but portable.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Tue, 18 Feb 2003 16:33:04 -0600
From: cp <cpryce@pryce.net>
Subject: Re: Returning the field list from DBI
Message-Id: <BA7810BF.18555%cpryce@pryce.net>
in article 3E529AEB.56EC1900@earthlink.net, Benjamin Goldberg at
goldbb2@earthlink.net wrote on 2/18/03 2:43 PM:
>>Jason Singleton wrote:
>>
>> Well I think the subject says it all here :) but basically I just need
>> to know the fields returned from a query when I don't name them eg
>> using *
>
> @{ $sth->{NAME} }, I think.
Yes. And also:
$sth->{NAME_uc}
$sth->{NAME_lc}
Which force the names fetched to all upper case or all lower case. Returns
an array ref.
$sth->{NUM_OF_FIELDS}
Returns number of fields returned.
Above methods work on a successfully executed statement handle.
>
>> Also how do I change the read position in the returned data? I don't
>> want to return all records to the user at once I want it to display
>> the returned data in pages like a search engine.
>
> There's two possible ways, both of which require support from the SQL
> driver.
>
> One is to use a LIMIT clause; this is the prefered way.
LIMIT is supported by a few databases. I know for sure MySQL syntax:
SELECT * FROM tablename WHERE [condition] LIMIT n,m
Where n is the starting position and m the number of rows. Not sure what
error is generated if n is greater than the total number of rows, so don't
do that.
I think a few others support LIMIT n to limit the query to the first n rows
(DBASE, and Postgres?)
MS SQL supports a limit with the keyword TOP, as in:
SELECT TOP n [PERCENT] * FROM ...
Where n is the number of rows returned. If PERCENT is specified, the n
PERCENT of rows are returned.
I often ask MS SQL for field names with:
SELECT TOP 0 * FROM tablename
And then use $sth->{NAME_lc}
None of these is a portable method. For portability in a CGI application,
you will should return the entire result set, and keep track of the cursor
position with hidden variables. HTML::Template has some built-in techniques
for this, IIRC.
cp
------------------------------
Date: Tue, 18 Feb 2003 19:14:54 GMT
From: Dan Wilga <dwilga-MUNGE@mtholyoke.edu>
Subject: Re: Socket command
Message-Id: <dwilga-MUNGE-878692.14145318022003@nap.mtholyoke.edu>
In article <1064154.gSdCNXuiSg@nyoga.dubu.de>,
"Harald H.-J. Bongartz" <bongie@gmx.net> wrote:
> Catharsis wrote:
> > print SOCKET "hello" || die "argh I couldnt say hello";
>
> Catching up on unread articles, I couldn't leave that uncommented.
> This statement is parsed as
> print SOCKET ("hello" || die "argh ...");
> which for sure is not what you want.
>
> Either use "or" instead of "||":
> print SOCKET "hello" or die "argh...";
> or use parentheses:
> print (SOCKET "hello") || die "argh...";
Or, to be even more explicit about what's going on:
(print SOCKET "hello") || die "argh...";
--
Dan Wilga dwilga-MUNGE@mtholyoke.edu
** Remove the -MUNGE in my address to reply **
------------------------------
Date: 18 Feb 2003 13:21:33 -0800
From: georgem@crystalgraphics.com (george)
Subject: Subroutine does not 'see' parameter passed to it
Message-Id: <620c2f02.0302181321.34425b33@posting.google.com>
I created a Module that contained a subroutine. I imported the
subroutine into my program (using 'use'). When I call the subroutine
with a parameter, the subroutine executes, but does not 'see' the
paramter I pass to it.
I know the subroutine is executing, because it writes or updates a
database record.
Here is a sketch of the code:
This is the Module:
package PURCHASETRACK;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw( writeTrackRecord );
sub writeTrackRecord;
{
my $somevar = shift;
... does some stuff, and calls some other
... subroutines that are defined in this module.
}
sub anothersubroutine
}
....
}
(a few more subroutines are defined.)
.
.
.
1;
#End of Module -------------------------------------------
Here is how I imported and called the function:
#!/usr/bin/perl5
push @INC, "d:\\InetPubic\\test\\webroot\\pgm";
require "ppdata3.pl";
use lib "d:\\InetPubic\\test\\webroot\\pgm";
use PURCHASETRACK;
.
.
.
&parse_form;
writeTrackRecord('P2');
.
.
.
#End of Program----------------------------------------
writeTrackRecord is supposed to write the value of the passed
parameter to a database record. However, the value written is always
blank.
I know that the value in $somevar can make it to the database, because
if I
set the value of $somevar inside of writeTrackRecord, then the value
will get written to the database.
sub writeTrackRecord;
{
#$somevar = shift;
$somevar = 'a value';
writeToDatabase($somevar);
}
With the code above, 'a value' will get written to the database.
But with the following code, the value in the database always ends up
being blank:
sub writeTrackRecord;
{
$somevar = shift;
writeToDatabase($somevar);
}
Also, another very strange thing, is that in order for the subroutine
to work,
I need to put a ';' at the end of the subroutine name in the
definition:
sub writeTrackRecord;
{
.
.
.
}
I originally put the semicolon in by mistake. (I did not intentionally
add the semicolon, but my fingers are just used to typing semicolons
at the end on a line.) But when I later removed it, the subroutine
would not work at all.
If anyone knows why the parameter cannot be 'seen' by my subroutine,
and why the subroutine definition only works with the semicolon, I'd
REALLY appreciate it.
Thanks,
George
------------------------------
Date: 18 Feb 2003 21:59:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Subroutine does not 'see' parameter passed to it
Message-Id: <b2uaci$glc$2@mamenchi.zrz.TU-Berlin.DE>
george <georgem@crystalgraphics.com> wrote in comp.lang.perl.misc:
> I created a Module that contained a subroutine. I imported the
> subroutine into my program (using 'use'). When I call the subroutine
> with a parameter, the subroutine executes, but does not 'see' the
> paramter I pass to it.
[lots snipped]
> Also, another very strange thing, is that in order for the subroutine
> to work,
> I need to put a ';' at the end of the subroutine name in the
> definition:
>
> sub writeTrackRecord;
> {
> .
> .
> .
> }
That turns the line "sub ..." to a mere declaration. The code inside
the sub block would run when the file is read, not when the sub is
called. If it is called at this stage, you'll get a runtime error
"Undefined subroutine...".
If it doesn't compile without the semicolon, it is wrong.
Anno
> I originally put the semicolon in by mistake. (I did not intentionally
> add the semicolon, but my fingers are just used to typing semicolons
> at the end on a line.) But when I later removed it, the subroutine
> would not work at all.
>
> If anyone knows why the parameter cannot be 'seen' by my subroutine,
> and why the subroutine definition only works with the semicolon, I'd
> REALLY appreciate it.
>
> Thanks,
>
> George
------------------------------
Date: Tue, 18 Feb 2003 22:54:10 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Subroutine does not 'see' parameter passed to it
Message-Id: <mQy4a.704$ID6.2139@newsc.telia.net>
george wrote:
> sub writeTrackRecord;
> {
>
> my $somevar = shift;
>
> ... does some stuff, and calls some other
> ... subroutines that are defined in this module.
> }
> ...
> Also, another very strange thing, is that in order for the subroutine
> to work, I need to put a ';' at the end of the subroutine name in the
> definition:
With that semicolon, you just declare a subroutine name with the line
'sub writeTrackRecord;'. The following block is then *not* part of the
subroutine, but just a separate block.
> But when I later removed [the semicolon], the subroutine
> would not work at all.
Can you be more precise? Exactly what did or did not happen? Which error
messages did Perl give you (assuming that you are using strictures and
warnings...)?
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 18 Feb 2003 22:10:59 -0000
From: "Mikey" <PleaseDontThrowSpam@Me.com>
Subject: Unsuccesful "Print"
Message-Id: <b2uauu$fi9$1@wisteria.csv.warwick.ac.uk>
Hi,
I am trying to run a Perl file on a Unix machine.
The following command successfully runs on a windows machine
print "Incorrect Usage\n";
But on the Unix machine nothing happens, the program doesn't error or
anything, it just fails to print.
The weird thing is that when I give an invalid option to the Perl file the
following is successfully output:
Unknown option: x
So what is happening? Why are somethings being out put whilst others aren't?
How can I fix it so that all is desired output is successful?
Please help,
Mikey
PS. Sorry for the cross post, I think I got the wrong newsgroup
------------------------------
Date: 18 Feb 2003 22:52:55 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Unsuccesful "Print"
Message-Id: <b2udg7$jhq$1@canopus.cc.umanitoba.ca>
In article <b2uauu$fi9$1@wisteria.csv.warwick.ac.uk>,
Mikey <PleaseDontThrowSpam@Me.com> wrote:
:I am trying to run a Perl file on a Unix machine.
:The following command successfully runs on a windows machine
:print "Incorrect Usage\n";
:But on the Unix machine nothing happens, the program doesn't error or
:anything, it just fails to print.
And is that -all- there is in the program?
:The weird thing is that when I give an invalid option to the Perl file the
:following is successfully output:
:Unknown option: x
Clearly not, then.
:So what is happening? Why are somethings being out put whilst others aren't?
Insufficient information.
$ perl
print "Incorrect Usage\n";
Incorrect Usage
What I would suspect is that something in the code select's a
different handle.
$ perldoc -f select
select FILEHANDLE
select Returns the currently selected filehandle. Sets the
current default filehandle for output, if FILEHANDLE
is supplied. This has two effects: first, a "write"
or a "print" without a filehandle will default to
this FILEHANDLE. Second, references to variables
related to output will refer to this output channel.
--
'ignorandus (Latin): "deserving not to be known"'
-- Journal of Self-Referentialism
------------------------------
Date: 18 Feb 2003 14:31:36 -0800
From: the_game_is_never_over@yahoo.co.uk (g)
Subject: Re: use DBI;
Message-Id: <2059e247.0302181431.797e2cdb@posting.google.com>
Thanks for your help guys, I have now installed dbi but when to
install DBD::Mysql though active perl it says its not indented for
this build of perl.:((
I use windows 2000, perl 5.6 any1 have any ideas
------------------------------
Date: Tue, 18 Feb 2003 20:48:38 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Using different hashes.
Message-Id: <Xns9326A0D57D2A5dkwwashere@216.168.3.30>
Michael Carman <mjcarman@mchsi.com> wrote on 18 Feb 2003:
> On 2/18/2003 10:32 AM, Richard S Beckett wrote:
>>
>> I have a subroutine that does the same thing 3 times, but for
>> different hashes, like this...
>>
[big snip]
>
> Really, though, your data structures are awkward. There's probably
> a better way to organize your data that would make the code much
> cleaner.
That's more or less why I posted an example illustrating an idea rather
than modifying the OP's code. Alternately, I was too lazy to try and
figure out which parts to change. :-)
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: Tue, 18 Feb 2003 19:55:55 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: Where is DB_File in redhat 8.0?
Message-Id: <fdw4a.17334$0L3.6547317@news2.news.adelphia.net>
"joe dekk" <no_email@none.abc> wrote in message
news:3E528222.4090407@none.abc...
> Hi
>
> RedHat 8.0 comes with perl 5.8.0 but DB_File
> is not there. But when I looked on cpan
> it apparently is in perl 5.8.0 and I cannot
> locate .tar.gz file for me install it. I
> find DB_File.pm but I am not sure whether
> it is appropriate it install that file
>
> Any advice would be appreciated
>
> Thanks in advance
>
I don't think DB_File came with my ActiveState 5.8 on Windows. However, the
TheoryX site does have it.
http://theoryx5.uwinnipeg.ca/
------------------------------
Date: Tue, 18 Feb 2003 20:10:09 GMT
From: Dan Wilga <dwilga-MUNGE@mtholyoke.edu>
Subject: Re: Where is DB_File in redhat 8.0?
Message-Id: <dwilga-MUNGE-159428.15100818022003@nap.mtholyoke.edu>
In article <3E528222.4090407@none.abc>, joe dekk <no_email@none.abc>
wrote:
> Hi
>
> RedHat 8.0 comes with perl 5.8.0 but DB_File
> is not there. But when I looked on cpan
> it apparently is in perl 5.8.0 and I cannot
> locate .tar.gz file for me install it. I
> find DB_File.pm but I am not sure whether
> it is appropriate it install that file
Of course you can just install DB_File. You may also want to install
BerkeleyDB if you are doing the prorgamming, since it is much more
powerful.
The easiest way is with the CPAN module:
perl -MCPAN -eshell
install DB_File
--
Dan Wilga dwilga-MUNGE@mtholyoke.edu
** Remove the -MUNGE in my address to reply **
------------------------------
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 4581
***************************************