[24533] in Perl-Users-Digest
Perl-Users Digest, Issue: 6713 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 21 14:06:01 2004
Date: Mon, 21 Jun 2004 11:05:07 -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, 21 Jun 2004 Volume: 10 Number: 6713
Today's topics:
Check syntax question... (Bob)
Re: Check syntax question... <ittyspam@yahoo.com>
Re: Creating a scalar value from other scalars <Joe.Smith@inwap.com>
DBIx::DBSchema::Table support for composite primary key <il.fogg@bigpond.net.au>
Re: Embedding perl in Java <Joe.Smith@inwap.com>
Re: Getting Values from Hashes <georgekinley@hotmail.com>
Help converting HTML to CSV <jimsimpson@cox.net>
Re: Help converting HTML to CSV <ittyspam@yahoo.com>
Re: how do I convert a file into its 8 bit 0/1 pattern <remorse@partners.org>
How to directly get the script-path. <a@b.c>
Re: How to directly get the script-path. (Sam Holden)
Re: How to directly get the script-path. <ittyspam@yahoo.com>
Re: How to directly get the script-path. <trammell+usenet@hypersloth.invalid>
Re: How to update a txt file with another txtfile? <scobloke2@infotop.co.uk>
Re: Perl TIMOUT <remorse@partners.org>
problem between perl-gtk2 and POE::Session <iron@ironiq.hu>
Re: remove redundant elements in an array <pinyaj@rpi.edu>
Re: SQL Error <tore@aursand.no>
Re: WMI and boolean values from Win32_Processor <Petri_member@newsguy.com>
XML::Simple - memory leak? <jcasadonte@northbound-train.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Jun 2004 09:52:47 -0700
From: bobx@linuxmail.org (Bob)
Subject: Check syntax question...
Message-Id: <1001ff04.0406210852.1937aeb1@posting.google.com>
I am going through another persons code. I turned on "strict" and
"warnings" and I am not sure what to do about this warning:
"Scalar value @_[0] better written as $_[0] at update_patch.pl line
939."
Should I change it to reflect what is suggested? Why did it suggest
that? I am just a wee learner of Perl.
Robert
------------------------------
Date: Mon, 21 Jun 2004 13:02:18 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Check syntax question...
Message-Id: <20040621125558.N23512@dishwasher.cs.rpi.edu>
On Mon, 21 Jun 2004, Bob wrote:
> I am going through another persons code. I turned on "strict" and
> "warnings" and I am not sure what to do about this warning:
>
> "Scalar value @_[0] better written as $_[0] at update_patch.pl line
> 939."
>
> Should I change it to reflect what is suggested?
Almost certainly yes. We'd have to see the code to be 100% certain, but
the chances of it not being better changed are very unlikely.
> Why did it suggest that?
In Perl, $ is used to mean scalar, which is a single value. @ is used to
mean array, a collection of values. The syntax of @array[2,3,4] for
example, means "the set containing the third, fourth, and fifth elements
of @array". The syntax @array[2] means "the set containing the third
element of @array". $array[2], on the other hand, means simply "the third
element of @array". There is almost never a reason to use a collection
containing one element where all you actually need is that one element.
That is what that warning is about.
> I am just a wee learner of Perl.
Read up! :-) Take a look at
perldoc perlsyn
for the syntax of Perl, and
perldoc perldiag
for a description and explanation of all the warnings you may encounter.
Paul Lali
------------------------------
Date: Mon, 21 Jun 2004 17:38:45 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Creating a scalar value from other scalars
Message-Id: <F2FBc.89683$0y.27693@attbi_s03>
Robert TV wrote:
> I read somewhere once that creating a scalar value from other scalars is bad.
Using tainted data is bad. Anything that comes from %ENV or @ARGV or from
CGI is tainted. Using such data without untainting it can allow an outside
user to walk all over your data. Changing the first line of your script to
"#!/usr/bin/perl -T" will enable taint checking.
> $ipaddress = $ENV{'REMOTE_ADDR'};
> $ipaddress =~ s/\.//g; #remove periods from IP address
> $filename = "$ipaddress\_$timestamp\.dat";
And what happens if $ENV{REMOTE_ADDR} happens to be '..\..\..\win32\system'?
[Actually, REMOTE_ADDR can probably be trusted as its value comes from
the web server. But many other values in %ENV cannot be trusted.]
Instead of stripping dots, you could use the corresponding 32-bit integer.
use Socket;
$ip_numeric = unpack "N", inet_aton $ENV{REMOTE_ADDR};
That will keep '12.122.1.50' (with a value of 209324850) distinct from
'12.12.211.50' (which has a value of 202167090).
-Joe
------------------------------
Date: Mon, 21 Jun 2004 13:56:49 GMT
From: I & L Fogg <il.fogg@bigpond.net.au>
Subject: DBIx::DBSchema::Table support for composite primary keys
Message-Id: <BOBBc.48159$sj4.16784@news-server.bigpond.net.au>
Ivan,
I'm experimenting with the DBIx::DBSchema module to copy a proprietary
DB into mysql (via an ODBC connection to the source DB).
I pull the DB schema with a variety of DBI calls, notably column_info
and primary_key. Building the DBIx::DBSchema::Table is fairly
straightforward when the primary key for the table is a single column.
However, when I have a composite primary key, it fails whenever
$table->primary_key is called.
For example, in the following fragment, I try to "fool" the Table module
into accepting multiple columns as the primary key by assigning a
comma-separated list, but the sql_create_table call barfs as soon as it
accesses primary_key.
my @pri_key = $dbh->primary_key($catalog, $schema, $table);
$table->primary_key(join(',', @pri_key));
my $sql = $table->sql_create_table($dbh2);
Checking the definition of primary_key, it is specifically excluding my
attempt to "fake it" thought its use of the regexp /^(\w*)$/ (line 279
in module DBIx::DBSchema::Table).
Some brief experimentation to allow primary_key to handle a comma
separated list...
sub primary_key {
my($self,$value)=@_;
if ( defined($value) ) {
$self->{primary_key} = $value;
} else {
=> $self->{primary_key} =~ /^(\w*)(,\w*)*$/
#aah!
or die "Illegal primary key: ", $self->{primary_key};
=> $2 ? $1.$2 : $1;
}
}
And the code fragment above generates the correct SQL for simple or
composite primary keys.
This seems way too simple. What else would break?
Cheers, Iain
------------------------------
Date: Mon, 21 Jun 2004 17:04:21 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Embedding perl in Java
Message-Id: <pyEBc.127932$3x.102214@attbi_s54>
Shalini Joshi wrote:
> .. All this while we were really
> feeling smart thinking we could actually solve the problem of hiding
> the source by embedding perl in java. Is there a solution to this
> problem? Do u mean to say that no commercial product makes use of Perl
> as a source language??
There are many commercial products that use Perl.
Including the source code does not make a product non-commercial.
You could store the Perl part as an encrypted string, then have
Java decrypt the string before feeding it to the embedded Perl
interpreter. But that has the same flaw as others; by monitoring
the Java program as it runs, the decryption process is revealed.
-Joe
------------------------------
Date: Mon, 21 Jun 2004 14:57:45 GMT
From: "George Kinley" <georgekinley@hotmail.com>
Subject: Re: Getting Values from Hashes
Message-Id: <JHCBc.19491$g4.375824@news2.nokia.com>
Paul Lalli wrote:
> On Fri, 18 Jun 2004, George Kinley wrote:
>
> > Paul Lalli wrote:
> >
> > > On Fri, 18 Jun 2004, George Kinley wrote:
> > >
> > > > Hi
> > > > I have an hash as $Hash{Name}{NickName}
> > > > Where Name is String
> > > > NickName Array
> > > > I can get All NickName in an array as
> > > >
> > > > @AllNN=values @{$$Hash{Name}}
> > > >
> > > > my query is Why I cant get the same result with
> > > > @AllNN=values %{$Hash{Name}}
> > > > or
> > > > @AllNN=values $Hash{Name}
> > > >
> > >
> > > I don't quite understand your claim that values @{$$Hash{Name}}
> > > works like you want it. Even if I have misunderstood your
> > > datastructure, you cannot pass an array to values(). This is a
> > > syntax error.
> > >
> >
> > I believe its my mistake that I did not mentioned that I was getting
> > this HASH as reference from another procedure, so that is the
> > reason I need to dereference it by double "$"
>
>
> This is not at all the issue. You're claiming that you're passing an
> array (something that starts with '@') to the values() function. This
> doesn't work. It's a syntax error. It doesn't matter how many
> levels of dereferencing are involved.
>
> Post a short but complete program that illustrates your problem if
> you're still having one.
>
> Paul Lalli
SOrry for asking the wrong question I was also not using the "values"
Sorry again
But my questions was
my query is Why I cant get the same result with
> > > > @AllNN=values %{$Hash{Name}}
> > > > or
> > > > @AllNN=values $Hash{Name}
> > > >
that was explained by you thanks
--
-Gk
------------------------------
Date: Mon, 21 Jun 2004 10:03:38 -0400
From: "Jim Simpson" <jimsimpson@cox.net>
Subject: Help converting HTML to CSV
Message-Id: <0VBBc.10721$wD3.2141@lakeread03>
I need to convert an HTML file to a tab delimited or CSV file. Can someone
who has done this give me some pointers please.
Thanks
Jim
------------------------------
Date: Mon, 21 Jun 2004 10:13:46 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Help converting HTML to CSV
Message-Id: <20040621100958.S23512@dishwasher.cs.rpi.edu>
On Mon, 21 Jun 2004, Jim Simpson wrote:
> I need to convert an HTML file to a tab delimited or CSV file. Can someone
> who has done this give me some pointers please.
It would be helpful if you would give a more descriptive problem
statement. What kind of conversion are you looking for? As in, what are
the fields of the CSV file, and where do they come from? Are you trying
to tokenize the HTML document so that every tag is a field? Are you
trying to parse it so that every pair of open-close tags will contain the
included tags as fields?
My *guess* is that you are trying to copy an HTML table's data into a CSV
file. This is only a guess of course, because you haven't been explicit
in what you want to do. For this task, I would recommend you look at the
following modules, available from search.cpan.org:
Text::CSV_XS
HTML::TableExtract
Read the documentations for those, and make an attempt. If you run into
problems, let us know.
Paul Lalli
------------------------------
Date: Mon, 21 Jun 2004 12:22:11 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: how do I convert a file into its 8 bit 0/1 pattern ?
Message-Id: <remorse-A45DE9.12221021062004@plato.harvard.edu>
In article <0kTxc.63973$3x.54438@attbi_s54>,
Joe Smith <Joe.Smith@inwap.com> wrote:
> Jack wrote:
>
> > I want to capture the exact 0/1 bitstream from a datafile. How do I
> > accomplish this ?
>
> Just read in the data and write it back out.
>
> The data will come in as individual bytes (8 bits each) and
> the exact 1/0 bitstream of 8-bit bytes will be written out.
With the caveat that on some operating systems you need to 'binmode' (or
otherwise open in binary mode) the file handles.
Ricky
------------------------------
Date: Mon, 21 Jun 2004 14:05:15 +0200
From: ZZT <a@b.c>
Subject: How to directly get the script-path.
Message-Id: <cb6itr$29o$1@news1.wdf.sap-ag.de>
Hi,
I'd like to get the directory of the currently running script (not the
working directory) but without concat constructs with $0 and getcwd().
Is there an easy way, an internal or ENV var?
thanks a lot
------------------------------
Date: 21 Jun 2004 12:57:53 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: How to directly get the script-path.
Message-Id: <slrncddmqh.hnr.sholden@flexal.cs.usyd.edu.au>
On Mon, 21 Jun 2004 14:05:15 +0200, ZZT <a@b.c> wrote:
> Hi,
>
> I'd like to get the directory of the currently running script (not the
> working directory) but without concat constructs with $0 and getcwd().
> Is there an easy way, an internal or ENV var?
perldoc -q "directory my program lives in"
--
Sam Holden
------------------------------
Date: Mon, 21 Jun 2004 09:07:34 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: How to directly get the script-path.
Message-Id: <20040621090443.U23512@dishwasher.cs.rpi.edu>
On Mon, 21 Jun 2004, ZZT wrote:
> Hi,
>
> I'd like to get the directory of the currently running script (not the
> working directory) but without concat constructs with $0 and getcwd().
> Is there an easy way, an internal or ENV var?
>
> thanks a lot
You might want a combination of File::Basename::dirname and
File::Spec::rel2abs. Something like this, perhaps:
[untested]
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Spec;
my $dir = File::Spec->rel2abs(dirname($0));
print "$dir\n";
Paul Lalli
------------------------------
Date: Mon, 21 Jun 2004 16:34:10 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: How to directly get the script-path.
Message-Id: <slrncde3g1.qgn.trammell+usenet@hypersloth.el-swifto.com.invalid>
On Mon, 21 Jun 2004 14:05:15 +0200, ZZT <a@b.c> wrote:
> I'd like to get the directory of the currently running script (not the
> working directory) but without concat constructs with $0 and getcwd().
> Is there an easy way, an internal or ENV var?
perldoc FindBin
------------------------------
Date: Mon, 21 Jun 2004 14:28:45 +0000 (UTC)
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: How to update a txt file with another txtfile?
Message-Id: <cb6ras$1rj$1@sparta.btinternet.com>
ricky wrote:
> I have the following tab delimited master.txt file which has about
> 1000 records and looks like this:
>
> NTADPH0853M00 Premier WST None "Lee, Tom" 4607 "Lee, Tom"
> NTADPH0892M00 Standard; Prime Shift Monitoring WST None "JOHNSON, DON"
> ntadph0919m00 Standard; Prime Shift Monitoring wst None "Lee, Tom"
> ntadph0961m00 Standard; Prime Shift Monitoring WST None "Wayne, John"
> NTADPH0964L01 Premier WST None "Smith, Adam" 3786 "Smith, Adam"
>
> Then I have a tab delimited update.txt file which has about 1000
> records also and looks like this:
>
> NTAPTH0236M01 19687 307 1 1
> NTADPH0853M00 31612 508 9 24
> NTAPTH0271M00 21735 307 4 4
> ntadph0919m00 19072 301 2 3
> NTADPH0964L01 18000 307 4 4
>
> I want to create a Perl script that will check for matches with the
> update.txt file against the first field in the master.txt file. If a
> match is found the master.txt file would be appended with the last
> four fields from the update.txt file.
> There are 3 records from the update.txt file that are found in the
> master.txt file in the above example.
>
> The result would look like this:
>
> NTADPH0853M00 Premier WST None "Lee, Tom" 4607 "Lee, Tom" 31612 508 9
> 24
> ntadph0919m00 Standard; Prime Shift Monitoring wst None "Lee, Tom"
> 19072 301 2 3
> NTADPH0964L01 Premier WST None "Smith, Adam" 3786 "Smith, Adam" 18000
> 307 4 4
read the updates into a hash
whilst reading master
if the hash exists for that key
print oldstuff and hashvalue to newfile
> I also want to produce an error listing of all the records in the
> update.txt file that don't match up with the master.txt file.
undefine the hash elements as you emit them
at the end, print remaining hash elements
------------------------------
Date: Mon, 21 Jun 2004 12:33:02 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: Perl TIMOUT
Message-Id: <remorse-8184FD.12330221062004@plato.harvard.edu>
In article <d0c53d.0406100039.4de3c95d@posting.google.com>,
wwfpalmaria@libero.it (Achille) wrote:
> Hi,
> I run a PERL script from Browser (internet Explorer) but the execution
> is very slow so the IIS stop my perl.exe
>
> I thinks the my problem is the "timout".
>
> I need to insert in my script the string of the command like ASP:
> Server.ScriptTimeOut = 7200
There are two things that might time out -- one is the server, the other
is the client.
The ASP command that you noted is only valid in an ASP environment --
are you using PerlScript to create an ASP in Perl? If not, you are
probably running a CGI. To change the server timeout for CGIs, you will
change it for all of them. This can be changed somewhere in the server
configuration, although you will probably need to restart IIS completely.
If the browser is what is timing out, then you will need to convince the
browser to wait. This can (for MSIE) be done by sending at least 1K of
data back to the browser. I have one case where I needed to do this
(converting a large excel spreadsheet into plain text, filtering the
answers, and sending back error data). To solve the problem of the
browser timing out, I did the following:
# near the start of the program:
$| = 1; # turn off output buffering
my $q = new CGI;
# later on
# send some data back to keep MSIE happy
print $q->header();
print $q->start_html();
print "<!--", 'x' x 2000, '-->\n";
# continue processing
HTH,
Ricky
------------------------------
Date: Mon, 21 Jun 2004 12:10:27 +0200
From: Krisztian VASAS <iron@ironiq.hu>
Subject: problem between perl-gtk2 and POE::Session
Message-Id: <2jnqc1F12ei5vU1@uni-berlin.de>
Hello...
I have some problem with perl-gtk2 and POE...
I'd like to write a small chat client in gtk2, but it doesn't want to
work as I'd like to.
If the program starts, 2 Gtk2::Window is opened (the main window and the
login window). After writing the nick and clicking to the OK button, the
connection should start. In the background I'm watching the OK button's
signal_connect("clicked") event, and I'd like to start a POE::Session
callback, but I can't see the $_[SESSION] variable in signal_connect().
The code is viewable here: http://nomorepasting.com/paste.php?pasteID=14758
The problem is in 200th line.
I could see, that the $var variable contains the $okbutton in akarmi()
function insted of the $_[SESSION].
Thanks for the early answer.
IroNiQ
--
Web: http://ironiq.hu
Email: iron@ironiq.hu
LinuxCounter: #331532
------------------------------
Date: Mon, 21 Jun 2004 09:48:12 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Yiping Zhan <yzhan@andrew.cmu.edu>
Subject: Re: remove redundant elements in an array
Message-Id: <Pine.SGI.3.96.1040621094751.18367B-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On Fri, 18 Jun 2004, Yiping Zhan wrote:
>Say, @a = qw(1 2 3 1 4 5);
>
>What is a good way to get (1 2 3 4 5)?
Tie::Array::Unique is a rather effortless way.
--
Jeff Pinyan RPI Acacia Brother #734 RPI Acacia Corp Secretary
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Mon, 21 Jun 2004 14:08:50 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: SQL Error
Message-Id: <pan.2004.06.21.12.08.49.674529@aursand.no>
On Mon, 21 Jun 2004 08:12:32 +0200, Alex wrote:
> Can't connect to local MySQL server through socket
> '/var/lib/mysql/mysql.sock' (2)
What is your Perl question? Your problem has clearly something to do with
MySQL, not Perl.
--
Tore Aursand <tore@aursand.no>
"When you see a good idea look for a better one. You should never play
the first good move that comes into your head." (Bruce Pandolfine)
------------------------------
Date: 21 Jun 2004 01:33:42 -0700
From: Petri <Petri_member@newsguy.com>
Subject: Re: WMI and boolean values from Win32_Processor
Message-Id: <cb66h602n66@drn.newsguy.com>
In article <6e613a32.0406201520.2e4c618f@posting.google.com>, Daniel Berger
says...
> So, either they're only defined in XP Pro and later or there's a
> bug in WMI (or just the WMI documentation).
> That, or Win32::OLE is broken somehow.
There are whole sections in MSDN that only exist on MSDN... :(
List the names of the properties that really exist:
---8<---
Set objClass = GetObject("winmgmts://./root/cimv2:Win32_Process")
WScript.Echo strClass & "Class Properties:"
WScript.Echo "------------------------------"
For Each objClassProperty In objClass.Properties_
WScript.Echo objClassProperty.Name
Next
---8<---
My apologies for the VBScript to all you poor readers of clpm, but I simply
don't know how to do this enumeration in Perl. :(
Petri
------------------------------
Date: Mon, 21 Jun 2004 12:07:50 -0400
From: "Joe Casadonte" <jcasadonte@northbound-train.com>
Subject: XML::Simple - memory leak?
Message-Id: <usmcohp2h.fsf@terrapin.northbound-train.com>
I've got a simple script, that consumes enormous amounts of memory:
while (<IN>) {
chomp;
next unless m{sampleResult};
my($xml) = eval { XMLin($_, %SIMPLE_OPTS); };
if ($@) {
warn qq(Malformed XML - $fname: $. - $@\n);
next;
}
$xml = undef;
}
close IN;
Underlying XML::Simple is XML::Sax::Expat, and of course it's possible
(probable?) that the problems lies somewhere below XML::Simple. It
happens with or without the eval, so that's not an issue.
===
This is perl, v5.8.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2002, Larry Wall
Binary build 804 provided by ActiveState Corp. http://www.ActiveState.com
Built 23:15:13 Dec 1 2002
===
perl -MXML::Simple -e "print $XML::Simple::VERSION"
1.06
(that's the latest version available via 'ppm' -- maybe that's my issue?)
===
Any help would be appreciated. Thanks!
--
Regards,
joe
Joe Casadonte
jcasadonte@northbound-train.com
------------------------------------------------------------------------------
Llama Fresh Farms => http://www.northbound-train.com
Gay Media Resource List => http://www.northbound-train.com/gaymedia.html
Perl for Win32 => http://www.northbound-train.com/perlwin32.html
Emacs Stuff => http://www.northbound-train.com/emacs.html
Music CD Trading => http://www.northbound-train.com/cdr.html
------------------------------------------------------------------------------
Live Free, that's the message!
------------------------------------------------------------------------------
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6713
***************************************