[18689] in Perl-Users-Digest
Perl-Users Digest, Issue: 857 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 8 18:06:41 2001
Date: Tue, 8 May 2001 15:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <989359509-v10-i857@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 8 May 2001 Volume: 10 Number: 857
Today's topics:
Re: Any d20 Gamers here? I'm building a GM aid... <bmstroh@cavtel.com>
client server application <alikbm@tx.technion.ac.il>
Re: difference of arrays ?? nobull@mail.com
Re: difference of arrays ?? <jesse@uchicago.edu>
Re: difference of arrays ?? <joe+usenet@sunstarsys.com>
Re: difference of arrays ?? <ren@tivoli.com>
DNS lookup (Bones)
Re: DNS lookup (Charles DeRykus)
Re: Good editor for perl Use Scite ! <hayden@club-internet.fr>
hanging fork? <sshannon@acc.com>
HELP with @INC <dennis.kowalsk@daytonoh.ncr.com>
Re: HELP with @INC <bart.lateur@skynet.be>
Re: How can you tell which modules are loaded? <lmoran@wtsg.com>
how to set debug mode in perl (LMC)
Re: latest stable version of Perl <Robert.Lopez@abq.sc.philips.com>
Re: latest stable version of Perl <elijah@workspot.net>
Loading a file full of SQL via DBI/DBD <pboin@sans.spam.mindspring.com>
need help with reading, splicing, substitution <lmoran@wtsg.com>
Re: need help with reading, splicing, substitution <ren@tivoli.com>
Re: need help with reading, splicing, substitution <krahnj@acm.org>
Re: need help with reading, splicing, substitution <lmoran@wtsg.com>
Question about "->" operator <napes@attglobal.net>
Re: R: Price for work? (BUCK NAKED1)
Really strange scoping problem! Help! ("Richard Stands")
Re: redirect to a url & avoiding hacks <tinamue@zedat.fu-berlin.de>
Seeking a PERL Tutorial <nweissma@mathlab.sunysb.edu>
Re: Seeking a PERL Tutorial <soso@open.net>
Re: Sort String <uri@sysarch.com>
Take out lines that are flagged <jimbob4334@deja.com>
Re: Take out lines that are flagged <krahnj@acm.org>
Re: unicode support in perl 5.6 -- I'm trying to get it <ilya@math.ohio-state.edu>
Re: unicode support in perl 5.6 -- I'm trying to get it <elijah@workspot.net>
Re: very big array <carlos@plant.student.utwente.nl>
Re: What would you do <me@my_no_spam.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 8 May 2001 10:40:14 -0700
From: Brent Stroh <bmstroh@cavtel.com>
Subject: Re: Any d20 Gamers here? I'm building a GM aid...
Message-Id: <9d9b1u06h@drn.newsguy.com>
In article <tfeu46e4ds7p7a@corp.supernews.com>, cberry@cinenet.net says...
>Interesting idea. Here's my approach for just the die-rolling part:
>
>#!/usr/bin/perl -w
># rpgdice - role dice for role-playing games.
># Craig Berry (20010507)
8< snip >8 of rpgdice
Good start. Unfortunately, I had to be a bit more anal than that. So, my dice
roller handles things like "4d6 keep 3 highest/lowest," "3d6 reroll 1s & 2s,"
etc. On the bright side, dice rolling is pretty easy; I've had something
written to do that for literally years.
Since I was trying to do something to force myself into more advanced topics,
each roll is an object, which I can save to avoid lookups later.
This lets me do things like figure out a skill roll, build a 'roll string,'
something like '1d20+4,' and use that to create ${self->{SKILL}}{hide}, which I
can store in ${character->{ROLLS}}{hide} for later reference. Saves me from
having to look up a skill score, ability modifier, etc, to build the roll string
each time.
Since d20 is a lot more streamlined than previous AD&D rules, it's much easier
to build a tool of this sort. Plus, running a PBEM over lunch, I'd rather not
have to shuffle dice & character sheets at my desk. :)
Some aspects of this seem like taking a sledgehammer to a gnat, but it's given
me an excuse to read and understand perltoot, and spend a lot more time with
references - things I've never pushed myself to learn before.
------------------------------
Date: Tue, 8 May 2001 22:58:26 +0200
From: "alik blochin" <alikbm@tx.technion.ac.il>
Subject: client server application
Message-Id: <9d9j0r$ssp$1@news.huji.ac.il>
Hi
i have a problem :
i have an external page which returns some info
how can i in javascript in my current page to get an
output of the external page ?
basicly i need to get an output from this page
every 6-7 seconds and upon the output to proceed ..
i've been thinking about layers but
how do i load a layer every 6-7 seconds ?
this the client-server application
and this external page (CGI script) is just checking wheather the server is
processing some information....
every time the information is processing in the server i want it to be shown
in my page :
processing....
processing...
once the server is through
it would be shown :
DONE......
so how do i do it ?
any help would be greatly appriciated....
------------------------------
Date: 08 May 2001 19:03:06 +0100
From: nobull@mail.com
Subject: Re: difference of arrays ??
Message-Id: <u9vgnblnvp.fsf@wcl-l.bham.ac.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> According to Logan Shaw <logan@cs.utexas.edu>:
> > In article <9d97gh$gph$1@mamenchi.zrz.TU-Berlin.DE>,
> > Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > >According to steve farris <sfarris9@home.com>:
> > >> Anybody know a one liner to get the difference of two arrays?
> > >>
> > >> e.g.
> > >>
> > >> @a = qw/one two three/;
> > >> @b = qw/one three/;
> > >>
> > >> @a - @b = ("two")
> > >
> > >That's a FAQ, and "perldoc -q difference" would have taken you there.
> >
> > Not exactly. The question was whether anyone knows a one-liner, and
> > the answer in the FAQ is 7 lines.
>
> [good answer snipped]
>
> You mean I should *read* the question before replying? What next?
I also pointed the OP to the FAQ.
Concatenating 7 lines into 1 is left as an exercise for the reader :-)
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 08 May 2001 14:09:47 -0500
From: Jesse James Jensen <jesse@uchicago.edu>
Subject: Re: difference of arrays ??
Message-Id: <3AF8447B.878CF83B@uchicago.edu>
nobull@mail.com wrote:
>
> Concatenating 7 lines into 1 is left as an exercise for the reader :-)
>
> -- \\ ( ) . _\\__[oo .__/ \\ /\@ . l___\\ # ll l\\ ###LL LL\\
But sometimes it's just not the same, is it?
------------------------------
Date: 08 May 2001 15:12:44 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: difference of arrays ??
Message-Id: <m34ruv1wpf.fsf@mumonkan.sunstarsys.com>
logan@cs.utexas.edu (Logan Shaw) writes:
> To put it another way, if I understood the question right, then if you
> have this:
>
> @a = qw/one two three/;
> @b = qw/one three four/;
>
> then, @a - @b should be qw/two/ and @b - @a should be qw/four/ ,
> whereas the FAQ says the answer it would give is qw/two four/ .
>
> Anyway, one possible one-liner is this:
>
> @a_minus_b = grep { my $x = $_ ; not grep ($x eq $_, @b) } @a;
>
> Not the prettiest or the most efficient, but it is one line.
Here's another one:
@a_minus_b = do {my %h; undef @h{@a}; delete @h{@b}; keys %h};
noisy, but fewer strokes
@a_minus_b=do{my%h;\@h{@a};delete@h{@b};keys%h};
--
Joe Schaefer "The only thing that interferes with my learning is my
education."
--Albert Einstein
------------------------------
Date: 08 May 2001 13:49:26 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: difference of arrays ??
Message-Id: <m3u22vsmkp.fsf@dhcp9-172.support.tivoli.com>
On 08 May 2001, nobull@mail.com wrote:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>
>> According to Logan Shaw <logan@cs.utexas.edu>:
>> > In article <9d97gh$gph$1@mamenchi.zrz.TU-Berlin.DE>,
>> > Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>> > >According to steve farris <sfarris9@home.com>:
>> > >> Anybody know a one liner to get the difference of two arrays?
>> > >>
>> > >> e.g.
>> > >>
>> > >> @a = qw/one two three/;
>> > >> @b = qw/one three/;
>> > >>
>> > >> @a - @b = ("two")
>> > >
>> > >That's a FAQ, and "perldoc -q difference" would have taken you
>> > >there.
>> >
>> > Not exactly. The question was whether anyone knows a one-liner,
>> > and the answer in the FAQ is 7 lines.
>>
>> You mean I should *read* the question before replying? What next?
>
> I also pointed the OP to the FAQ.
>
> Concatenating 7 lines into 1 is left as an exercise for the reader
> :-)
As is converting the symmetric difference provided in the FAQ to the
asymmetric difference that the OP is likely after.
If anyone's in the mood, it seems like including code for asymmetric
difference in the FAQ would be useful.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 08 May 2001 18:23:54 GMT
From: xbonesgt@cc.gatech.edu (Bones)
Subject: DNS lookup
Message-Id: <3af834df.55154613@news.gatech.edu>
I'm working on a script that takes in the name of a server and returns
its IP, using the local machine's DNS lookup mechanism. I was also
hoping to do it without the need for any external modules. So I took
a look at the gethostbyname function, but I haven't done any
network-related programming like this before (I've only done text-file
munging and simple CGI scripts) and I'm confused by the POD on cpan,
and not even sure this is the function I want to use anyway. If
anyone could point me in the right direction, either with example code
or a helpful Web page, It would be much appreciated. Thanks in
advance.
-Dan Orzechowski
xbonesgt@cc.gatech.edu
B is for BORIS, assaulted by bears.
------------------------------
Date: Tue, 8 May 2001 20:11:32 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: DNS lookup
Message-Id: <GD19F8.25t@news.boeing.com>
In article <3af834df.55154613@news.gatech.edu>,
Bones <xbonesgt@cc.gatech.edu> wrote:
>I'm working on a script that takes in the name of a server and returns
>its IP, using the local machine's DNS lookup mechanism. I was also
>hoping to do it without the need for any external modules. So I took
>a look at the gethostbyname function, but I haven't done any
>network-related programming like this before (I've only done text-file
>munging and simple CGI scripts) and I'm confused by the POD on cpan,
>and not even sure this is the function I want to use anyway. If
>anyone could point me in the right direction, either with example code
>or a helpful Web page, It would be much appreciated. Thanks in
>advance.
>
use Socket; # comes with Perl distribution
my $packed_ip = gethosbyname($server_name);
my $server_ip = inet_ntoa($packed_ip);
or module-less:
my $packed_ip = gethosbyname($server_name);
my $server_ip = join "." => unpack("C4",$packed_ip);
Look at the doc/examples for additional info: perldoc perlipc
The "Perl Cookbook" for many networking examples as well.
--
Charles DeRykus
------------------------------
Date: Mon, 7 May 2001 21:03:03 +0200
From: "Prévost Christophe" <hayden@club-internet.fr>
Subject: Re: Good editor for perl Use Scite !
Message-Id: <9d7kup$41s$1@front1m.grolier.fr>
"Super-Simon"
> I'm searching for a good, fast editor with syntax highlighting for perl
> (CGI) for use under Windows 2000 / Windows 98 (I use windowz only for
> editing scripts, scripts runs on Linux-server). It has to be free (I'm a
> poor student ;-)
I'm quite surprise that scite isn't better known...
Scite use Scintilla control like komodo but scite it reallly small. Komodo
use a lot of memory. Scite is cross platform (Linux / Win32) and really
customisable. In fact to be really easy to use you may have to customize it
(for example to change the position of the output bar, to enable line
numbers on gutter, enable multiple buffers, customise syntax highligthing
etc...)
Scite is updated oftently, free... opensource... marvellous... paramount
I use it for php, python and perl...
URL: http://www.scintilla.org
------------------------------
Date: Tue, 08 May 2001 14:42:33 -0700
From: Scott Shannon <sshannon@acc.com>
Subject: hanging fork?
Message-Id: <3AF86849.44936C85@acc.com>
Hi. I'm new to perl&cgi, so sorry if this is a silly problem...
I'm trying to make a perl cgi script that will usually run a long
program on some othe rmachines (I'm doing that with Net::Telnet).
Because its long , I want to fork, give a simple message in the parent,
which then returns to the main page, while the child ges off and
runs the program, later emailing the result.
The problem Im finding is that, even tho the fork works, the
parent 'hangs' like it's waiting for the child to finish...when I say
hang I mean the little loading bar at the bottom of the page is
still going, and when I hit either the form return button or simple
stop,
I get a big "Transfere Interrupted'..on the page, and when I view the
resulting source,
it says something about 'Missing post reply data...'.
Why is the webpage 'waiting' for the child to finish even tho its forked
off?
I realise I could possibly avoid this by creating a seperate program,
whichis called
via a system call along with all the parameters (which is why i want to
avoid
doing that), but is there another way around this problem? Thanks for
any info
S
------------------------------
Date: Tue, 8 May 2001 15:44:14 -0400
From: "Dennis Kowalski" <dennis.kowalsk@daytonoh.ncr.com>
Subject: HELP with @INC
Message-Id: <3af84c8c$1@rpc1284.daytonoh.ncr.com>
I am trying to modify @INC at runtime to include a directory where I have a
.pm file.
Say it is x.pm in /dira/dirb
This works as the first line of the script
#!/bin/perl -I/dira/dirb
use x;
I do not want to hardcode the location so I have tried the following
variations.
I have an environmental variable called MYLIB set to /dira/dirb and the
following does not work
#!/bin/perl -I$MYLIB
neither does
#!/bin/$ENV{MYLIB}
The $MYLIB text is added to @INC.
I have also tried the following
use lib $ENV{MYLIB}
That does not work either.
I have also tried
push @INC, $ENV{MYLIB};
That does not work either.
When it fails I get a BEGIN failed message saying x.pm could not be found.
The use x.pm follows all of the variations I have shown you.
Can someone tell me how to add the contents of an environmental variable to
@INC ??
------------------------------
Date: Tue, 08 May 2001 20:49:47 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: HELP with @INC
Message-Id: <p0ngftkdbpdrllj9f0h8ma0iiv4dr58gng@4ax.com>
Dennis Kowalski wrote:
>I am trying to modify @INC at runtime to include a directory where I have a
>.pm file.
>
>Say it is x.pm in /dira/dirb
>
>This works as the first line of the script
>
>#!/bin/perl -I/dira/dirb
>
>use x;
>
>I do not want to hardcode the location
Have you tried setting the environment variable PERL5LIB?
--
Bart.
------------------------------
Date: Tue, 08 May 2001 14:39:41 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: How can you tell which modules are loaded?
Message-Id: <u4fgft8esp4mtghrfq11m6ta46q9tti2dv@4ax.com>
On 08 May 2001 17:41:55 +0100, nobull@mail.com wrote wonderful things
about sparkplugs:
>Lou Moran <lmoran@wtsg.com> writes:
>
>> --Say I sit at diff't boxes with diff't OSes but they all have Perl.
>>
>> --How can I tell which modules are loaded?
>
>The list of _loaded_ modules is keys(%INC).
>
>I suspect you mean the list of installed modules.
I meant that which you have mentioned
>
>perldoc perllocal
perfect
--
print "\x{263a}"
------------------------------
Date: Tue, 08 May 2001 17:33:37 -0400
From: "Andrew Pan (LMC)" <Andrew.Pan@lmc.ericsson.se>
Subject: how to set debug mode in perl
Message-Id: <3AF86631.503B1931@lmc.ericsson.se>
Hi there,
I'm a new user of Perl and I'd like to know how to set debug mode when
running perl script. As you know in B shell script we can add "set -x"
in the first line then the script would run in debug mode, showing every
step's I/O. Basically I'd like to have the same function in Perl.
Thanks a lot for your help.
BR/Andrew
------------------------------
Date: 08 May 2001 12:17:00 -0600
From: Robert Lopez <Robert.Lopez@abq.sc.philips.com>
Subject: Re: latest stable version of Perl
Message-Id: <jc6n18nemeb.fsf@abqb1k.sc.philips.com>
abigail@foad.org (Abigail) writes:
> Brian Cantin (dcantin@earthlink.net) wrote on MMDCCCVII September
> MCMXCIII in <URL:news:wkr8y0lbd1.fsf@earthlink.net>:
> ''
> '' I am about to install a new version of Perl on mutiple platforms.
> '' For a variety of infrastructure reasons, changing the Perl version
> '' is a big deal. When I went to CPAN, 5.6.1 was identified as the
> '' latest stable version. So, I have been working with 5.6.1 in
> '' preparing for the upgrade.
> ''
> '' Randal Schwartz recently posted a message where he said that
> '' 5.6.1 is not shaken out enough for use on his production machines.
> ''
> '' So, if you were to pick a Perl version that you trusted in a
> '' production environment, which one would it be?
>
>
> None. Every version of Perl I've used had its problems in one way or the
> other. Just because Randal doesn't want to use 5.6.1 on his production
> servers (note that Randal gives no clue what kind of mission critical
> things he's doing with Perl) doesn't mean you shouldn't. Perhaps the
> version of Perl Randal finds suitable for his machines won't work for you.
>
>
>
> Abigail
> --
> srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
> //=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
"None." Is this to say abigail has never implemented a production
program in perl? Teasing or serious?
--
Robert.Lopez@Philips.com
------------------------------
Date: 8 May 2001 21:28:09 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: latest stable version of Perl
Message-Id: <eli$0105081722@qz.little-neck.ny.us>
In comp.lang.perl.misc, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> >>>>> "Brian" == Brian Cantin <dcantin@earthlink.net> writes:
> Brian> So, if you were to pick a Perl version that you trusted in a
> Brian> production environment, which one would it be?
> I've never been happy with what I saw about 5.6.0, so I'm running
> 5.5.3 until I decide 5.6.1 is fine.
I second the 5.005_03 recomentdation. I just wish the CPAN module
wouldn't try to upgrade perl itself for me, even if some module
claims to be dependent on it.
Elijah
------
thinks it was the libnet bundle that tried to do that
------------------------------
Date: Tue, 08 May 2001 17:46:11 -0400
From: pb <pboin@sans.spam.mindspring.com>
Subject: Loading a file full of SQL via DBI/DBD
Message-Id: <aopgftcnna5si3ae42oprn9vl9shcfv2dk@4ax.com>
I'm trying to separate what's basically a bunch of CREATE TABLE
statements from my perl code. It just seems easier maintainence-wise
to keep the files separate.
Now, I know mySQL has LOAD DATA INFILE, but I want to remain un-bound
to a particular database. Therefore, I'm re-inventing that particular
wheel by reading the file, looking for a complete SQL statement, and
then sending it to the db via the do() method from DBI.
I think I'm having some kind of DOS/UNIX or chop/chomp end of line
problems, and I'm totally burnt from working on it the last few hours.
I'm about to hang it up and come back tommorrow, but figured I'd throw
it out anyway.
What's wierd is that the 'or die' clause doesn't get hit, but mySQL
does indeed send back error messages and the program does stop
running. The mySQL error messages don't seem to have good carriage
control, and I think they're writing over them selves.
Here's a quickly condensed version of what I'm doing:
sub execExternalSQL{
my $sqlstring = "";
my $ifile = $_[0]; # assign 1st parm to $ifile (sql commands)
while (<SQL>){
if ($_ =~ /^#/){ next;} # skip comments in the SQL entirely
else{
$sqlstring = $sqlstring.$_; # concatenate new data
chomp($sqlstring);
}
# if we found the end semicolon AND there's some length
if ( $sqlstring =~ /;/ && length($sqlstring)){
$dbh->do($sqlstring) or die ("Ack!:$sqlstring\n");
$sqlstring = "";
}
}
}
--
pb
------------------------------
Date: Tue, 08 May 2001 15:59:39 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: need help with reading, splicing, substitution
Message-Id: <mpigft8biobuu98010j5edcif3o401n7c3@4ax.com>
--I want to write a script that will read the following from a text
file:
paaro
aachi
jachi
(+300 more)
and do the output the following:
paaro = 72276
aachi = 22244
jachi = 52244
The way the numbers get "figured out" is:
ABC = 2
DEF = 3
GHI = 4
JKL = 5
MNO = 6
PQR = 7
STU = 8
VWX = 9
YZ = 0
So I have a text file formatted like the above, or:
paaro
aachi
jachi
which I OPEN and next is where it all gets real fuzzy...
I assume I need to (oh please let this be the right word) splice the
names so that the letters can be substituted:
s/a/2;
s/b/2;
s/c/3;
and so on (although I am guessing there is a better way.)
So here's the questions:
1 -- what's the best way to splice those 5 character strings in their
current format, or should the text be reformatted?
2 -- what's the best way to write that substution string (regex)?
3 -- if I s/ or t/ how can I keep the orginal value for the final
output?
Hope this make sense.
--
print "\x{263a}"
------------------------------
Date: 08 May 2001 15:21:43 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: need help with reading, splicing, substitution
Message-Id: <m37kzrsiaw.fsf@dhcp9-172.support.tivoli.com>
On Tue, 08 May 2001, lmoran@wtsg.com wrote:
> --I want to write a script that will read the following from a text
> file:
>
> paaro
> aachi
> jachi
>
>
> (+300 more)
>
> and do the output the following:
>
> paaro = 72276
> aachi = 22244
> jachi = 52244
>
> The way the numbers get "figured out" is:
>
> ABC = 2
> DEF = 3
> GHI = 4
> JKL = 5
> MNO = 6
> PQR = 7
> STU = 8
> VWX = 9
> YZ = 0
Actually, this is quite simple:
perl -pe "y/A-Za-z/2223334445556667778889990022233344455566677788899900/"
> I assume I need to (oh please let this be the right word) splice the
> names so that the letters can be substituted:
splice isn't the right word, though it is a Perl function. Issuing
"perldoc -f splice" will describe it.
> s/a/2;
> s/b/2;
> s/c/3;
>
> and so on (although I am guessing there is a better way.)
You guessed correctly! tr/// (a.k.a. y/// as above) is the better
way. See perlop(1) for a description.
> So here's the questions:
>
> 1 -- what's the best way to splice those 5 character strings in their
> current format, or should the text be reformatted?
> 2 -- what's the best way to write that substution string (regex)?
> 3 -- if I s/ or t/ how can I keep the orginal value for the final
> output?
If you need to keep the current values, just copy them first:
($new = $old) =~
tr/A-Za-z/2223334445556667778889990022233344455566677788899900/;
Unfortunately, as perlop(1) states:
Because the transliteration table is built at com
pile time, neither the SEARCHLIST nor the REPLACE
MENTLIST are subjected to double quote interpola
tion. That means that if you want to use vari
ables, you must use an eval():
eval "tr/$oldlist/$newlist/";
die $@ if $@;
eval "tr/$oldlist/$newlist/, 1" or die $@;
which is even uglier than that long sequences of numbers.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 08 May 2001 21:18:24 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: need help with reading, splicing, substitution
Message-Id: <3AF8629C.9B45A5AA@acm.org>
Lou Moran wrote:
>
> --I want to write a script that will read the following from a text
> file:
>
> paaro
> aachi
> jachi
>
> (+300 more)
>
> and do the output the following:
>
> paaro = 72276
> aachi = 22244
> jachi = 52244
>
> The way the numbers get "figured out" is:
>
> ABC = 2
> DEF = 3
> GHI = 4
> JKL = 5
> MNO = 6
> PQR = 7
> STU = 8
> VWX = 9
> YZ = 0
>
> So I have a text file formatted like the above, or:
>
> paaro
> aachi
> jachi
>
> which I OPEN and next is where it all gets real fuzzy...
>
> I assume I need to (oh please let this be the right word) splice the
> names so that the letters can be substituted:
>
> s/a/2;
> s/b/2;
> s/c/3;
>
> and so on (although I am guessing there is a better way.)
>
> So here's the questions:
>
> 1 -- what's the best way to splice those 5 character strings in their
> current format, or should the text be reformatted?
> 2 -- what's the best way to write that substution string (regex)?
> 3 -- if I s/ or t/ how can I keep the orginal value for the final
> output?
my %lookup;
@lookup{ ('A'..'Z','a'..'z') } =
(2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,0,0) x 2;
while ( <TEXTFILE> ) {
chomp;
( my $x = $_ ) =~ s/(.)/$lookup{$1}/eg;
print "$_ = $x\n";
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 08 May 2001 17:37:28 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: need help with reading, splicing, substitution
Message-Id: <m9pgft0opgedknulicdlu5hoqq0djlmkf4@4ax.com>
On 08 May 2001 15:21:43 -0500, Ren Maddox <ren@tivoli.com> wrote
wonderful things about sparkplugs:
>Actually, this is quite simple:
>
>perl -pe "y/A-Za-z/2223334445556667778889990022233344455566677788899900/"
>
SNIP
Thanks yours is way better
>
>If you need to keep the current values, just copy them first:
>
> ($new = $old) =~
> tr/A-Za-z/2223334445556667778889990022233344455566677788899900/;
>
since I open a file to get the info out I figured out (indirectly from
your answer that I could do it this way instead of copying.
#!/usr/bin/perl -w
use diagnostics;
use strict;
open (LIST, "sn.txt") ||
die "No file sn.txt exists." ;
my $pwd = <LIST>;
$pwd =~ s/^/, /; #attempt to replace \n with ", " -- not working
$pwd =~
y/A-Za-z/2223334445556667778889990022233344455566677788899900/;
my $names = <LIST>;
print "$names = $pwd";
close LIST;
___
So now the only hurdle left is how to get this script to read more
than the first line of my text file. I am guessing from the output:
aachi
= , 72276
that newlines (or something just like them from notepd.exe) are the
culprit. I thought I could reformat the text on the fly with:
s/^/, / but I was sorely mistaken.
I appreciate your help.
Thanks,
Lou M
--
print "\x{263a}"
------------------------------
Date: Tue, 08 May 2001 18:04:12 -0400
From: Ed Napier <napes@attglobal.net>
Subject: Question about "->" operator
Message-Id: <3AF86D5C.E3848F99@attglobal.net>
I feel as though I'm misunderstanding something. I think the thing I'm
missing is a complete understanding of the "->", the infix dereference
operator.
Here is a snippet of code.
# Take the first element and use it as the key
# to the primary list.
# Take the second element and use it as the key
# to the secondary list.
# Take the third element and use it as the value to the
# to the secondary list.
#$cds->{$host}->{$src} = $dest;
$cds{$host}->{$src} = $dest; # This line does what I want. The
one
above does not.
I don't really understand what I'm asking perl to do when I use "->".
Can
someone explain it to me? I checked perlop, but that really doesn't
click.
Thanks,
Ed
------------------------------
Date: Tue, 8 May 2001 14:37:53 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: R: Price for work?
Message-Id: <28090-3AF84B11-10@storefull-243.iap.bryant.webtv.net>
I had someone ask me to do some HTML pages for them and told them $25/hr
and never heard from them again... though I think that $20-$25/hr is a
fair price for HTML. On the contrary, If I knew perl well, I think
$50-$60/hr would a fair price. For an "expert" perler, maybe
$75-$100/hr.
Just my 2cents.
--Dennis
------------------------------
Date: Tue, 8 May 2001 21:00:31 +0000 (UTC)
From: rstands@hotmail.com ("Richard Stands")
Subject: Really strange scoping problem! Help!
Message-Id: <F43CI76rOJhKPc99ir30000013f@hotmail.com>
<html><DIV>I am using Win32::API(Version: 0.01 (08 Jul 1997)) with Perl(Activestate Perl ver. v5.6.0 built for<BR>MSWin32-x86-multi-thread) on an NT workstation(sp5) to access a third party dll.<BR>This library(dll) requires one to create a (c type long) session handle first and then pass<BR>that to any subsequent function calls. This all works fine in a simple test<BR>script e.g.:</DIV>
<DIV> </DIV>
<DIV>use Win32::API;<BR>my $api = new Win32::API("the.dll", "function1", ["P"], ["V"]);<BR>my $ptr = pack("L", 0);<BR>$api->Call($ptr);<BR>my $handle = unpack("L", $ptr);<BR>$api = new Win32::API("the.dll", "function2", ["N", "P"], ["N"]);<BR>$ptr = pack("A*", "string");<BR>my $res = $api->Call($handle, $ptr);<BR>...</DIV>
<DIV>However, I wanted to simplify the calls I need so I put everything in a<BR>module nice and neat(I have created successful modules before, no problem).<BR>But now, after I call the initial method to get a handle, subsequent calls<BR>to other functions, via other methods that call them, don't like that<BR>handle! But, it works *if* the method that<BR>creates the initial handle also calls another method that needs that handle!<BR>This made me think that perhaps the memory location for the handle(in Perl)<BR>was changing with method calls, which I thought might upset the API module.<BR>Nope. When I print it out i.e. print(\$handle); it is always the same hex<BR>value, in whatever method I call! I made sure the handle var is *not* part<BR>of the blessed data so there can't be something going on with $self(as that<BR>memory location does change with method calls). I'm really at a loss to<BR>understand why my calls to Win32::API fail when the value stored in the<BR>handle vari!
able and it's memory location are obviously the same between<BR>methods but it seems certain that *something* is changing after the initial<BR>method is called and before the next one is, at least in my case. Does<BR>anyone have any ideas? Here is a link to the module I made:</DIV>
<DIV> </DIV>
<DIV><A href="http://www.mohawk.net/~stuart/Zp4.pm.txt">http://www.mohawk.net/~stuart/Zp4.pm.txt</A></DIV>
<DIV> </DIV>
<DIV>kinda messy with debugging stuff in it - sorry. Thanks to anyone who can<BR>figure out or has any ideas as to what might be messing me up here!</DIV>
<DIV> </DIV>
<DIV>-Rich<BR></DIV>
<DIV> </DIV>
<DIV> </DIV><br clear=all><hr>Get your FREE download of MSN Explorer at <a href="http://explorer.msn.com">http://explorer.msn.com</a><br></p></html>
--
Posted from [63.66.71.66] by way of f43.law11.hotmail.com [64.4.17.43]
via Mailgate.ORG Server - http://www.Mailgate.ORG
------------------------------
Date: 8 May 2001 20:28:38 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: redirect to a url & avoiding hacks
Message-Id: <9d9ktm$h8v00$2@fu-berlin.de>
Keith G <gasper@cis.ohio-state.edu> wrote:
> Sorry to have put everyone into a tizzy! I figured
> out the easiest way to do it was to avoid using
> Perl to do the redirection and to instead do this:
> .......
> print "<script>location.replace(\"http://mypage.com\");</script>\n";
> .......
i wouldn't do that. what happens to users with javascript
switched off?
please, print at least an extra link for those users.
it's frustrating to surf without javascript and then realizing that
a form or link doesn't work because it's javascript only.
and then a simple thing like a redirect...
but that's offtopic now...
> This seems to work just fine. I'd love to respond
> to godzilla's knock about being a 'copy and paste
> baby' or needing to 'learn how to program,' but
> i've got more important things to concentrate on.
that's right, me too. i should killfile her again, but
maybe longer than 28 days this time.
regards,
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx
------------------------------
Date: Tue, 8 May 2001 17:39:54 -0400
From: Neal Weissman <nweissma@mathlab.sunysb.edu>
Subject: Seeking a PERL Tutorial
Message-Id: <Pine.GSO.4.05.10105081730411.16383-100000@SunRa.mathlab.sunysb.edu>
Please recommend a PERL tutorial.
Thanks.
--neal weissman
------------------------------
Date: Wed, 9 May 2001 00:07:05 +0100
From: "Martijn Mulder" <soso@open.net>
Subject: Re: Seeking a PERL Tutorial
Message-Id: <9d9qh2$p14$1@nereid.worldonline.nl>
Neal Weissman wrote:
> Please recommend a PERL tutorial.
Learning Perl by Randal Schwartz, published
by O'Reilly & Associates. Also other books
from the same publisher on Perl.
Also, see the the Perl FAQ
------------------------------
Date: Tue, 08 May 2001 21:37:04 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sort String
Message-Id: <x78zk7cyjm.fsf@home.sysarch.com>
>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:
RLS> So for me, I teach:
RLS> split /..../ when you know what you want to toss
RLS> /(....)/g when you know what you want to keep
that makes perfect sense to teach it that way.
RLS> and never use split /(....)/.
well, not until you know why you need to use it. i have rarely used it
but it has a use nonetheless. sometimes you want to keep the fields and
their delims (which could be odd and not just fixed strings).
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Tue, 8 May 2001 14:54:45 -0500
From: "Jim F" <jimbob4334@deja.com>
Subject: Take out lines that are flagged
Message-Id: <9d9iu6$ost12@nntp.cig.mot.com>
Hi,
I have a file that has many fields in it. The first field is the unique id
for the record. ($id)
There is field called $flagged, if there is a value in flagged, I want to
remove the record of data that has the matching $if.
I want to be able to go through the file and grab all the $flagged values
then go through a second time and remove those where $id matches $flagged.
File is tab seperated, so I use split to load it into variables for each
line then dump it into a pipe seperated file.
What is the best way to remove the flagged $id ???
open(INSP_FILE, "$inspection_data_file") || die "$inspection_data_file
cannot be opened\n";
@prs = <INSP_FILE>;
foreach $ln (@prs)
{
if ((!/""/) && (!/^Feature/)) #skip blank lines and header
{
chomp $ln;
($id,$flagged,$Total_Faults,$Source_Schema) =
split(/\t/,$ln);
$new_data5 .= "$id|$Total_Faults|$Source_Schema\n";
}
}
close(INSP_FILE);
open(OUTPUT1, ">> $output1") || die "$output1 cannot be opened\n";
print OUTPUT1 $new_data5;
------------------------------
Date: Tue, 08 May 2001 21:51:40 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Take out lines that are flagged
Message-Id: <3AF86A67.F7ACF77A@acm.org>
Jim F wrote:
>
> Hi,
>
> I have a file that has many fields in it. The first field is the unique id
> for the record. ($id)
>
> There is field called $flagged, if there is a value in flagged, I want to
> remove the record of data that has the matching $if.
There is no variable $if in the supplied code. Perhaps you mean $id?
> I want to be able to go through the file and grab all the $flagged values
> then go through a second time and remove those where $id matches $flagged.
Can $id match any $flagged or only the one in the same record?
> File is tab seperated, so I use split to load it into variables for each
> line then dump it into a pipe seperated file.
>
> What is the best way to remove the flagged $id ???
>
> open(INSP_FILE, "$inspection_data_file") || die "$inspection_data_file
> cannot be opened\n";
You should include the $! variable in your error message.
> @prs = <INSP_FILE>;
> foreach $ln (@prs)
You're only using @prs once, why not just:
while ( my $ln = <INSP_FILE> )
> {
> if ((!/""/) && (!/^Feature/)) #skip blank lines and header
Your regular expressions are bound to the $_ variable but the current
line is in $ln so they aren't doing anything useful. Also /""/ does not
match a blank line, it matches two quote marks anywhere in the line.
if ( $ln !~ /^\s*$/ and $ln !~ /^Feature/ )
> {
> chomp $ln;
> ($id,$flagged,$Total_Faults,$Source_Schema) =
> split(/\t/,$ln);
> $new_data5 .= "$id|$Total_Faults|$Source_Schema\n";
> }
>
> }
> close(INSP_FILE);
> open(OUTPUT1, ">> $output1") || die "$output1 cannot be opened\n";
> print OUTPUT1 $new_data5;
Here you are only writing out the last line of the input file. Nowhere
do you do any comparisons of $id or $flagged so it's hard to tell what
you are trying to accomplish.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 8 May 2001 20:13:22 GMT
From: Ilya Zakharevich <ilya@math.ohio-state.edu>
Subject: Re: unicode support in perl 5.6 -- I'm trying to get it to work l
Message-Id: <9d9k12$gvp$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Eike Grote
<eike.grote@epost.de>], who wrote in article <3AF7A69E.AE5CA0CB@fmis.de>:
> use utf8;
>
> @c = (chr(0x00e0), chr(0x00e1), chr(0xddc0));
>
> print join("",@c[0,1]),"\n";
> print join("",@c[0,2]),"\n";
>
> Output:
>
> àá
> Ã í·
>
> (In case the data is scrambled by the mail program: the first
> two characters by themselves are printed fine, but as soon as I
> add "0xddc0" the output is completely different to the case
> without "0xddc0" at the end.)
Why do you consider this behaviour broken? Your script is broken,
this is right. The Perl's behaviour is just "making the best of the
bad code".
In which encoding you want the strings to be print()ed? You did not
specify the wanted encoding on STDOUT. So perl is not trying to
second-guess you, and just dumps the internal representation.
[I do not know how to set I/O encodings, and whether it is possible at
all. Perl's Unicode I/O *may* be unfinished, but the processing
*while in Perl* should be pretty good nowadays.]
Ilya
------------------------------
Date: 8 May 2001 21:59:25 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: unicode support in perl 5.6 -- I'm trying to get it to work l
Message-Id: <eli$0105081742@qz.little-neck.ny.us>
In comp.lang.perl.misc, Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> Eike Grote <eike.grote@epost.de>], wrote:
> > use utf8;
> > @c = (chr(0x00e0), chr(0x00e1), chr(0xddc0));
> > print join("",@c[0,1]),"\n";
> > print join("",@c[0,2]),"\n";
> > Output:
> > àá
> > Ã í·
> >
> > (In case the data is scrambled by the mail program: the first
> > two characters by themselves are printed fine, but as soon as I
> > add "0xddc0" the output is completely different to the case
> > without "0xddc0" at the end.)
What is U+DDC0 anyway?
> Why do you consider this behaviour broken? Your script is broken,
> this is right. The Perl's behaviour is just "making the best of the
> bad code".
>
> In which encoding you want the strings to be print()ed? You did not
> specify the wanted encoding on STDOUT. So perl is not trying to
> second-guess you, and just dumps the internal representation.
How does one specify the encoding for STDOUT? The stuff output does
not resemble UTF-8, but that could be my inexperience with UTF-8
showing.
> [I do not know how to set I/O encodings, and whether it is possible at
> all. Perl's Unicode I/O *may* be unfinished, but the processing
> *while in Perl* should be pretty good nowadays.]
I can prove this wonderful theorem, but I have not way of writing
down the proof?
Here's another weird UTF-8 thing in perl:
#!/usr/bin/perl -w
use strict;
require 5.006;
use vars qw( $chr1 $chr2 @oct $oct $len $isutf8 $same );
use charnames qw( :full ); # comes with perl 5.6.0
use Convert::Scalar qw( :utf8 );
# \N{name} is a feature of the charnames module.
$chr1 = "\N{LATIN CAPITAL LETTER J}\N{SKULL AND CROSSBONES}";
@oct = $chr1 =~ /(.)/g;
$len = length($chr1);
$oct = @oct;
$isutf8 = (utf8 $chr1)? "yes" : "no";
print "CHR 1: $oct bytes, $len chars, in <$chr1>; is utf8? $isutf8\n";
$chr2 = "J☠";
@oct = $chr2 =~ /(.)/g;
$len = length($chr2);
$oct = @oct;
$isutf8 = (utf8 $chr2)? "yes" : "no";
print "CHR 2: $oct bytes, $len chars, in <$chr2>; is utf8? $isutf8\n";
print "(<$chr1> cmp <$chr2>)";
$same = ($chr1 cmp $chr2)? "same" : "not same";
print " == $same\n";
print "But after cmp, they are now <$chr1> and <$chr2>\n";
__END__
:r! perl %
CHR 1: 4 bytes, 2 chars, in <J☠>; is utf8? yes
CHR 2: 4 bytes, 4 chars, in <J☠>; is utf8? no
(<J☠> cmp <J☠>) == same
But after cmp, they are now <J☠> and <J☠>
Why does using C<cmp> cause it to print differently?
Elijah
------
mentioned that output oddity in <eli$0104101434@qz.little-neck.ny.us>
------------------------------
Date: Tue, 8 May 2001 22:05:31 +0200
From: "carlos" <carlos@plant.student.utwente.nl>
Subject: Re: very big array
Message-Id: <9d9jbb$7c8$1@dinkel.civ.utwente.nl>
you call that big?
"T_Boss" <T_boss75@curanet.com> wrote in message
news:AmAI6.209879$lj4.6007255@news6.giganews.com...
> I need to compare to array's of 270 elements.
> I did it like this:
>
> foreach $mod (@tot_modem)
> foreach $f_mod (@array)
> last if $mod eq $f_mod;
> if ($f_mod eq $array[$#array])
>
> Is there an eazier way to do this, or maybe faster?.
>
> And how to create such big array, is there a way to continue on the next
> line without closing the array?
>
>
------------------------------
Date: Tue, 08 May 2001 14:04:29 -0400
From: Dave VP <me@my_no_spam.org>
Subject: Re: What would you do
Message-Id: <3AF8352D.BB8DD001@my_no_spam.org>
"Michael R. McPherson" wrote:
>
> I have a number of validations I need to run on some input. I have to test
> for correct length, as it needs to be a fixed size, and also need to test
> for appropriate format. Plus I need to "Murphy Proof" these tests as it can
> be a pain to fix the database if any of this input is committed to the
> database incorrectly. I also need to "yell" at the user should they input
> something incorrectly and let them know what they did wrong.
>
> So far I have come up with the following script but being a newbie at this I
> would love to see some variations that may be more efficient at it.
>
> TYIA
>
> IMSI in a 310470XXXXXXXXX format (where X = digit) ;
> ISDN in a 1671788XXXX format (where X = digit) ;
>
> sub mode_preadd {
> my $imsi=$q->param('imsi');
> my $isdn=$q->param('isdn');
> print "<META HTTP-EQUIV=\"REFRESH\"
> CONTENT=\"1;URL=mproc.pl?mode=preaddtwo&imsi=$imsi&isdn=$isdn\">";
> print "Please stand by while I check to make sure that IMSI:<font
> color=red>$imsi</font> and ISDN:<font color=red>$isdn</font> are available";
>
> }
>
> sub mode_preaddtwo {
> #test imsi length
> my $imsi=$q->param('imsi');
> my $isdn=$q->param('isdn');
> my $imsil = length $imsi;
> if ($imsil < 15 || $imsil > 15 ){
> $MODEERR = "IMSI $imsi is either to short or long in length. 15
> Characters in 310470XXXXXXXXX format";
> mode_error($MODEERR);
> }else{
> mode_preaddthree($imsi, $isdn)
> }
> }
>
> sub mode_preaddthree {
> #test isdn length
> my ($imsi,$isdn)=@_;
> my $isdnl = length $isdn;
> if ($isdnl < 11 || $isdnl > 11 ){
> $MODEERR = "ISDN $isdn is either to short or long in length. Please
> use the 1671788XXXX format";
> mode_error($MODEERR);
> }else{
> mode_preaddfour($imsi, $isdn)
> }
> }
>
> sub mode_preaddfour {
> #test imsi format
> my ($imsi,$isdn)=@_;
> if ($imsi =~ /310470\d{9}/) {
> mode_preaddfive($imsi,$isdn);
> }else{
> $MODEERR = "IMSI $imsi is not in the correct format
> 310470XXXXXXXXX";
> mode_error($MODEERR);
> }
> }
>
> sub mode_preaddfive {
> #test isdn format
> my ($imsi,$isdn)=@_;
> if ($isdn =~ /1671788\d{4}/) {
> mode_preaddsix($imsi,$isdn);
> }else{
> $MODEERR = "ISDN $isdn is not in the correct format 1671788XXXX";
> mode_error($MODEERR);
> }
>
> }
>
> sub mode_preaddsix {
> print "OK";
> }
>
> sub mode_error {
> my $err = $_[0];
> print "<META HTTP-EQUIV=\"REFRESH\"
> CONTENT=\"3;URL=mproc.pl?mode=add\">";
> print "You have been rejected due to:<br> ";
> print "<font color=red>$err</font><br>";
> print "You will be redirected back in 3 seconds";
> }
Michael,
You've done fairly well. Some constructive criticism:
Why do you go to the trouble of specifically checking whether the
entered data is greater than (>) or less than (<) the target length?
What you are checking is inequality (!=). They achieve the same thing,
but inequality is clearer.
However, if you really want to be nice and report back length errors,
then you should tell the user exactly what is wrong with the input.
Your message, "ISDN $isdn is either to short or long in length"
^^^^^^
is not very helpful.
Your regex does most of the work. Add some anchors to it:
if($isdn =~ /^1671788\d{4}$/) {
#Process a good looking ISDN value
}
By adding the anchors, you know that the user has entered the correct
pattern, followed by the correct number of digits.
It would be better to check the "pattern" before the length. Imagine
the frustration a user would have re-entering the data several times to
get the length right, then finding out that the pattern was incorrect
from the start.
It would be nice to show the user just where the input is being
rejected. Modify your regexes to determine what matches, then
color-code the error message (with the <font color> directives),
pointing to the part of the string which doesn't match.
Now, you just need to verify that the value input is a valid ISDN, eh?
Good luck,
Dave
------------------------------
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 857
**************************************