[17970] in Perl-Users-Digest
Perl-Users Digest, Issue: 130 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 24 00:10:32 2001
Date: Tue, 23 Jan 2001 21:10:14 -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: <980313013-v10-i130@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 23 Jan 2001 Volume: 10 Number: 130
Today's topics:
Globals & strict <spewmuffin@my-deja.com>
Re: Globals & strict <joe+usenet@sunstarsys.com>
Re: Globals & strict egwong@netcom.com
Re: Globals & strict (Tad McClellan)
Re: hash table (Eric Bohlman)
Re: hash table (Damian James)
Re: hash table (Richard J. Rauenzahn)
I N D I G O Perl - A Quick Opinion <anonymous@anonymous.anonymous>
Re: I N D I G O Perl - A Quick Opinion <jbuff1856@my-deja.com>
Re: I N D I G O Perl - A Quick Opinion <anonymous@anonymous.anonymous>
Re: java stream (Charles DeRykus)
Re: Performing ops on matched strings <xxxtmanningxxx@canada.com>
Re: Performing ops on matched strings <xxxtmanningxxx@canada.com>
Re: Perl Crashes on my Win2k Box <someguyREMOVE@REMOVEsunflower.com>
Please help how to use Open3 tuoihong@my-deja.com
Re: Please help how to use Open3 (Garry Williams)
Porting from VB to perl <frawg@BLAH.sdf.lonestar.org>
Re: Porting from VB to perl <chrisw@dynamite.com.au>
Re: printing to a printer? <jhelman@wsb.com>
Re: Quick Newbie Qeustion please... <ofirb@jdc.org.il>
Re: s/// inconsistency <roman@topologix.de>
Re: s/// inconsistency <roman@topologix.de>
Thanks Joe & Eric <ofirb@jdc.org.il>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 23 Jan 2001 23:22:11 GMT
From: SpewMuffin <spewmuffin@my-deja.com>
Subject: Globals & strict
Message-Id: <94l3mq$pjj$1@nnrp1.deja.com>
Is there a way to declare global variables while under strict mode?
I like the error checking features of 'use strict;' but it doesn't like
global variables declared outside of functions.
Since these are all around constants that is used in many places, I
rather have a collection of constants rather than passing them in as
variables and then have to separate them out from arrays that are also
passed in.
Thanks for any and all info!
--
SpewMuffin; E-mail: spewmuffin@juno.com
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 23 Jan 2001 19:06:45 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Globals & strict
Message-Id: <m3lms1rey2.fsf@mumonkan.sunstarsys.com>
SpewMuffin <spewmuffin@my-deja.com> writes:
> Is there a way to declare global variables while under strict mode?
> I like the error checking features of 'use strict;' but it doesn't like
> global variables declared outside of functions.
Either package-qualified (everywhere):
package My;
use strict;
%My::hash; #package-global, only used as %My::hash, not %hash
or use vars:
package My;
use strict;
use vars qw(%hash); # ignore strictures on %hash
Note that you might not want/need package globals, but rather
file-scoped lexicals instead:
# package My; # lexicals are not related to packages
use strict;
my %hash; # every sub in this file can use %hash (but noone else)
> Since these are all around constants that is used in many places, I
> rather have a collection of constants rather than passing them in as
> variables and then have to separate them out from arrays that are also
> passed in.
I don't know what your original problem is,
but I suggest to use a hash.
-Rafael Garcia-Suarez
--
Joe Schaefer
------------------------------
Date: Wed, 24 Jan 2001 01:21:39 GMT
From: egwong@netcom.com
Subject: Re: Globals & strict
Message-Id: <D6qb6.17354$J%.1316788@news.flash.net>
Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> SpewMuffin <spewmuffin@my-deja.com> writes:
>> Is there a way to declare global variables while under strict mode?
>> I like the error checking features of 'use strict;' but it doesn't like
>> global variables declared outside of functions.
Aside from what Joe's already said, if you're using perl 5.6, you can
(should?) use 'our' to declare a global variable with lexical scope.
------------------------------
Date: Wed, 24 Jan 2001 03:37:16 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Globals & strict
Message-Id: <slrn96s9qh.1po.tadmc@tadmc26.august.net>
egwong@netcom.com <egwong@netcom.com> wrote:
>Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
>> SpewMuffin <spewmuffin@my-deja.com> writes:
>>> Is there a way to declare global variables while under strict mode?
Yes. There is also a way to have global variables *without*
any declaration under strict mode.
That was Joe's first example.
>>> I like the error checking features of 'use strict;' but it doesn't like
>>> global variables declared outside of functions.
>
>Aside from what Joe's already said,
I'd like to add that Joe's third one was the best one.
Always try lexical variables first, only use dynamic variables
when you really really need to.
>if you're using perl 5.6, you can
>(should?) use 'our' to declare a global variable with lexical scope.
See also, MJD's "Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
recently updated for 5.6 :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 23 Jan 2001 23:58:50 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: hash table
Message-Id: <94l5rq$11e$4@bob.news.rcn.net>
boussard <boussard@my-deja.com> wrote:
> Sure, I have 4 files with a few variables and ~10,000 values in each
> file.
> for example:
> file 1:
> diseaseID patientid
> file 2:
> diseaseID diseaseName
> file 3:
> diseaseName medicine
> I would like to create a new file with
> patientID, diseaseName, medicine
What you're talking about is called a "relational join" (as you might
guess, a lot of the code in a relational database manager is devoted to
doing this efficiently).
It seems to me that you want to read file 2, building a hash keyed on
diseaseID and with values of diseaseName, read file 3, building a hash
keyed on diseaseName with values of medicine, and then read through file 1
sequentially, splitting each entry into patientID and diseaseID, use the
first hash to look up diseaseName from diseaseID, the second hash to look
up medicine from diseaseName, and then write the three things out.
If you're going to be doing this a lot and file 2 or file 3 are large,
consider building tied DBM hash files for them to speed things up.
------------------------------
Date: 24 Jan 2001 00:18:02 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: hash table
Message-Id: <slrn96s7qr.plk.damian@puma.qimr.edu.au>
Thus spake Eric Bohlman on 23 Jan 2001 23:58:50 GMT:
>boussard <boussard@my-deja.com> wrote:
>> ...
>> for example:
>>
>> file 1:
>> diseaseID patientid
>> file 2:
>> diseaseID diseaseName
>> file 3:
>> diseaseName medicine
>>
>> I would like to create a new file with
>> patientID, diseaseName, medicine
>
>What you're talking about is called a "relational join" (as you might
>guess, a lot of the code in a relational database manager is devoted to
>doing this efficiently).
>
>...
>
>If you're going to be doing this a lot and file 2 or file 3 are large,
>consider building tied DBM hash files for them to speed things up.
Or indeed consider using a fully fledged RDBMS (MySQL is just a download
away). You could make each file above a separate table, then do the join
with an SQL statement like:
select file1.patientid, file2.diseaseName, file3.medicine
from file1, file2, file3
where file2.diseaseID = file1.diseaseID
and file3.diseaseName = file2.diseaseName;
You would then consult the perl DBI documentation for you preferred method
to get the output as a Perl data structure, then choose your own way to
output to file.
HTH
Cheers,
Damian
------------------------------
Date: 23 Jan 2001 21:34:48 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: hash table
Message-Id: <980285687.552723@hpvablab.cup.hp.com>
boussard <boussard@my-deja.com> writes:
>Sure, I have 4 files with a few variables and ~10,000 values in each
>file.
>
>for example:
>
>file 1:
>diseaseID patientid
>
>file 2:
>diseaseID diseaseName
>
>file 3:
>diseaseName medicine
>
>I would like to create a new file with
>
>patientID, diseaseName, medicine
I would use the following algorithm, basically a database join --
pseudocode follows:
Read file 2 and create a hash ... i.e., for each line:
$disease_names{$disease_id} = $disease_name;
Read file 3 and create a hash ... i.e., for each line:
$medicines{$disease_name} = $medicine;
Read file 1 and for each line:
print $patient_id, $disease_names{$disease_id}, $medicines{$disease_names{$disease_id}}
Rich
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014
------------------------------
Date: Tue, 23 Jan 2001 19:21:32 -0800
From: Anonymous <anonymous@anonymous.anonymous>
Subject: I N D I G O Perl - A Quick Opinion
Message-Id: <3A6E4A3C.CFF654AD@stomp.stomp.tokyo>
My apologies if you see this post more than once,
and my apologies to those of you who have me
killfiled as Godzilla and Kira. I've tried twice
today to post this article and, after many hours,
it doesn't show up on various news servers. My
best guess is SuperNews spam filters are rejecting
it based on the word "Indigo" in my subject line.
This is why I am using one of my other news servers
as Anonymous to post this. Darn SuckerNews anyhow.
..
Indigo Perl. This is a great, absolutely great
program to install both Perl and an Apache Web
Server for Win 32 environments, especially for
testing Perl based cgi applications.
Indigo Perl comes with Perl documentation,
Perl FAQs and CPAN modules documentation
along with a pre-configured Apache Web
Server including Perl and Mod_Perl for
running your cgi scripts. Indigo also
includes a fantastic graphical interface
for accessing Perl and Apache information.
Installation was a snap and flawless.
Not a single problem with installation
and only took a few minutes after unzip.
With a quick reboot to set a new path
via autoexec.bat, starting Indigo Perl
and an Apache Webserver, requires only
a mouse click under Start Program.
I do have an independent Apache Web
Server installed and am learning,
with the aid of a couple Apache books,
how to configure it, exhaustively.
This is worthwhile. However, installing
Indigo Perl allows me to test my scripts
with an easy one-click html interface
while I learn Apache.
To enhance this setup, I also have Perl
installed, binary build, for running
pure Perl scripts during development,
but have quite a bit of learning yet
before I master this program.
Indigo Perl allows me to write and
develop Perl cgi scripts instantly.
I am able to continue my studies
of Apache, continue my studies of
Perl, yet enjoy Perl programming
before I master these other programs.
This post is being made to help those
having problems incorporating Perl and
an Apache web server on a Win32 box.
I have read enough articles here asking
questions, about this and that, pertaining
to setting up Perl and Apache on Win to
warrant this suggestion.
Give Indigo Perl a try until you master
installation problems associated with
building your own Apache/Perl setup.
These installation and configuration
problems associated with a binary
install of Apache and Perl stand-alones
are quite formidable and time consuming.
Indigo Perl performs with flawless
perfection and requires no more than
a click on install.bat to setup. It
is a great program package.
http://www.indigostar.com/indigoperl.htm
It is extremely rare I suggest any program.
This one, Indigo Perl, is really nice.
Godzilla!
--
--------== Posted Anonymously via Newsfeeds.Com ==-------
Featuring the worlds only Anonymous Usenet Server
-----------== http://www.newsfeeds.com ==----------
------------------------------
Date: Wed, 24 Jan 2001 04:03:33 GMT
From: jbuff <jbuff1856@my-deja.com>
Subject: Re: I N D I G O Perl - A Quick Opinion
Message-Id: <94lk6i$78v$1@nnrp1.deja.com>
In article <3A6E4A3C.CFF654AD@stomp.stomp.tokyo>,
Anonymous <anonymous@anonymous.anonymous> wrote:
> http://www.indigostar.com/indigoperl.htm
>
> It is extremely rare I suggest any program.
> This one, Indigo Perl, is really nice.
>
Can you install CPAN modules?
--jbuff
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 23 Jan 2001 21:01:55 -0800
From: Anonymous <anonymous@anonymous.anonymous>
Subject: Re: I N D I G O Perl - A Quick Opinion
Message-Id: <3A6E61C3.CFFA0C5D@stomp.stomp.tokyo>
jbuff wrote:
Gosh darn it! Forgot this won't post via SuckerNews.
See my previous apologies to those whose feathers
I frequently ruffle, if not pluck, painfully.
Indigo, why the heck is SuckerNews spam filtering
that word? Hmm... is Indigo the color of prurient
sexual activities? Maybe it is filtered out because
it is one of seven prismatic colors.
jbuff wrote:
(Godzilla wrote from a different server:)
> > http://www.indigostar.com/indigoperl.htm
> > It is extremely rare I suggest any program.
> > This one, Indigo Perl, is really nice.
> Can you install CPAN modules?
Copy and paste from an introductory page:
It is provided in zip format with an installation script
written in perl. You can easily customize or repackage
it for redistribution with additional modules.
It can be installed on all Win32 systems.
It includes an integrated Apache webserver for testing and
developing CGI scripts. Apache is pre-configured for running
perl cgi scripts. Mod_perl is also installed.
It includes a browser based GUI Package Manager as well as a
command line Dynamic Package Manager. The package manager can
install pre-built binary packages from a repository as well as
well as CPAN source modules.
* minor giggle over their grammar *
You can read about Indigo at their site. I am very
pleased with this program package. For me personally,
their package is serving as a 'classroom example' of
how to configure Apache and Perl for a web server
environment. I can learn Apache from my books, play
with my independent Apache server along with looking
at configuration files under Indigo to see how they
wrote configuration files; working Apache examples.
For Perl, this Indigo package allows me to develop
Perl scripts while still working on mastering
ActiveState Perl and, I can study how Perl, along
with mod_perl, is configured for Apache via Indigo.
It is a free program and sure does everything they
claim it will do. Indigo delivers on their promises.
Can't beat this one with a stick. It's free, it works.
Godzilla!
--
--------== Posted Anonymously via Newsfeeds.Com ==-------
Featuring the worlds only Anonymous Usenet Server
-----------== http://www.newsfeeds.com ==----------
------------------------------
Date: Wed, 24 Jan 2001 00:10:47 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: java stream
Message-Id: <G7n4Hz.3p7@news.boeing.com>
In article <94k1rd$6a8$1@pheidippides.axion.bt.co.uk>,
Géry <ducateg@info.bt.co.uk> wrote:
>Hello,
>
>I have a Perl script which has to pass a hash to Cold Fusion, a package that
>is able to gather bits of data from various sources and build HTML code.
>Cold Fusion has its house language (CFML, where CF stands for Cold Fusion).
>It is ok to stream data from Java to Cold Fusion, but I have not found how
>to stream data from Perl.
>
>Therefore, my idea is to pass a hash to a java piece of code (applet,
>servlet, bean or whatever) which will in turn transmit it to Cold Fusion.
>
>Does anyone know of a handy module to pass a hash from Perl to Java. Even
>better, from Perl to Cold Fusion!
>
The JPL cross compiler would at least enable you to
embed Perl in Java -- not quite as classy as a direct
Perl to Java connection though.
http://search.cpan.org/search?dist=JPL
hth,
--
Charles DeRykus
------------------------------
Date: Tue, 23 Jan 2001 23:31:42 GMT
From: Tom <xxxtmanningxxx@canada.com>
Subject: Re: Performing ops on matched strings
Message-Id: <yvob6.50510$OD6.4626151@news1.telusplanet.net>
That's great, thanks :) Only problem I have left is how to keep it from
giving me a number with a couple dozen decimal points. Is there a way to
evaluate numbers in an expression and make sure it *only gives you two
decimal places?* I know printf would work, possibly, if for a different
purpose.
So far I have this, and it works:
foreach $i (@lines)
{
# $i =~ s/(\d\.\d\d)/eval (($1 \/ 1.1) + $1)/eg;
# $i =~ s/(\d\d\.\d\d)/eval (($1 \/ 1.1) + $1)/eg;
$i=~ s/\$(.*\d\.\d\d)/TESTING/g;
$n = eval (($1 / 1.1) + $1);
$i =~ s/TESTING/\$$n/g;
print $i;
}
I had to comment out the /e lines, since I needed to get prices with 1 and
with 2 numbers in front of the decimal point. Maybe there's a better way
(I'm fairly new at Perl, sorry!)
Tom
Damian James wrote:
> Thus spake Tom on Tue, 23 Jan 2001 22:46:28 GMT:
> >...
> >Problem:
> >I have an HTML file with a zillion things in it, among them some prices,
> >separated by commas. I want to increase the prices by a certain formula.
> >I was thinking of writing something like this:
> >
> >$i =~ s/\$(.*?),/<insert replace function here>/g;
> >
> >Solution? :
> >How do I use a formula to manipulate the matched floating point number,
> >and stick it back in the text??
> >
> >I want to change the matched number (eg 2.41) to ((2.41 / 1.1) + 2.41)
> >
>
> On the perlop manpage, look under s/// and see the example given for
> using the /e option.
>
> HTH
>
> Cheers,
> Damian
------------------------------
Date: Tue, 23 Jan 2001 23:45:58 GMT
From: Tom <xxxtmanningxxx@canada.com>
Subject: Re: Performing ops on matched strings
Message-Id: <WIob6.50514$OD6.4630169@news1.telusplanet.net>
Never mind, figured it out :) sprintf is my new friend..... Thanks....
Tom
Tom wrote:
> That's great, thanks :) Only problem I have left is how to keep it from
> giving me a number with a couple dozen decimal points. Is there a way to
> evaluate numbers in an expression and make sure it *only gives you two
> decimal places?* I know printf would work, possibly, if for a different
> purpose.
>
> So far I have this, and it works:
>
> foreach $i (@lines)
> {
> # $i =~ s/(\d\.\d\d)/eval (($1 \/ 1.1) + $1)/eg;
> # $i =~ s/(\d\d\.\d\d)/eval (($1 \/ 1.1) + $1)/eg;
>
> $i=~ s/\$(.*\d\.\d\d)/TESTING/g;
> $n = eval (($1 / 1.1) + $1);
> $i =~ s/TESTING/\$$n/g;
> print $i;
> }
>
> I had to comment out the /e lines, since I needed to get prices with 1 and
> with 2 numbers in front of the decimal point. Maybe there's a better way
> (I'm fairly new at Perl, sorry!)
>
> Tom
>
> Damian James wrote:
>
> > Thus spake Tom on Tue, 23 Jan 2001 22:46:28 GMT:
> > >...
> > >Problem:
> > >I have an HTML file with a zillion things in it, among them some
> > >prices, separated by commas. I want to increase the prices by a certain
> > >formula. I was thinking of writing something like this:
> > >
> > >$i =~ s/\$(.*?),/<insert replace function here>/g;
> > >
> > >Solution? :
> > >How do I use a formula to manipulate the matched floating point number,
> > >and stick it back in the text??
> > >
> > >I want to change the matched number (eg 2.41) to ((2.41 / 1.1) + 2.41)
> > >
> >
> > On the perlop manpage, look under s/// and see the example given for
> > using the /e option.
> >
> > HTH
> >
> > Cheers,
> > Damian
>
>
>
------------------------------
Date: Tue, 23 Jan 2001 18:10:38 -0600
From: "Hawk" <someguyREMOVE@REMOVEsunflower.com>
Subject: Re: Perl Crashes on my Win2k Box
Message-Id: <t6s7eikj6qtpec@corp.supernews.com>
If the regulars all have attitudes like yours, then they DO need to leave.
This newsgroup DOES exist to help people. If you can not grasp the concept
of sharing ideas and experiences to better your (and your peers) knowledge
of the language, then you DO need to leave. If all newbies are met with this
kind of resistance then this newsgroups existence is pointless.
How can
"Jeez, seems like we're beating the newbies off with a spoon lately.."
be taken in any other context? That is a condescending remark. Perhaps you
should wait until you have a more solid grasp on the English language before
you post a flame.
Cheers!
-Tony
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:94k55l$ema$2@mamenchi.zrz.TU-Berlin.DE...
> Hawk <someguyREMOVE@REMOVEsunflower.com> wrote in comp.lang.perl.misc:
>
> >This forum is to help people.
>
> Wrong. This newsgroup is for people who have an interest in the
> Perl language.
>
> > If you can not do that without your
> >condescending remarks, I'd like to be the first to suggest that you take
an
> >extended leave of absence.
>
> Wrong again. If you want free help, you'll have to take it at the
> terms given, including what your perceived condescending remarks.
> Or you have a choice?
>
> The fact that no actual help was offered besides education in the
> mores of this group may have to do with the fact that your problem
> description was next to null.
>
> Perhaps the ones that need to be "beaten off
with
> >a spoon" are the regulars with a god complex.
>
> Oh yeah. Drive out the regulars, good idea.
>
> Anno
------------------------------
Date: Wed, 24 Jan 2001 01:58:59 GMT
From: tuoihong@my-deja.com
Subject: Please help how to use Open3
Message-Id: <94lct0$176$1@nnrp1.deja.com>
I currently have a piece of code that looks like this:
open (FTP, "|lftp $server\n";
print FTP "user $username $password\n";
print FTP "mkdir $remote_dir\n";
print FTP "lcd $upload_dir\n";
print FTP "mput *\n";
close (FTP);
Currently ftp the files I need to ftp. However, I would like to
capture the output/error of the program "lftp" to LOG routine. I've
read the document on Open3 but not quite sure how to use it. If
someone can give some details on this, I would really appreciate it.
I'm new to Perl so please help....
(by the way useing Net::Ftp module is not an option).
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 24 Jan 2001 04:10:32 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Please help how to use Open3
Message-Id: <YAsb6.155$GF2.6376@eagle.america.net>
On Wed, 24 Jan 2001 01:58:59 GMT, tuoihong@my-deja.com
<tuoihong@my-deja.com> wrote:
>I currently have a piece of code that looks like this:
>
> open (FTP, "|lftp $server\n";
> print FTP "user $username $password\n";
> print FTP "mkdir $remote_dir\n";
> print FTP "lcd $upload_dir\n";
> print FTP "mput *\n";
> close (FTP);
>
>Currently ftp the files I need to ftp. However, I would like to
>capture the output/error of the program "lftp" to LOG routine. I've
>read the document on Open3 but not quite sure how to use it. If
>someone can give some details on this, I would really appreciate it.
>
>I'm new to Perl so please help....
>
>(by the way useing Net::Ftp module is not an option).
Why not? It's really what you want. (Well, Net::FTP is.)
--
Garry Williams
------------------------------
Date: Tue, 23 Jan 2001 22:14:20 -0600
From: bob <frawg@BLAH.sdf.lonestar.org>
Subject: Porting from VB to perl
Message-Id: <3A6E569C.184E753A@BLAH.sdf.lonestar.org>
I'm pretty sure that I'm going to get flamed for this, but what the
hell.
I've been stuck with the job of porting an XOR cipher routine from
Visual Basic to perl. So far, its turned out to be nigh impossible, and
I was wondering if anyone who is familliar with both languages might
have an idea as to what is going wrong. While my knowledge of Visual
Basic is little to none, I think I know enough to understand the logic
of the program, but all of my attempts to port it to perl have been
unsucessful to say the least. If you want to take a whack at it or have
any suggestions, you can take a look at the visual basic code at
http://members.fortunecity.com/fcsvenu/fullcode/encryptdec.html (I am
porting the StrDecode function) and here is the perl code I have come up
with so far:
sub decrypt {
my $i;
my $chr;
my @retArr;
my $ar = shift;
my $key = $ARGV[0];
my $len = scalar(@$ar);
my $k1 = (11 + ($key % 233));
my $k2 = (7 + ($key % 239));
my $k3 = (5 + ($key % 241));
my $k4 = (3 + ($key % 251));
for $i (0..($len)) {
$ar->[$i] = ord($ar->[$i]);
}
for $i (0..($len - 2)) {
$ar->[$i] = ($ar->[$i] ^ $ar->[$i + 2] ^ ($k4 * $ar->[$i + 1]) %
256);
$chr = chr($ar->[$i]);
push @retArr, $chr;
}
for ($i = $len; $i != 3; $i--) {
$ar->[$i] = ($ar->[$i] ^ $ar->[$i - 2] ^ ($k3 * $ar->[$i - 1]) %
256);
$chr = chr($ar->[$i]);
for $i (0..($len - 1)) {
$ar->[$i] = ($ar->[$i] ^ $ar->[$i + 1] ^ ($k2 * $ar->[$i + 1]) %
256);
$chr = chr($ar->[$i]);
push @retArr, $chr;
}
for ($i = $len; $i !=2; $i--) {
$ar->[$i] = ($ar->[$i] ^ $ar->[$i - 1] ^ ($k1 * $ar->[$i - 1]) %
256);
$chr = chr($ar->[$i]);
push @retArr, $chr;
}
return @retArr;
}
------------------------------
Date: Wed, 24 Jan 2001 15:23:31 +1100
From: "Chris W" <chrisw@dynamite.com.au>
Subject: Re: Porting from VB to perl
Message-Id: <wOsb6.83$Q82.3140@news0.optus.net.au>
"bob" <frawg@BLAH.sdf.lonestar.org> wrote in message
news:3A6E569C.184E753A@BLAH.sdf.lonestar.org...
> I'm pretty sure that I'm going to get flamed for this, but what the
> hell.
Got your asbestos underwear on? :-)
> sub decrypt {
> my $i;
> my $chr;
> my @retArr;
>
> my $ar = shift;
> my $key = $ARGV[0];
> my $len = scalar(@$ar);
$len now contains the number of elements in the array referenced by the
first argument to the function. This will make all the following for()
loops one iteration longer than I think you really want them. If you start
your for() loops with a zero index (it's one in VB) then you probably want
$#{@$ar} to get the upper bound for the array.
Contrast the results from these:
perl -e "@t=(0, 1, 2, 3); $ar = \@t; print $#{@$ar}; "
perl -e "@t=(0, 1, 2, 3); $ar = \@t; print scalar(@$ar); "
Are you really passing in an array reference, or just an array (list)?
------------------------------
Date: Wed, 24 Jan 2001 02:24:37 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: printing to a printer?
Message-Id: <hves6tcd8k8vqf8nasgqjkjaf36lc4ph6e@4ax.com>
On Tue, 23 Jan 2001 20:34:11 GMT, hanja <hanja@my-deja.com> wrote:
>Is it possible to print a file to a printer instead
>to the screen?
Yes.
That being said, you might try sharing a few other things, such as
your operating system, code that you have tried (please tell me you
tried something before posting), etc. We aren't mind readers here.
For example, assuming an MS-Win32 environment, the following will work
for a printer defined to the system as LPT1...
open PRINTER, ">lpt1:";
print PRINTER "Testing the printer.\n\f";
close PRINTER;
Note the form feed at the end of the line. Some configurations will
not actually dump the page until a form feed is encountered, which may
be your problem.
Let us know what you tried and you'll be a thousand times more likely
to get useful help.
JH
------------------------------
Date: Tue, 23 Jan 2001 09:02:18 +0200
From: "Ofir" <ofirb@jdc.org.il>
Subject: Re: Quick Newbie Qeustion please...
Message-Id: <94ja97$4q0$1@news.netvision.net.il>
Wow, that's a nice answer. NOT to my question though...;-)
"Eric Bohlman" <ebohlman@omsdev.com> wrote in message
news:94gjk6$rtd$1@bob.news.rcn.net...
> Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> > #!/usr/bin/perl -w
> > use strict;
>
> > package get;
>
> > sub clue { exec("perldoc", "perldoc") }
>
> > get a clue
>
> > __END__
>
> That's not valid indirect-object syntax; you'd need something like:
>
> package a;
>
> sub get {exec('perldoc', 'perldoc') if shift() eq 'clue'}
>
> get a clue;
>
------------------------------
Date: Wed, 24 Jan 2001 04:42:29 GMT
From: "Roman Moeller" <roman@topologix.de>
Subject: Re: s/// inconsistency
Message-Id: <94lmd5$139$1@crusher.de.colt.net>
On 23-Jan-2001, mgjv@tradingpost.com.au (Martien Verbruggen) wrote:
> $2 and $1 are just variables. They get used by Perl internally, but in
> contexts like these they're the same as all the others.
This was my fundamental misconception. I thought of them as backreferences
which only make sense in the replacement string as those old \1 ones.
I never considered \1 as a full flexed variable, but something internal to
the regex machine.
> > Any better ?
>
> Yes. Don't do it this way. Maybe you should sort of explain to us what
> it is you want to do, and maybe we can cone up with a better solution to
> the problem.
I need a file rename tool with the full power of perls regexes. So
both the pattern as the substitution are commaand line parameters.
Here is what i got so far
------------------------------
Date: Wed, 24 Jan 2001 04:42:29 GMT
From: "Roman Moeller" <roman@topologix.de>
Subject: Re: s/// inconsistency
Message-Id: <94lmd5$139$2@crusher.de.colt.net>
On 23-Jan-2001, mgjv@tradingpost.com.au (Martien Verbruggen) wrote:
> $2 and $1 are just variables. They get used by Perl internally, but in
> contexts like these they're the same as all the others.
That was my fundamental misconception. I thought of them as something
special
for the regex machine, possibly due to the old \1 notation. I never thought
of \1
being a variable, because it made only sense in the replacement string
> > Any better ?
> Yes. Don't do it this way. Maybe you should sort of explain to us what
> it is you want to do, and maybe we can cone up with a better solution to
> the problem. If you just want to reverse the two matches, a literal $2$1
> in the right hand side of the s/// will do. But you're not using a
> literal, so there must be some magical need oyu have that we're not
> aware of. Once you tell us what that is, maybe we'll be able to tell you
> whether you need to use ugly stuff, or whether you can use less ugly
> stuff.
Not so magical at all. I need a file rename tool with the full power of
perls
regexes. So both the pattern and the replacement string are command
line parameters. Here's what I got so far
#!/usr/bin/perl -w
use strict ;
my ($pat,$sub) = @ARGV ;
# argument validation usingusing cookbooks eval trick skipped
opendir(CUR,".");
my @files = grep { -f "./$_" } readdir CUR ;
my @matches = grep { /$pat/ } @files ;
my (%subs,$s) ;
foreach my $m (@matches) {
eval '($s=$m)'." =~ s/$pat/$sub/;"; #still ugly
$subs{$m}=$s;
}
# implementation of renaming skipped, debug output instead
foreach my $k (keys %subs) {
print "$k -> $subs{$k}";
}
After all, if everything I learned from this thread is correct, I'll have
to bear the eval uglyness, because the command line parameters
are inherently "symbolic references".
Thanks for your insights.
Roman
------------------------------
Date: Tue, 23 Jan 2001 09:09:53 +0200
From: "Ofir" <ofirb@jdc.org.il>
Subject: Thanks Joe & Eric
Message-Id: <94jane$51c$1@news.netvision.net.il>
Wow, that's a nice answer. NOT to my question though...;-)
Hi all,
I want to be able to determine how many lines are in a file.
What is the way (subroutine) to check the total number of lines written in a
file?
TIA,
Ofir
ebohlman@omsdev.com (Eric Bohlman) writes:
> Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> > #!/usr/bin/perl -w
> > use strict;
>
> > package get;
>
> > sub clue { exec("perldoc", "perldoc") }
>
> > get a clue
>
> > __END__
>
> That's not valid indirect-object syntax; you'd need something like:
>
> package a;
>
> sub get {exec('perldoc', 'perldoc') if shift() eq 'clue'}
>
> get a clue;
>
Not really; if you don't like the "package get;" line,
you can just comment it out. The syntax is just fine either
way. Try running the original first, though ;)
--
Joe Schaefer
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 130
**************************************