[19943] in Perl-Users-Digest
Perl-Users Digest, Issue: 2138 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 15 11:05:51 2001
Date: Thu, 15 Nov 2001 08:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005840310-v10-i2138@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 15 Nov 2001 Volume: 10 Number: 2138
Today's topics:
Re: (Solved) Need help with strange performance problem (Tim Moose)
Re: Accessing NT Network Neighbourhood <bart.lateur@skynet.be>
ANNOUNCE: Acme::EyeDrops 1.01 <andrew.savige@ir.com>
ANNOUNCE: XML::SAX (Matt Sergeant)
Re: Call a CGI from another CGI script (Richard)
Re: DBI changing from CSV to mySQL probs <cpryce@pryce.net>
Re: Declare Database Handle in Main or Module (Anno Siegel)
Re: distributing balanced elements across entities (RE (Anno Siegel)
Re: distributing balanced elements across entities (RE <bart.lateur@skynet.be>
get text from mysql db into form <harm.bouwman@mediasys.nl>
Re: get text from mysql db into form <mbudash@sonic.net>
Re: IBM AS/400 data queue access <jessica.bull@broadwing.com>
Re: Regular Expression Madness <peb@bms.umist.ac.uk>
Re: Regular Expression Madness <bart.lateur@skynet.be>
Re: shift operator / large numbers (Anno Siegel)
Re: shift operator / large numbers <bart.lateur@skynet.be>
Re: shift operator / large numbers <krahnj@acm.org>
Re: shift operator / large numbers (Anno Siegel)
Sorting of arrays by an element of each <mikecook@cigarpool.com>
Re: specific array items, loop iterator <pne-news-20011115@newton.digitalspace.net>
Re: specific array items, loop iterator <bernard.el-hagin@lido-tech.net>
Re: Tie and anonymous hashes (Anno Siegel)
Re: Tie and anonymous hashes <Tassilo.Parseval@post.rwth-aachen.de>
Re: Using TCP "keep alives" with IO::Socket news@roaima.freeserve.co.uk
Re: What do ecommerce authentication and ecommerce secu (Anno Siegel)
Re: What do ecommerce authentication and ecommerce secu <bernard.el-hagin@lido-tech.net>
Where can I find a binary Perl 5.005_53 for Win? <edgue@web.de>
XML::Xerces 1.5.2_0 (Jason E. Stewart)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Nov 2001 06:55:37 -0800
From: wtmoose@yahoo.com (Tim Moose)
Subject: Re: (Solved) Need help with strange performance problem processing large files
Message-Id: <48a86175.0111150655.75501494@posting.google.com>
I was finally able to solve this problem myself through
trial-and-error. I think others may find the solution useful or
perhaps interesting, so I will describe it here.
My script was taking 1.5 hours to go halfway through a 400MB file.
After making a one line change, it now goes through the full file in 5
minutes!
It was definitely a memory management issue. In my original post, I
had boiled the problem down to some a small number of common elements
and provided a sample program that exhibited the same (or similar)
performance problem. As far as I could tell, the common elements were
1. Process a large number of strings of varying length.
2. Modify the length of the strings.
3. Create and save numberous objects.
4. Assign modified strings to the objects.
After some research, I found two clues that led me to a solution.
a. All of the time was consumed by element (4). I found this by
profiling with -d:DProf. In my sample program, that was the line
$object->{V1} = $_;
b. The problem did not occur then the strings were of fixed length.
Based on (a) and (b), I had the idea of initializing the objects with
a fixed length string, as large or larger than "most" of the strings
to be processed. Magically it worked and my 400MB file was parsed in 5
minutes.
To try this in my sample program, make the following change.
# Just some object with several data members.
package Object;
sub new {
my $class = shift;
my $self = {
# Initializing to a fixed-length seems to work.
'V1' => '.' x 60,
'V2' => undef,
'V3' => undef, 'V4' => undef,
'V5' => undef, 'V6' => undef,
'V7' => undef, 'V8' => undef,
'V9' => undef, 'V10' => undef,
'V11' => undef, 'V12' => undef,
};
return bless $self, $class;
}
I have some ideas, but I would be very interested to hear a technical
explanation of why the memory management algorithms were getting
bogged down. Also, does anyone have an idea about the optimal string
length? Or a cleaner solution?
Later!
Tim
------------------------------
Date: Thu, 15 Nov 2001 12:40:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Accessing NT Network Neighbourhood
Message-Id: <grd7vt8q6id1437lrv96vdf0jaiunqnkot@4ax.com>
S Warhurst wrote:
>How can I access a network drive (NT), in this case - to create a file?
>
>I am trying:
>
> open(FILE, "\\\\servername\\directory\\file.txt")
>
>I can write to it from the machine the script is running on through Network
>Neighbourhood OK, indicating that the account has teh correct permissions on
>that directory, but the script itself falls over.
Getting back to your original question... Assuming you accidently forgot
the ">" in the open() call... Can you write to the file if you use the
normal DOS-ish "F:\..." syntax? Is it just these UNC names that fail?
Bacuse in the latter case it *would* be a Perl problem.
--
Bart.
------------------------------
Date: Wed, 14 Nov 2001 18:15:30 +1100
From: "Andrew" <andrew.savige@ir.com>
Subject: ANNOUNCE: Acme::EyeDrops 1.01
Message-Id: <tv7j2p7ub7tj5b@corp.supernews.com>
A new release of Acme::EyeDrops has recently been uploaded to CPAN.
To improve this module, I would like to add more shapes.
So if anyone out there with an artistic bent has a shape
(or an idea for a shape) they would like to contribute,
please let me know.
A shape is just a simple text file (which should be
displayed with a fixed width font).
An example shape is:
################ #########
################### #########
###### ######## ######
###### ####### ######
###### ####### ######
###### ####### ####### ######### #### ######
###### ####### ########### ######### ###### ######
###### ###### ###### ###### ####### ### ######
###### ###### ###### ###### ###### # ######
################ ###### ###### ###### ######
############# ################# ###### ######
######## ################# ###### ######
###### ###### ###### ######
###### ###### ###### ######
###### ###### ## ###### ######
###### ###### ### ###### ######
############# ############## ########## ##########
############# ######## ########## ##########
## ## ## #### ## ### #### ## ##### ## ## ####
# # # # # # # # # # # ## # # ## # # #
# # # # # ## # # # # # # #
# # # # # # # # # ####### # ####
# # # # # # # # # # # #
# # # # # # # # ## # # # # #
### ### ### #### ### ### #### # #### ### ####
#
# #
#####
EyeDrops allows you to pour a Perl program into a shape, for example:
''=~('('.'?'.'{' .('`'|'%'
).('['^'-').(('`')| '!').('`'
|','). '"'.('`' |'/').
("\["^ "\+").( ('`')|
'%').( '`'|'.' ).('{'
^'['). ("\^"^( '`'|'.' ))."\;".( '!'^ "\+").
'\\'.+ '$'.'/' .'='.("\["^ '.').('`' |'.'). ("\`"|
'$').( ('`')| '%').( ('`')| ('&')). ';' .('!'^
"\+"). '\\'.+ "\$".( ('[')^ "\#"). ( "\=").
'<'.('^'^(('`')| '.')). ('>'). "\;".( ('!')^
'+').('`'|'#' ).('`'|',').('`'| '/').( ('[')^
('(')).( '`'|'%').('{'^'[' ).('^' ^('`'|
'.')). "\;".( ('!')^ "\+").
'\\'.+ "\$".( ('[')^ "\#").
('='). "\~".( (( '['))^ '/').(
('[')^ "\)"). '/' ."\!". ('-').
'~'.'/'."\#". '/'.';'.("\!"^ '+').('['^ '+').('['^
')').('`'|')' ).("\`"| '.').('['^ '/').'\\'.
(( (( (( '$') )) ))) .''. +( "\["^ (( (( '#')
) ) ) ) . ( ( ( ( ( ( (( ( ( (( ( ( (
( ( ( ( ( (( ( ( ( ( ( ( (
( ( ( ( ( ( ( ( ( '!')))) ) ))))
) ) ) ) ) ) ) ) ) ) ) )
) ) ) ) ) ) ) ) )) ) ) ) ) )
)^+ '+' ).+ '"'. '}' .(( ')') ) );$: =(( '.')
)
^ (
'~');
When you run the above Perl program, it will output the original shape.
Cheers,
Andrew.
------------------------------
Date: 15 Nov 2001 02:38:07 -0800
From: msergeant@star.net.uk (Matt Sergeant)
Subject: ANNOUNCE: XML::SAX
Message-Id: <tv7j258amkfl4f@corp.supernews.com>
XML::SAX consists of several framework classes for using and building
Perl SAX2 XML parsers, filters, and drivers. It is designed around the
need to be able to "plug in" different SAX parsers to an application
without requiring programmer intervention. Those of you familiar with
the concepts behind DBI will be right at home. Some of the designs
come from the Java JAXP specification (SAX part), only without the
javaness.
XML::SAX also includes Kip Hampton's super-cool XML::SAX::Base, which
makes writing filters and drivers really easy. In fact, if you're
writing a SAX2 parser or driver, you should be using XML::SAX::Base
because otherwise it'll be really hard to make your parser fully
compliant and work right with XML::SAX.
Also included is a Pure Perl XML parser, XML::SAX::PurePerl, which
means that anyone using XML::SAX will always have a fallback parser to
use. This is an almost fully compliant XML parser, which supports
everything apart from conditional sections and parameter entities
(both of which are being worked on). It does not do validation at this
time, but it may be added in the future.
Available on CPAN now.
------------------------------
Date: 15 Nov 2001 03:38:57 -0800
From: google@richmore.com (Richard)
Subject: Re: Call a CGI from another CGI script
Message-Id: <81f7a6eb.0111150338.5634cabe@posting.google.com>
"Th.G" <th_gi@hotmail.com> wrote in message news:<3BF2F1F2.2040005@hotmail.com>...
> Hi
>
> How can I call a CGI-script from another CGI, give any parameters to
> that CGI and receive
> any results from the other CGI.
> Eg. 2 scripts 'main.cgi' and 'check.cgi'.
> 'main.cgi' calls 'check.cgi' and sends a parameter to check. 'check.cgi'
> gives back any
> result based on that parameter.
> Can I use this:
> in main.cgi:
> .
try the lwp modules, it won't do quite what you expect, but close enough.
Use perl's perldoc command to find more info about lwp.
perldoc lwpcook
perldoc LWP::Simple
------------------------------
Date: Thu, 15 Nov 2001 09:47:27 -0600
From: cpryce <cpryce@pryce.net>
Subject: Re: DBI changing from CSV to mySQL probs
Message-Id: <B8193FAF.2F97%cpryce@pryce.net>
in article APDI7.1520$xO6.234964@news.uswest.net, Michael Cook at
mikecook@cigarpool.com wrote on 11/14/01 6:16 PM:
> var=|| Content-type: text/html
> Software error:
> Can't call method "do" on an undefined value at addpipe.pl line 188.
>
> Can anyone point me in the right direction?
> Thx a million!!!
> Michael
>
> $db = 'pipes';
> $dbuser='user';
> $dbpasswd='password';
> $dbh = DBI->connect("DBI:mysql:$db:host.domain.com", $dbuser, $dbpasswd);
^^^^^
After the driver, MySQL takes a semi-colon separated lists of attributes.
So:
$dbh = DBI->connect("dbi:mysql:$db;host=host.domain.com", $dbuser,
$dbpasswd, {-RaiseError=>1, -AutoCommit=>1});
Obviously, host.domain.com must be a valid host. If the same machine runs
both the Web server and MySQL, you should specify host=localhost. Local host
is the default, however, I've seen connections fail if it is not explicitly
set, depending on how you have your GRANTS arranged in the mysql database.
>
> $STATEMENT = "
> INSERT INTO $db
> VALUES 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0
> ";
> print "<BR>var=|$dbh|\n";
> $dbh->do( $STATEMENT );
Unless your table is the same name as your Database, this statement will
still fail. INSERTs go into tables, not Databases. A better SQL statement
would be:
$STATEMNT = "INSERT INTO $table (column [,column, column ...] ) VALUES
('value' [,'value', 'value' ...] )";
Don't for get that you will have to properly quote the values. See the DBI
documentation for details on the quote method and bound parameters.
--
cp
------------------------------
Date: 15 Nov 2001 11:49:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Declare Database Handle in Main or Module
Message-Id: <9t0a3e$dv5$1@mamenchi.zrz.TU-Berlin.DE>
According to Joel Caughran <caughran@chem.uga.edu>:
> I have been writing a few scripts that interact with a very simple
> database. After some reading, I thought it would be a good idea to
> create the database handle in a module and export it so that it would be
> available to the scirpt. For example:
>
> package myDB;
>
> require Exporter;
> @ISA = qw(Exporter);
>
> @EXPORT = wq( $dbh );
^^
>
> use DBI;
>
> my $dbh = DBI->connect( "dbi:ODBC:Computer_Info" )
^^
> or die "Can't connect to 'Computer_Info':$DBI::errstr\n";
>
> Then in the main script I would have:
>
> #!perl
>
> use strict;
> use warnings;
>
> use myDB;
>
> $sth = $dbh->prepare( "SELECT * FROM table" )
> or die "Can't retrieve records:$DBI::errstr\n";
>
> The obvious advantage is that if I make some change to the database all
> I really need to change is the myDB.pm. What are the disadvantages to
> this plan?
It won't work. You didn't even try to run your code before submitting
it, did you?
You can't export a lexical variable, as you try to do with $dbh. It
must be a package variable. Also, you have "wq" where you want "qw".
Anno
------------------------------
Date: 15 Nov 2001 11:58:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: distributing balanced elements across entities (RE solution preferred)
Message-Id: <9t0al4$dv5$2@mamenchi.zrz.TU-Berlin.DE>
According to shòwdög <showdog@my-deja.com>:
> here's my dilemma
>
> I have a string such as (linebreaks for clarity, actually all on one
> line):
>
> =c1 =it foo
> =c2 bar
> =c3 baz =ro
> =c4 yadda yadda
> =c5 =it still more text =ro
>
> where the =it and =ro are the opening and closing elements. What I
> need in the result is (again, linebreaks for clarity):
>
> =c1 =it foo =ro
> =c2 =it bar =ro
> =c3 =it baz =ro
> =c4 yadda yadda
> =c5 =it still more text =ro
>
> any suggestions? I have _no_ idea how to do this -- I've tried
> negative look ahead assertions and such but no joy!
Regular expressions are notoriously weak at matching balanced elements.
*Regular* regular expressions (without backreferences) can't do it
at all. Using backreferences and other irregular means (like, perhaps,
embedded code blocks), you can come closer.
The module Text::Balanced tackles this problem explicitly. If your case
isn't particularly simple and restricted this may be your best bet.
Anno
------------------------------
Date: Thu, 15 Nov 2001 13:15:01 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: distributing balanced elements across entities (RE solution preferred)
Message-Id: <1gf7vtka57fc5imvunlvk7bn7hbe52k178@4ax.com>
shòwdög wrote:
>I have a string such as (linebreaks for clarity, actually all on one
>line):
>
>=c1 =it foo
>=c2 bar
>=c3 baz =ro
>=c4 yadda yadda
>=c5 =it still more text =ro
>
>where the =it and =ro are the opening and closing elements. What I
>need in the result is (again, linebreaks for clarity):
>
>=c1 =it foo =ro
>=c2 =it bar =ro
>=c3 =it baz =ro
>=c4 yadda yadda
>=c5 =it still more text =ro
>
>any suggestions?
It's a pity that those line breaks are there only for clarity. They sure
would help a lot. Perhaps the next can be a starting point? (Align
script to the left, especially the DATA section:)
while(<DATA>) {
if((my $open = /=it\b/) .. (my $close = /=ro\b/)) {
$open or s/(=c\d+) /$1 =it /;
$close or s/ ?$/ =ro/;
}
print;
}
__DATA__
=c1 =it foo
=c2 bar
=c3 baz =ro
=c4 yadda yadda
=c5 =it still more text =ro
This prints:
=c1 =it foo =ro
=c2 =it bar =ro
=c3 =it baz =ro
=c4 yadda yadda
=c5 =it still more text =ro
All I can say is: yeay!
Instead of using <DATA>, you can try a split() on /(?==c\d)/.
foreach(split /(?==c\d)/) {
...
}
--
Bart.
------------------------------
Date: Thu, 15 Nov 2001 15:11:35 +0100
From: <harm.bouwman@mediasys.nl>
Subject: get text from mysql db into form
Message-Id: <9t0if2$gba$1@news1.xs4all.nl>
Hello,
I try to create an cgi script to edit text out of a mysql table. Like below
where default\"@field[1]\" value the text will be inserted into the form,
but it will not show on screen. I have to view the source withing my
explorer browser to see the text.
Does anyone now how to display the text.
Regards,
Harm
harm.bouwman@mediasys.nl
my $dbh = DBI->connect("DBI:mysql:${db}", "${user}", "${password}",(
{'RaiseError' => 1}));
my $sth = $dbh->prepare("${Editsql}");
$sth->execute();
while (my @field = $sth->fetchrow_array()) {
print" <tr>\n";
print" <td valign=\"top\" height=\"8\" width=\"50\">\n";
print" <input type=\"text\" name=\"head\" default=\"@field[1]\"
maxlength=\"50\" size=\"50\">\n";
print" </td>\n";
print" </tr>\n";
------------------------------
Date: Thu, 15 Nov 2001 15:31:36 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: get text from mysql db into form
Message-Id: <mbudash-BA4CD4.07313715112001@news.sonic.net>
In article <9t0if2$gba$1@news1.xs4all.nl>, <harm.bouwman@mediasys.nl>
wrote:
> Hello,
>
> I try to create an cgi script to edit text out of a mysql table. Like
> below
> where default\"@field[1]\" value the text will be inserted into the form,
> but it will not show on screen. I have to view the source withing my
> explorer browser to see the text.
>
> Does anyone now how to display the text.
>
> Regards,
>
[snip]
> print" <input type=\"text\" name=\"head\" default=\"@field[1]\"
> maxlength=\"50\" size=\"50\">\n";
here's your problem: the 'default' attribute should be a value
attribute, and for gosh sake use another quote type so you don't have to
escape all the doulbe-quotes!:
print qq{ <input type="text" name="head" value="@field[1]"
maxlength="50" size="50">\n};
hope this helps,
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Thu, 15 Nov 2001 15:52:47 GMT
From: "Jessica Bull" <jessica.bull@broadwing.com>
Subject: Re: IBM AS/400 data queue access
Message-Id: <ixRI7.65326$XR.4838771@bin3.nnrp.aus1.giganews.com>
Ok...i know what they are. At one time, long ago i had done something
similar, but like you said, it was with VB using ODBC. I would think perl
has some use of ODBC connections if that is the way you would want to go.
Try this: DBD::ODBC -- DBD module interfacing the ODBC databases. or
iodbc_ext_0_1. you can search cpan for either of these. sorry i couldn't
be of more help.
"David Fosdike" <dfosdike@nospam.elders.com.au> wrote in message
news:VSEI7.18$Ns2.1178@nsw.nnrp.telstra.net...
> A useful starting point for understanding AS/400 Data queues is
> http://www.iseriesnetwork.com/Resources/ClubTech/TNT400/bo400ng/as400dat
> aqs.htm
>
> I basically need to communicate between different platforms and the
> AS/400 for procedural control and Perl access via data queues would
> provide a standard way of doing it. At present I know of three
> different sources of API's (MS Host Integration Server, IBM Client
> Access and a third party on which I cannot remeber at present) which
> allow such access but they need to be coded in VBscript or C++ or the
> like. Also there is nothing for Linux etc. AFAIK.
>
> Thanx for your interest,
>
> David
> Jessica Bull wrote in message ...
> >There are several ways to access data with in the AS/400. I don't know
> what
> >you mean by data queues though. Can you elaborate?
> >
> >"David Fosdike" <dfosdike@nospam.elders.com.au> wrote in message
> >news:m5nI7.32$5c2.1560@nsw.nnrp.telstra.net...
> >> Anyone know of any scripts or modules to access AS/400 data queues
> from
> >> either MS, Unix or Linux platform?
> >>
> >> Thanx in advance,
> >>
> >> David Fosdike
> >> dfosdike@nospam.elders.com.au
> >>
> >>
> >>
> >
> >
>
>
>
------------------------------
Date: Thu, 15 Nov 2001 11:15:09 +0000
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Regular Expression Madness
Message-Id: <3BF3A3BD.E8CFDD76@bms.umist.ac.uk>
Tyler Cruz wrote:
>
> I'm a Perl newbie so I'm not sure about this, but other than switching to
> =~, doesn't the RegEx parameters have to be in parethethis?:
>
> $text =~ s/<%(.*?)%>//sg;
Only if you want to store them for some reason.
Otherwise $text =~ s/<%.*?%>//sg; will work just fine (with all the
usual limitations/pitfalls on trying to use simple regexes to deal with
HTML style tags...).
Paul
------------------------------
Date: Thu, 15 Nov 2001 12:37:58 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regular Expression Madness
Message-Id: <ufd7vtcdgebbqafi0fgp2d08t6fgprm5bf@4ax.com>
Bernard El-Hagin wrote:
>But again, I have to warn you that you can't parse HTML with a regex.
>Unless you're really sure of your input HTML you should be using
>a parser. Don't say you weren't warned when you get burned.
You'll get burned if you'll try parsing "<%...%>"-like tags with
HTML::Parser. It doesn't like it. Actually, it treats it like text
(splitting for calls between the "<" and the "%").
--
Bart.
------------------------------
Date: 15 Nov 2001 11:16:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: shift operator / large numbers
Message-Id: <9t0876$b6l$1@mamenchi.zrz.TU-Berlin.DE>
According to John W. Krahn <krahnj@acm.org>:
> Jens Luedicke wrote:
> >
> > I messed around with perl's shift operators and I would like to know why
> > those onliners have the same results:
> >
> > jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16'
> > 2147483648
> >
> > jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16 << 32'
> > 2147483648
>
> Because on your platform integers are 32 bits wide so '<< 32' is a noop.
The 'so' in your reply makes it sound as if this were a logical
consequence.
While it is true that compilers and hardware tend to treat x << n as
x << ( n mod Wordsize), this is a rather arbitrary convention, and
not a good one IMHO. It would be more consistent to let (logical)
shifts of more than the word size return zero.
Anno
------------------------------
Date: Thu, 15 Nov 2001 12:45:50 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: shift operator / large numbers
Message-Id: <j0e7vt02eii2v44vpfp6o21pbbkhi31prm@4ax.com>
Jens Luedicke wrote:
>I messed around with perl's shift operators and I would like to know why
>those onliners have the same results:
>
>jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16'
>2147483648
>
>jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16 << 32'
>2147483648
I don't really know. I do know that for shifts, "<<" and ">>" (plus "&"
and "|" and "^", and even "%") to work correctly, the number must fit
into an integer. It depends on your platform what that means, but
commonly than means at most 32 bits, 64 if you're very lucky. Here, that
condition isn't met.
Oh, a possibility is that for shift, the argument on the right is
treated modulo 32 (or 64).
print 123 << 33;
-->
246
Yup. That is the case on my platform.
--
Bart.
------------------------------
Date: Thu, 15 Nov 2001 13:19:17 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: shift operator / large numbers
Message-Id: <3BF3C191.CF525B7@acm.org>
Anno Siegel wrote:
>
> According to John W. Krahn <krahnj@acm.org>:
> > Jens Luedicke wrote:
> > >
> > > I messed around with perl's shift operators and I would like to know why
> > > those onliners have the same results:
> > >
> > > jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16'
> > > 2147483648
> > >
> > > jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16 << 32'
> > > 2147483648
> >
> > Because on your platform integers are 32 bits wide so '<< 32' is a noop.
>
> The 'so' in your reply makes it sound as if this were a logical
> consequence.
>
> While it is true that compilers and hardware tend to treat x << n as
> x << ( n mod Wordsize), this is a rather arbitrary convention, and
It appears that only Perl does this.
> not a good one IMHO. It would be more consistent to let (logical)
> shifts of more than the word size return zero.
This is what C and IIRC i86 assembler do.
$ perl -le'print 2 << 4; print 2 << 4 << 32; print 2 << 4 << 34'
32
32
128
$ cat tryshift.c
#include <stdio.h>
#include <stdlib.h>
int main ( void ) {
printf( "sizeof int = %d\n", sizeof( int ) );
printf( "2 << 4 = %d\n", 2 << 4 );
printf( "2 << 4 << 32 = %d\n", 2 << 4 << 32 );
printf( "2 << 4 << 34 = %d\n", 2 << 4 << 34 );
return EXIT_SUCCESS;
}
$ ./tryshift
sizeof int = 4
2 << 4 = 32
2 << 4 << 32 = 0
2 << 4 << 34 = 0
John
--
use Perl;
program
fulfillment
------------------------------
Date: 15 Nov 2001 13:51:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: shift operator / large numbers
Message-Id: <9t0h9h$l0e$1@mamenchi.zrz.TU-Berlin.DE>
According to John W. Krahn <krahnj@acm.org>:
> Anno Siegel wrote:
> >
> > According to John W. Krahn <krahnj@acm.org>:
> > > Jens Luedicke wrote:
> > > >
> > > > I messed around with perl's shift operators and I would like to know why
> > > > those onliners have the same results:
> > > >
> > > > jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16'
> > > > 2147483648
> > > >
> > > > jens@cello:~$ perl -le 'print 2 << 2 << 4 << 8 << 16 << 32'
> > > > 2147483648
> > >
> > > Because on your platform integers are 32 bits wide so '<< 32' is a noop.
> >
> > The 'so' in your reply makes it sound as if this were a logical
> > consequence.
> >
> > While it is true that compilers and hardware tend to treat x << n as
> > x << ( n mod Wordsize), this is a rather arbitrary convention, and
>
> It appears that only Perl does this.
>
> > not a good one IMHO. It would be more consistent to let (logical)
> > shifts of more than the word size return zero.
>
> This is what C and IIRC i86 assembler do.
Indeed. I was under the impression Perl inherited the behavior from
its ancestry, but wherever I ran your little test program (now snipped)
I saw the same results you showed.
Anno
------------------------------
Date: Thu, 15 Nov 2001 08:33:27 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: Sorting of arrays by an element of each
Message-Id: <ffRI7.44$2M4.62462@news.uswest.net>
Hi folks,
I am having a difficult time with this sort. I have a group of arrays
like:
@1001 = (field1, field2, 1001, field3)
@1002 = (field4, field5, 1002, field6)
@1003 = (field6, field7, 1003, field8)
It is possible that there may be more than 1 identical array, so I used
this to remove duplicates:
@CHOSENNUMS = sort keys %{ { map {$_ => 1} @CHOSENNUMS} };
I now have the set of unique arrays, but I don't want to display them in
the order of the array names, I am trying to sort them by the second element
in the array. Any ideas? I am stumped (I think maybe a hash, but can't
figure how to get the output).
Thanks!!!
Michael
--
== CigarPool ==
http://www.cigarpool.com
------------------------------
Date: Thu, 15 Nov 2001 15:18:58 +0100
From: Philip Newton <pne-news-20011115@newton.digitalspace.net>
Subject: Re: specific array items, loop iterator
Message-Id: <62j7vtgm8e1o6pmc4iuk0r4vmfp4tsm7ed@4ax.com>
On Thu, 15 Nov 2001 09:13:38 +0000 (UTC), Bernard El-Hagin
<bernard.el-hagin@lido-tech.net> wrote:
> On Thu, 15 Nov 2001 09:06:23 GMT, Sean Hamilton <sh@planetquake.com> wrote:
> > 1. Is there a good way to extract only certain items from an array? For
> > example, if I only want the inode of a file, I can use something like
> >
> > my $inode = (stat ($file))[1];
> >
> > However, what if I want the first and ninth item? Must I create a bunch of
> > dummy variables?
>
> (stat($file))[1,9];
That gives you the second and tenth item.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 15 Nov 2001 14:20:51 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: specific array items, loop iterator
Message-Id: <slrn9v7mqj.3il.bernard.el-hagin@gdndev25.lido-tech>
On Thu, 15 Nov 2001 15:18:58 +0100, Philip Newton
<pne-news-20011115@newton.digitalspace.net> wrote:
> On Thu, 15 Nov 2001 09:13:38 +0000 (UTC), Bernard El-Hagin
><bernard.el-hagin@lido-tech.net> wrote:
>
>> On Thu, 15 Nov 2001 09:06:23 GMT, Sean Hamilton <sh@planetquake.com> wrote:
>> > 1. Is there a good way to extract only certain items from an array? For
>> > example, if I only want the inode of a file, I can use something like
>> >
>> > my $inode = (stat ($file))[1];
>> >
>> > However, what if I want the first and ninth item? Must I create a bunch of
>> > dummy variables?
>>
>> (stat($file))[1,9];
>
> That gives you the second and tenth item.
$[ = 1;
Cheers,
Bernard
------------------------------
Date: 15 Nov 2001 12:38:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Tie and anonymous hashes
Message-Id: <9t0cvf$dv5$3@mamenchi.zrz.TU-Berlin.DE>
According to Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de>:
> [
> Please put your comments below the part you are quoting,
> not on top. Trim it suitably. Don't quote signatures. Be a
> good boy. ;-)
> ]
>
> On Wed, 14 Nov 2001 17:48:13 GMT, Mark Riehl wrote:
> > Tassilo - I understand that I can use Tie to retrieve in insertion order.
> > The question is - can you use Tie on an anonymous hash? If so, how do you
> > do it?
> >
> > In the example that I posted, there aren't any hashes declared, so I can't
> > use Tie as it is normally used.
>
> Ah, now I understand your question.
> No, I don't think you can. That will certainly make it unpleasant to add
> many tied hashes into an array.
> If order _really_ matters for you, then you would need a temporary hash:
>
> while (<HANDLE>) {
> # do some splitting etc
> # now tie a hash
> my %hash;
> tie %hash, Tie::IxHash;
^^^^^^^^^^^
You need to quote that, tie doesn't take barewords.
>
> # fill it
> $hash{key} = "value"...;
> push @array, \%hash;
> }
You don't have to name the hash if you don't want to. On way is
while ( <HANDLE> ) {
tie %{ $array[ @array]}, 'Tie::IxHash'; # vivat autovivification
# fill it
$array[ $#array]->{ key} = "value";
}
Anno
[...]
------------------------------
Date: Thu, 15 Nov 2001 14:33:46 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Tie and anonymous hashes
Message-Id: <9t0g7q$avh$06$1@news.t-online.com>
On 15 Nov 2001 12:38:07 GMT, Anno Siegel wrote:
> According to Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de>:
>> while (<HANDLE>) {
>> # do some splitting etc
>> # now tie a hash
>> my %hash;
>> tie %hash, Tie::IxHash;
> ^^^^^^^^^^^
> You need to quote that, tie doesn't take barewords.
Oh, it does as long as you turn strictures off. ;-)
As a matter of fact, you are right, they must be quoted. I more or less
copied (not by character) the snippets from the Tie::IxHash manpage
which does not use quotes. Since I hardly use strict in one-liners I
wouldn't get any complaints from Perl.
>> # fill it
>> $hash{key} = "value"...;
>> push @array, \%hash;
>> }
>
> You don't have to name the hash if you don't want to. On way is
>
> while ( <HANDLE> ) {
> tie %{ $array[ @array]}, 'Tie::IxHash'; # vivat autovivification
But here the hash is associated with an array-element holding a reference to
it. That means an anonymous hash needs to be stored away somewhere
before it can be tied.
This is not possible:
my $r = tie { key => 'value', key2 => 'value2' }, 'Tie::IxHash';
Of course, you already knew that. But the original topic was whether one can
tie an anonymous hash.
Tassilo
--
You'll never see all the places, or read all the books, but fortunately,
they're not all recommended.
------------------------------
Date: 15 Nov 2001 11:33:50 GMT
From: news@roaima.freeserve.co.uk
Subject: Re: Using TCP "keep alives" with IO::Socket
Message-Id: <3bf3a81d@news.netserv.net>
4875.3bf2a342.1804289383 <4875.3bf2a342.1804289383@temp> wrote:
> I just need a way to test it. I guess I need a sniffer of
> some sort to look at the TCP activity on my Solaris box to
> make sure the "keep alive" packets are actually being sent.
> If you have any suggestions for a good packet sniffer, let
> me know. I'll post a follow-up if I get this thing working.
Try etherreal or tcpdump, both available from www.sunfreeware.com.
Chris
------------------------------
Date: 15 Nov 2001 12:59:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: What do ecommerce authentication and ecommerce security mean?
Message-Id: <9t0e87$dv5$4@mamenchi.zrz.TU-Berlin.DE>
According to Big Banana <bigbanana@mailandnews.com>:
> Can someone tell me what ecommerce authentication and ecommerce security
> mean?
> What technologies are we talking about?
> I kinda know the answer... but just want a more concrete one.
Why are you asking this in a Perl newsgroup?
Anno
------------------------------
Date: Thu, 15 Nov 2001 13:06:03 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: What do ecommerce authentication and ecommerce security mean?
Message-Id: <slrn9v7iec.3il.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 14 Nov 2001 14:41:10 -0000, Big Banana <bigbanana@mailandnews.com>
wrote:
> Can someone tell me what ecommerce authentication and ecommerce security
> mean?
Yes.
> What technologies are we talking about?
We're talking about ecommerce authentication and ecommerce security.
> I kinda know the answer... but just want a more concrete one.
>
> Thanks.
You're welcome.
Cheers,
Bernard
------------------------------
Date: Thu, 15 Nov 2001 15:12:48 +0100
From: Edwin =?iso-8859-1?Q?G=FCnthner?= <edgue@web.de>
Subject: Where can I find a binary Perl 5.005_53 for Win?
Message-Id: <3BF3CD60.C712CF6E@web.de>
Hi there,
I am developping some perl code for OS/2. The latest perl for
OS/2 that is available as binary is 5.005_53.
But I prefer to work on W2K - but of course, when you are
developping your code with Perl 5.6.1 and you carry it
to 5.005_53 you might be surprised from time to time ....
Thus I would like to install the same "old" perl on my windows
box - and therefore I am wondering where I can find a 5.005_53
binary for Windows (or a version that comes "as close as possible").
I had a look at the CPAN list of sites (where to find
windows binaries) - but none of them offered what I am looking
for.
Any other idea?
------------------------------
Date: 12 Nov 2001 11:06:43 -0700
From: jason@openinformatics.com (Jason E. Stewart)
Subject: XML::Xerces 1.5.2_0
Message-Id: <tv7j34bkbu8p64@corp.supernews.com>
==============================================================================
Release of version 1.5.2_0 of XML::Xerces
==============================================================================
NAME
XML::Xerces - Perl Interface to the Apache Xerces XML Parser
DESCRIPTION
Because it is based on the Xerces-C parser, Xerces.pm provides a
validating XML parser written in a portable subset of C++. Xerces-C
makes it easy to give your application the ability to read and
write XML data. A shared library is provided for parsing,
generating, manipulating, and validating XML documents. Xerces-C is
faithful to the XML 1.0 recommendation and associated standards (
DOM 1.0, DOM 2.0. SAX 1.0, SAX 2.0, Namespaces, and partial support
for W3C XML Schema). The parser provides high performance,
modularity, and scalability. It also provides full support for
Unicode.
AUTHORS
Jason Stewart: Xerces 1.4 and 1.5 ports
Harmon Nine: Xerces 1.3 DOM port
Fredrick Paul Eisele: Xerces 1.3 DOM port
Tom Watson: Xerces 1.1 DOM port
COPYRIGHT
Copyright (c) 2001, Apache Software Foundation. All Rights
Reserved. This code is distributed under the terms of the Apache
Software License, Version 1.1. See the file LICENSE for details
==============================================================================
REQUIREMENTS
* Perl 5.6.0 or greater
* Xerces-C 1.5.2: available from:
http://xml.apache.org/dist/xerces-c/stable/
==============================================================================
CHANGES IN VERSION 1.5.2_0
- Version numbering change, to reflect that this is the first
release of XML::Xerces to require Xerces-C-1.5.2
- Unicode now works! I modified all I/O between Perl and
Xerces-C to use transcoders to properly convert between
Perl's internal UTF-8 format and Xerces-C's internal UTF-16
format.
- IDOM operators (== and !=) now work
- I?DOM_Attr::setAttribute() will now accept integer and
floating point values as well as strings, so you no longer
need to wrap them in strings.
- New sample application: IDOMPrint.pl
- All overloaded methods (except DOM API) are now supported.
==============================================================================
AVAILABILITY
XML::Xerces is available from:
http://xml.apache.org/dist/xerces-p/stable/
==============================================================================
------------------------------
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 2138
***************************************