[26629] in Perl-Users-Digest
Perl-Users Digest, Issue: 8738 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 6 18:05:17 2005
Date: Tue, 6 Dec 2005 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, 6 Dec 2005 Volume: 10 Number: 8738
Today's topics:
javascript to perl converter? <no-spam@new.rr.com>
Re: javascript to perl converter? <no@email.com>
Re: javascript to perl converter? <emschwar@pobox.com>
Re: Slow insertion to hashes? <jindroush.nospam@seznam.cz>
Why array always printed as pointer? <speediercoREMOVE_THIS@yahoo.com>
Re: Why array always printed as pointer? <speediercoREMOVE_THIS@yahoo.com>
Re: Why array always printed as pointer? <mothra@nowhereatall.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 06 Dec 2005 22:05:53 GMT
From: "P. Thompson" <no-spam@new.rr.com>
Subject: javascript to perl converter?
Message-Id: <Pine.LNX.4.63.0512061603490.14339@localhost.localdomain>
Does anyone know of a utility to convert javascript to perl?
I would like a perl script which can convert formulas such as this
function dF(s){var s1=unescape(s.substr(0,s.length-1)); var
t='';for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1))
but for whatever reason I am having trouble getting my mind around what to
do to convert it. I would think such a utility would be feasible; I just
don't know if one exists and google provides much static.
------------------------------
Date: Tue, 06 Dec 2005 22:30:39 +0000
From: Brian Wakem <no@email.com>
Subject: Re: javascript to perl converter?
Message-Id: <3vmhofF16hs4aU1@individual.net>
P. Thompson wrote:
> Does anyone know of a utility to convert javascript to perl?
I doubt such a thing exists, or works properly if it does.
> I would like a perl script which can convert formulas such as this
>
> function dF(s){var s1=unescape(s.substr(0,s.length-1)); var
>
t='';for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1))
I don't know much JS. What does that do?
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Tue, 06 Dec 2005 15:35:59 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: javascript to perl converter?
Message-Id: <etofyp5voog.fsf@wilson.emschwar>
"P. Thompson" <no-spam@new.rr.com> writes:
> Does anyone know of a utility to convert javascript to perl?
Nope. It's barely possible that you might find a tool that would
convert small subsets of javascript to perl, but they're two very
different languages-- their approaches to objects alone are wildly
different. In any event, such code would almost certainly look like
terrible Perl, based on my experience of similar tools, and would
probably be a poor one to learn from.
> I would like a perl script which can convert formulas such as this
>
> function dF(s){var s1=unescape(s.substr(0,s.length-1)); var
> t='';for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1))
>
> but for whatever reason I am having trouble getting my mind around what to
> do to convert it.
No wonder. It's poorly-written.
use URI::Escape; Here's my best stab-- note that Perl, as a rule,
doesn't make character-by-character iteration over a string as easy as
iterating over a list, so I convert the string into a list of
characters, and iterate over that instead. Note also that $t is not
returned, but then your snippet above isn't even syntactically correct
(you don't have a close brace for the function), so I leave that as an
exercise for the reader. I've also renamed several variables, when I
could tell what they were doing, and introduced one or two as
appropriate.
# what does dF mean?
sub dF
{
my $escaped = shift;
my $string = uri_unescape($escaped);
my $lastChar = ord( substr($string, -1, 1) );
my $t;
for my $char (split //, $string) {
$t .= chr( ord($char) - $lastChar );
}
}
Except perhaps as someone's very silly idea of "encryption", I can't
figure out what this is supposed to do.
> I would think such a utility would be feasible; I just don't know
> if one exists and google provides much static.
I seriously doubt such a utility would be feasible, and if one exists,
I would advise giving it a wide berth; the odds that it's correct and
good are very slim.
-=Eric
------------------------------
Date: Tue, 06 Dec 2005 21:18:24 +0100
From: Jindroush <jindroush.nospam@seznam.cz>
Subject: Re: Slow insertion to hashes?
Message-Id: <dn4rmk$bel$1@news.vol.cz>
Jindroush wrote:
> Hi,
>
> I have to load a file. I 'index' the records in two hashes. At the
> beginning I do:
> This works good up to cca 70000 records (file1
> has about 91000 records, each record is about 85 chars, split in 6
> strings). Then it is _DEAD SLOW_. I load three such files in 3 (6)
> different hashes. The two other files are also _DEAD SLOW_. I have quite
> fast computer and s**tloads of free ram. Running: v5.6.1 built for
> MSWin32-x86-multi-thread (activestate) on WXP (no way to change the perl
> version/os).
>
> Why is it so slow? How can I make it faster?
According to the messages, I'm posting more 'proper' problem report.
The code is below. Input file is about 91k records, 8.8MBs. I have 1GB
of ram, the script takes under 50megs while running. So no swapping
(100%). I tried to comment various parts of the script and it seems that
the whole problem is the size of each %H. The shorter it is, the faster
the script works. How to solve that (easily?).
use strict;
my %DB;
my $in = "file1";
my $fl = -s $in;
my $recs = int( $fl / 85 );
keys( %DB ) = $recs;
open IN, $in or die;
print "Loading '$in'...\n";
print( "preallocated $recs records...\n" );
my $cnt = 0;
my $st = time;
while( my $line = <IN> )
{
chomp $line;
my( $v1, $v2, $v3, $v4, $v5, $fname )= split( / /, $line);
my %H;
$H{ v1 } = $v1;
$H{ v2 } = $v2;
$H{ v3 } = $v3;
$H{ v4 } = $v4;
$H{ v5 } = $v5;
$H{ fname } = $fname; #must be here
$DB{ lc $fname } = \%H;
printf( "%4d $cnt\n", time - $st ) unless ( $cnt % 1000 );
$cnt++;
}
close IN;
print "\n";
------------------------------
Date: Tue, 6 Dec 2005 14:28:54 -0500
From: "OttawaTrade" <speediercoREMOVE_THIS@yahoo.com>
Subject: Why array always printed as pointer?
Message-Id: <LM2dnXO8pejhewjenZ2dnUVZ_vydnZ2d@rogers.com>
article ( [ MSGID|MSGNUM ], [FH] )
Retrieve the header, a blank line, then the body (text) of the specified
article.
If FH is specified then it is expected to be a valid filehandle and the
result will be printed to it, on sucess a true value will be returned. If FH
is not specified then the return value, on sucess, will be a reference to an
array containg the article requested, each entry in the array will contain
one line of the article.
If no arguments are passed then the current article in the currently
selected newsgroup is fetched.
MSGNUM is a numeric id of an article in the current newsgroup, and will
change the current article pointer. MSGID is the message id of an article as
shown in that article's header. It is anticipated that the client will
obtain the MSGID from a list provided by the newnews command, from
references contained within another article, or from the message-id provided
in the response to some other commands.
If there is an error then undef will be returned.
I did this
print $nntp-> article ('<FIqdndE94PcxiwjeRVn-sw@rogers.com>');
output:
ARRAY(0x1d3ffac)
I want to print and do regex on the output. Is there a to_string, _print
option on an array?
I think pring $array will work, but not in my case. I can not find why.
------------------------------
Date: Tue, 6 Dec 2005 14:36:30 -0500
From: "OttawaTrade" <speediercoREMOVE_THIS@yahoo.com>
Subject: Re: Why array always printed as pointer?
Message-Id: <1eSdnYCg9u_bdQjenZ2dnUVZ_t-dnZ2d@rogers.com>
I guess it is a deref issue.
I did two things. 1 works, 2 does not
1 $lines= $nntp-> article ('<FIqdndE94PcxiwjeRVn-sw@rogers.com>');
print @$lines;
2 print @($nntp-> article ('<FIqdndE94PcxiwjeRVn-sw@rogers.com>'));
Is there a way to get rid of the middleman $lines?
------------------------------
Date: Tue, 6 Dec 2005 13:40:00 -0800
From: "mothra" <mothra@nowhereatall.com>
Subject: Re: Why array always printed as pointer?
Message-Id: <11pc19knavep6b3@corp.supernews.com>
OttawaTrade wrote:
> I guess it is a deref issue.
> I did two things. 1 works, 2 does not
>
> 1 $lines= $nntp-> article ('<FIqdndE94PcxiwjeRVn-sw@rogers.com>');
> print @$lines;
>
> 2 print @($nntp-> article ('<FIqdndE94PcxiwjeRVn-sw@rogers.com>'));
>
>
> Is there a way to get rid of the middleman $lines?
print @{$nntp-> article ('<FIqdndE94PcxiwjeRVn-sw@rogers.com>')};
Hope this helps
Mothra
------------------------------
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 8738
***************************************