[11094] in Perl-Users-Digest
Perl-Users Digest, Issue: 4694 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 19 22:05:27 1999
Date: Tue, 19 Jan 99 19:00:18 -0800
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, 19 Jan 1999 Volume: 8 Number: 4694
Today's topics:
A question about pack function <markn_nospam_@mincom.com>
Re: Binary and Hex number conversion scraig@my-dejanews.com
Re: Clueless Newbie..... <address@web.page>
Re: flock <collin.starkweather@colorado.edu>
Re: Help sought with complex extraction/report <javaprogrammer@Mindspring.com>
Re: How to determine time? (Larry Rosler)
Re: How to determine time? (Sam Holden)
Re: Is there a way to create self contained perl execut <markn_nospam_@mincom.com>
Re: location of the faq (was append to beginning) (I R A Aggie)
Re: MacPerl question (Paul J. Schinder)
Re: newbie - endless loop on simple program. <henk@crash.nu>
Perl Password Hiding Challenge jbharvey@auspex.net
Re: Perl Password Hiding Challenge <kprice@cardinal.co.nz>
Re: Perl Password Hiding Challenge <kprice@cardinal.co.nz>
Re: Perl Password Hiding Challenge <spam.me@idea.co.uk>
Re: Perl Password Hiding Challenge (Martien Verbruggen)
perlcc in 500502 <arolfe@genome.wi.mit.edu>
Re: Problem compiling Perl 5.004... <jnath@us.oracle.com>
Re: problem with: use module; (Fluffy)
Re: Remove all %0A's from string??? <baliga@synopsys.com>
Re: text indexes from lists (Martien Verbruggen)
Re: variable scoping question <baliga@synopsys.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 20 Jan 1999 09:26:31 +0800
From: "Mark Nold" <markn_nospam_@mincom.com>
Subject: A question about pack function
Message-Id: <783g38$3mq$1@pithy.mincom.oz.au>
Hi,
As per the FAQ "How do I convert bits into ints?" im trying to convert a
binary string to a decimal. Perl only returns a strange character (i assume
the ascii representation of the binary????). My complete two line script is
below;
$decimal = pack('B8', '10110110');
print $decimal, "\n";
Any help is appreciated.
Thanks.
------------------------------
Date: Wed, 20 Jan 1999 01:30:36 GMT
From: scraig@my-dejanews.com
Subject: Re: Binary and Hex number conversion
Message-Id: <783bjs$2mi$1@nnrp1.dejanews.com>
In article <780n9g$p40$1@pithy.mincom.oz.au>,
"Mark Nold" <markn_nospam_@mincom.com> wrote:
> Hi i want to easily convert fractional binary numbers to decimal.
> For example, the number 0000000000003e40 is in fact 30.
You described the standard IEEE double precision floating point
representation.
This works for the endian order on my machine:
perl -e 'print unpack d, pack H16, sprintf "%016x", 0x3e40'
If the string is already formatted to be 16 characters long, then the sprintf
part wouldn't be necessary.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 19 Jan 1999 18:02:33 PST
From: "Phlip" <address@web.page>
Subject: Re: Clueless Newbie.....
Message-Id: <783dfp$ick@journal.concentric.net>
Glyn escribis:
>$mypic[1]="/bannerimages/test/banner3.gif WIDTH=400 HEIGHT=40";
...
>print "<A HREF=\"$myurl[$pick]\"> <IMG SRC=$mypic[$pick]></A>";
...
>What am I doing wrong??? When I go to the URL
>"http://www.hernandocountyrealty.com/airports/page.shtml" it trys to
load
>the graphic, but just dosn't seem to do it......
When you hit your browser's View Source feature what does it reveal
that all your 'print's outputted?
(More exigently, what happens when you run that source thru an HTML
Validation program?)
But I think you'd get this:
<IMG SRC=/bannerimages/test/banner3.gif WIDTH=400 HEIGHT=40>
That has illegal things in the 'SRC' prop - the value has no "" around
it. The _browser_ now must either "forgive" you and request the entire
string as a GIF file, or give up somewhere around the first /.
Different browsers forgive in different ways.
Add \" markers around the file name and you should get stable.
--
Phlip at politizen dot com (address munged)
======= http://users.deltanet.com/~tegan/home.html =======
-- All sensors report Patti having a very good time --
------------------------------
Date: Tue, 19 Jan 1999 18:56:25 -0700
From: Collin Starkweather <collin.starkweather@colorado.edu>
To: "M. Morgan" <mmorgan@gladstone.uoregon.edu>
Subject: Re: flock
Message-Id: <36A537C9.12BF@colorado.edu>
The 2 (the LOCK_EX constant) requests an exclusive lock (noone else
should be able to access it). 8 (the LOCK_UN constant) unlocks the
file. 1 requests a shared lock (the LOCK_SH constant) (truthfully, I
don't know what this is all about).
If you add 4 to any of the above (the LOCK_NB constant) , then flock
will return a value immediately that tells you whether the file is
already locked by another process. Otherwise, the process will hang out
until the cows come home waiting for the other process to give up the
lock if the other process doesn't terminate and doesn't unlock the file
(with 8). I usually wrap a loop around an flock(FILEHANDLE,6) (6=2+4)
with a sleep 1 command that will give an error if the file isn't freed
up in an adequate amount of time.
I hope this answers some of your question.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Collin Starkweather (303) 492-4784
University of Colorado collin.starkweather@colorado.edu
Department of Economics http://ucsu.colorado.edu/~olsonco
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
M. Morgan wrote:
>
> Anyone here know about flock?
>
> In the case of a HTML guestbook, it will prevent any errors that might
> happen if two people try to write to the
> guestbook at the same time. For example:
>
> open(LOG, ">>logfile.txt") || die "an error occured";
> flock(LOG,2);
> print LOG $comments;
> flock(LOG,8);
> close(LOG);
>
> I do not know the reason behind the 2 and 8, but I know that flock(FILE,2);
> begins the flock and flock(FILE,8); ends the flock.
> My question is if I have two files that need to be written to are both safe
> with flock if I do the following:
>
> open(LOG, ">>logfile.txt") || die "an error occured";
> flock(LOG,2);
> print LOG $comments;
> flock(LOG,8);
> close(LOG);
>
> open(DATA, ">>datafile.txt") || die "an error occured";
> flock(DATA,2);
> print DATA $comments;
> flock(DATA,8);
> close(DATA);
>
> Or do I need to do this:
>
> open(LOG, ">>logfile.txt") || die "an error occured";
> flock(LOG,2);
> print LOG $comments;
>
> open(DATA, ">>datafile.txt") || die "an error occured";
> flock(DATA,2);
> print DATA $comments;
> flock(DATA,8);
> close(DATA);
>
> flock(LOG,8);
> close(LOG);
>
> Or would one file close as soon as I open another one? Can you offer any
> help on this?
>
> -Mike Morgan
------------------------------
Date: Tue, 19 Jan 1999 19:03:39 -0600
From: "d.k. henderson" <javaprogrammer@Mindspring.com>
Subject: Re: Help sought with complex extraction/report
Message-Id: <783a3d$d8k$1@camel21.mindspring.com>
So is this a Perl application?
One thing that stood out to me and I am not a chess programmer is that you
have to validate which piece is being moved,i.e., the King's knight or
Queen's knight.
------------------------------
Date: Tue, 19 Jan 1999 17:09:50 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How to determine time?
Message-Id: <MPG.110eccbbfc7f01ca9899a9@nntp.hpl.hp.com>
In article <slrn7aa7o8.mma.sholden@pgrad.cs.usyd.edu.au> on 20 Jan 1999
00:10:48 GMT, Sam Holden <sholden@pgrad.cs.usyd.edu.au> says...
> On Tue, 19 Jan 1999 13:39:03 -0600, Michael Kangas <kangas@anlon.com> wrote:
> >($s,$m,$h,$d,$mo,$yr,$wk,$yd,$i) = localtime(time);
> >
> >print "seconds: $s\n";
> >print "minutes: $m\n";
> >print "hour: $h\n";
> >print "day of month: $d\n";
> >print "month: $mo\n";
> >print "year: $yr\n";
> >print "weekday: $wk\n";
> >print "Day of Year: $yd\n";
> >print "isdst: $i\n";
>
> Or maybe just print scalar localtime;
Because in that case the off-by-one-month and off-by-1900-years bugs in
the above code will be dealt with correctly.
:-)
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 20 Jan 1999 01:38:40 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: How to determine time?
Message-Id: <slrn7aact0.opk.sholden@pgrad.cs.usyd.edu.au>
On Tue, 19 Jan 1999 17:09:50 -0800, Larry Rosler <lr@hpl.hp.com> wrote:
>In article <slrn7aa7o8.mma.sholden@pgrad.cs.usyd.edu.au> on 20 Jan 1999
>00:10:48 GMT, Sam Holden <sholden@pgrad.cs.usyd.edu.au> says...
>> On Tue, 19 Jan 1999 13:39:03 -0600, Michael Kangas <kangas@anlon.com> wrote:
>> >($s,$m,$h,$d,$mo,$yr,$wk,$yd,$i) = localtime(time);
>> >
>> >print "seconds: $s\n";
>> >print "minutes: $m\n";
>> >print "hour: $h\n";
>> >print "day of month: $d\n";
>> >print "month: $mo\n";
>> >print "year: $yr\n";
>> >print "weekday: $wk\n";
>> >print "Day of Year: $yd\n";
>> >print "isdst: $i\n";
>>
>> Or maybe just print scalar localtime;
>
>Because in that case the off-by-one-month and off-by-1900-years bugs in
>the above code will be dealt with correctly.
>
>:-)
If only I had actually read the code I could have made a much more scathing
comment... curses foiled again...
--
Sam
Simple rule: include files should never include include files.
--Rob Pike
------------------------------
Date: Wed, 20 Jan 1999 10:51:46 +0800
From: "Mark Nold" <markn_nospam_@mincom.com>
Subject: Re: Is there a way to create self contained perl executable?
Message-Id: <783g71$3nc$1@pithy.mincom.oz.au>
Try PERL2EXE (for WIN32 only) from activestate (www.activestate.com i think)
neilpaku wrote in message <36A64630.60D9@paradise.net.nz>...
>Hi all,
> I couldn't find in the faqs a solution to my problem. I would like to
>create a script that also contained the perl interpreter so that I could
>place this script on any machine and run it without having to install
>perl. Is this possible? The intended platform is nt. If it is possible,
>where can I find examples?
>Thanks for your time,
> Neil.
------------------------------
Date: Tue, 19 Jan 1999 21:02:10 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: location of the faq (was append to beginning)
Message-Id: <fl_aggie-1901992102100001@aggie.coaps.fsu.edu>
In article <36A52508.64D0DB18@OnlineRAGE.com>, "Ronnie D. Jewell"
<jewell@OnlineRAGE.com> wrote:
+ For future reference; where do I find a copy of the FAQ everyone
+ mentioned?
>From your handy-dandy unix command line:
perldoc perlfaq
Its included with every proper distribution of perl.
James
------------------------------
Date: 20 Jan 1999 01:57:47 GMT
From: schinder@leprss.gsfc.nasa.gov (Paul J. Schinder)
Subject: Re: MacPerl question
Message-Id: <783d6r$866$1@clarknet.clark.net>
In <182CBD3DCS86.PETER@yaleads.ycc.yale.edu> PETER@yaleads.ycc.yale.edu writes:
>Hi. Can someone tell me how to call a MacPerl script from within another
>MacPerl script?
Try using do or eval. See the docs for details.
------------------------------
Date: Wed, 20 Jan 1999 02:03:02 +0100
From: "Henk Slaaf" <henk@crash.nu>
Subject: Re: newbie - endless loop on simple program.
Message-Id: <783a6n$rpj$1@dinkel.civ.utwente.nl>
> REJ> This suggests to me that the issue is related to floating point.
> REJ> But my SAMS "Teach Yourself Perl in 21 Days" solves the problem a
>
>well 14 days have passed by andhave you learned 2/3 of perl? :-)
>
>get a better book. any by o'reilly and stay aways from any perl book
>with a time limit in its title.
Of course, I don't discuss that O Reilly ain't the best. But me myself has
bought this 21 days perl book at some market in Ney York and I am very
pleased with it. It does explain the difficulties abound floating point
numbers and comparisions.
------------------------------
Date: Wed, 20 Jan 1999 01:29:05 GMT
From: jbharvey@auspex.net
Subject: Perl Password Hiding Challenge
Message-Id: <783bgm$2k9$1@nnrp1.dejanews.com>
I have a question to pose to the upper echelons of the perl user community,
Say someone has coded a script to access a website or database and it is not
going to be run interactively. In order for the script to access said
website or database it must provide a username and password to the API of
it's choosing for the request, and since it's running from cron, you cannot
ask a user for a password. How do you securely store the user/pass in the
script or module? I don't think you can. Here are a few points:
1. You cannot stick the password in your script, since if someone cracks your
account or gains access to root, they now have an additional user/pass.
2. You cannot put the password in the module for the same reason, and modules
must be read-able to be used.
3. There is no use doing a 'chmod 700' because again root can see it.
Aside from "don't ever do this" responses, anyone have suggestions? Even
comments/hints on making it a little more inaccessable are helpful.
Justin
--
Justin B. Harvey
jbharvey@auspex.net
http://www.auspex.net/jbharvey
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 20 Jan 1999 15:12:40 +1300
From: Kelvin Price <kprice@cardinal.co.nz>
Subject: Re: Perl Password Hiding Challenge
Message-Id: <36A53B98.F6EC196C@cardinal.co.nz>
jbharvey@auspex.net wrote:
>
> I have a question to pose to the upper echelons of the perl user community,
>
> Say someone has coded a script to access a website or database and it is not
> going to be run interactively. In order for the script to access said
> website or database it must provide a username and password to the API of
> it's choosing for the request, and since it's running from cron, you cannot
> ask a user for a password. How do you securely store the user/pass in the
> script or module? I don't think you can. Here are a few points:
>
> 1. You cannot stick the password in your script, since if someone cracks your
> account or gains access to root, they now have an additional user/pass.
>
> 2. You cannot put the password in the module for the same reason, and modules
> must be read-able to be used.
>
> 3. There is no use doing a 'chmod 700' because again root can see it.
>
> Aside from "don't ever do this" responses, anyone have suggestions? Even
> comments/hints on making it a little more inaccessable are helpful.
>
> Justin
I wouldn't count myself as part of the Perl upper echelon, but I'm going
to answer anyway !
Encrypt the password within the script. Have fun, invent your own
encryption routine or use crypt. Here's a simple code fragment to
express the idea.
my $secret_code="drowssap";
print "Password = " . (reverse $secret_code) . "\n";
where you would replace the print statement with whatever submits the
password to the site.
HTH
Kelvin
------------------------------
Date: Wed, 20 Jan 1999 15:22:07 +1300
From: Kelvin Price <kprice@cardinal.co.nz>
Subject: Re: Perl Password Hiding Challenge
Message-Id: <36A53DCF.42FE00D3@cardinal.co.nz>
Doh !!
Just realised my answer still violates point 1.
But whatever the script does will be repeatable by whoever cracks your
account, so there probably isn't an answer.
------------------------------
Date: Wed, 20 Jan 1999 02:36:01 +0000
From: Kiril <spam.me@idea.co.uk>
Subject: Re: Perl Password Hiding Challenge
Message-Id: <36A54111.991931B7@idea.co.uk>
Kelvin Price wrote:
>
> jbharvey@auspex.net wrote:
<snip>
>
> Encrypt the password within the script. Have fun, invent your own
> encryption routine or use crypt. Here's a simple code fragment to
> express the idea.
>
> my $secret_code="drowssap";
> print "Password = " . (reverse $secret_code) . "\n";
>
> where you would replace the print statement with whatever submits the
> password to the site.
>
what's to stop ROOT (?) from copying the script, adding a PRINT
somewhere appropriate & looking at your password nicely
printed out ??????
Kiril
------------------------------
Date: Wed, 20 Jan 1999 02:46:40 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Perl Password Hiding Challenge
Message-Id: <ksbp2.203$7g1.6921@nsw.nnrp.telstra.net>
In article <783bgm$2k9$1@nnrp1.dejanews.com>,
jbharvey@auspex.net writes:
Because of the phrasing of the question, I am going to assume that
this is all about a Unix system.
> Say someone has coded a script to access a website or database and
> it is not going to be run interactively. In order for the script to
> access said website or database it must provide a username and
> password to the API of it's choosing for the request, and since it's
> running from cron, you cannot ask a user for a password. How do you
> securely store the user/pass in the script or module? I don't think
> you can. Here are a few points:
Most often this is done by having a file in a set directory (home or
so), which is only readable and writeable by owner.
> 1. You cannot stick the password in your script, since if someone
> cracks your account or gains access to root, they now have an
> additional user/pass.
>
> 2. You cannot put the password in the module for the same reason,
> and modules must be read-able to be used.
>
> 3. There is no use doing a 'chmod 700' because again root can see
> it.
You can't stop root from anything. Anything you can do, root can do.
You can't stop anyone who has hijacked your account. Anything you can
do, they can do.
Without user intervention (prompting for a password), there simply is
no way of distinguishing between you, or someone else logged in as
you. There is also no way of stopping root.
chmod 700 is the best protection you get on unix, I suppose. Together
with making access to your machine more secure and robust, that's as
good as it gets.
Encryption and decryption won't really work, since the decryption
stuff has to be readable again.
Anyone with a better idea?
> Aside from "don't ever do this" responses, anyone have suggestions?
It's up to you whether you want to run the risk of having stuff that's
only readable by you or not. It's up to you to trust the root person
at your place. If you don't trust root, and you can get away from
them, do that.
> Even comments/hints on making it a little more inaccessable are
> helpful.
obscurity may be a way to 'hide' it a little. If it isn't clear on
first sight where that password is coming from, it may take a cracker
too long to figure it out. Nothing failsafe as far as I know.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Tue, 19 Jan 1999 15:08:32 -0500
From: Alex Rolfe <arolfe@genome.wi.mit.edu>
Subject: perlcc in 500502
Message-Id: <36A4E640.41C6@genome.wi.mit.edu>
When trying to compile a very simple (hello world) program with
perl500502 (on digital unix 4.0), I get the following error message :
DynaLoader object version 1.00 does not match DynaLoader.pm $VERSION
1.03 at
/home/platinum/arolfe/perl/lib/5.00502/alpha-dec_osf-thread/DynaLoader.pm
line 80.
If I change the VERSION variable in DynaLoader.pm to 1.00, then it
complains that version 1.03 doesn't match ... 1.00! Any thoughts as to
how to fix this problem?
Thanks,
Alex Rolfe
arolfe@genome.wi.mit.edu
------------------------------
Date: Tue, 19 Jan 1999 16:45:41 -0800
From: Joydeep Nath <jnath@us.oracle.com>
Subject: Re: Problem compiling Perl 5.004...
Message-Id: <36A52734.9F17C6B0@us.oracle.com>
I also have the same problem; My sparc20 was also upgraded to 2.6. More info from
comp.lang.perl below:
Hi
I also got the same error while trying to compile using gcc. Using cc works fine.
Also got the same error "No DATAMODEL_NATIVE specified" while compiling
postgresSQL (gcc was used), so this may not be perl specific.
Tried to include appropriate header files to get around the problem, but started
getting other problems.
Will appreciate any help.
Thanks
joydeep
joe rice wrote:
> i'm trying to compile perl-5.005.02 on sparc/solaris-2.6 and i'm getting
> this error, could some one help?
>
> `sh cflags libperl.a miniperlmain.o` miniperlmain.c
> CCCMD = gcc -DPERL_CORE -c -I/usr/local/include -O
> In file included from perl.h:361,
> from miniperlmain.c:11:
>
/usr/local/encap/gcc-2.7.2/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2/include/sys/param.h:187:
> warning: `NBBY' redefined
> /usr/include/sys/select.h:45: warning: this is the location of the
> previous definition
> In file included from /usr/include/sys/stream.h:26,
> from /usr/include/netinet/in.h:38,
> from perl.h:517,
> from miniperlmain.c:11:
> /usr/include/sys/model.h:32: #error "No DATAMODEL_NATIVE specified"
> *** Error code 1
> make: Fatal error: Command failed for target `miniperlmain.o'
>
> thanks in advance,
> joe
Greg Ward wrote:
> ccboone@amber.indstate.edu <ccboone@amber.indstate.edu> wrote:
> > I am having difficulty compiling perl 5.004xx on a Solaris 2.6 machine. The
> > machine was upgraded from 2.5.1. The machine is also a sparc 20. I have
> > successfully compiled on a Ultra 10 running 2.6, but can not get the sparc 20
> > to compile it. I get a message about no memory model specified. I have never
> > had to specify a memory model before. Any ideas?? Please email me at
> > ccboone@amber.indstate.edu
>
> Maybe you should try a more recent version of Perl; 5.005 has been out
> since last summer, and the current maintenance release is 5.00502.
> You'll find it at
>
> http://www.perl.com/CPAN/src/5.0/perl5.005_02.tar.gz
>
> However, I don't think the build process changed much from 5.004 to
> 5.005 (at least not from the user's perspective). So you might have
> similar problems if you keep doing things the same way. Some things to
> consider:
>
> * did you start with a completely fresh distribution (ie. no
> old config.sh file)
> * did you run 'Configure' manually, answering all questions in
> a sensible way?
> * did 'Configure' give any errors or "WHOA THERE" messages that you
> brushed under the carpet?
>
> It might be helpful if you told us exactly what you did, and showed us
> the exact error message you're getting. But don't waste time with old
> versions: try again with perl 5.00502.
>
> Greg
> --
> Greg Ward - software developer gward@cnri.reston.va.us
> Corporation for National Research Initiatives
> 1895 Preston White Drive voice: +1-703-620-8990 x287
> Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: 20 Jan 1999 01:25:11 GMT
From: meowing@banet.net (Fluffy)
Subject: Re: problem with: use module;
Message-Id: <783b9n$rdo$1@meowhost.meow.invalid>
Julien 'Jay' Tane <jtane@etu.info.unicaen.fr> wrote:
>
> when I try : perl mainfile.pl
>
> it stops the compilation and prints:
> Module.pm did not return a true value at mainfile.pl
You forgot to meow. Add the following as the last line in Module.pm:
'meow';
and all will be well.
(Okay, any true statement will work, but meowing has so much more
panache than a simple 1. See the 'require' entry in perlfunc for an
explanation of what the meowing accomplishes. 'use' is a form of
'require', which is why the documentation may seem out of place.)
------------------------------
Date: Tue, 19 Jan 1999 17:16:02 -0800
From: Yogish Baliga <baliga@synopsys.com>
To: Ken Williams <tekkin@hotmail.com>
Subject: Re: Remove all %0A's from string???
Message-Id: <36A52E52.312692A9@synopsys.com>
$string =~ s/%0A//g;
-- Baliga
Ken Williams wrote:
> I have a string:
>
> %23+%0D%0A%23
>
> How do I get rid of all the "%0A"'s?
>
> I tried $string =~ tr/[%0A]//d;
>
> but it don't do what I want.
>
> Thanks.
------------------------------
Date: Wed, 20 Jan 1999 02:23:06 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: text indexes from lists
Message-Id: <e6bp2.183$7g1.6921@nsw.nnrp.telstra.net>
In article <7835l9$tgj$1@nnrp1.dejanews.com>,
sno@ais.org writes:
> I'm not as frequent a reader of this newsgroup as I should be, so
> if this is a lamer question, please point me in the right direction.
# perldoc perldata
# perldoc perlref
# perldoc perllol
# perldoc perldsc
> My desire is to have values in a regular array become a text key to
> positions in another array.
That is not exactly what you want. You seem to be wanting structured data.
> For example:
>
> @list_of_keys ('id', 'name', 'address', 'home phone', 'work phone');
>
> @list_of_arrays = (
> ['1', 'George', '333 Way Way', 'none', '555-5555'],
> ['2', 'Pattie', '123 Orchard', '555-5555', '555-5555'],
> ['3', 'Gary', '4444 Forest', '555-5555', '555-5555']
> );
because you really seem to be wanting to work with structured records,
I'll deal with that first, but see later on in the post for a probably
faster method if you don't want to change the data list you are
working with.
You can of course create a hash, with the keys and store that in the
array. Preferrably you would do this in the first place, instead of
building the above structure.
my @list_of_hashes;
foreach my $person (@list_of_arrays)
{
my %hash;
@hash{@list_of_keys} = @$person;
push @list_of_hashes, \%hash;
}
Each element of @list_of_hashes is now a hash reference to a person
hash.
In the case of highly structured data, like this, you probably want to
wrap all this in a module, and use blessed references to objects. It
just seems more appropriate that way.
If you don't want to deal with that, you could also consider using the
Class::Struct module. It's pretty handy for this sort of situation.
> I would like to be able to acquire a column of data from all lists using
> the key name by position value.
I guess that you just look through the array, getting each column
every time.
> So that conceptually:
>
> $list_of_arrays[$num]['id'] would always reference the zero'th list position
> of all records. 'name' would reference list position '1', etc.
for my $i (0 .. $#list_of_hashes)
{
print $list_of_hashes[$i]{'id'}, "\n";
}
Or... alternatively, you can just build a 'lookup' hash:
my %lookup;
@lookup{ @list_of_keys } = ( 0 .. $#list_of_keys );
my $wanted_el = $lookup{'id'};
for my $i (0 .. $#list_of_arrays)
{
print $list_of_arrays[$i][$wanted_el], "\n";
}
You can of course replace $wanted_el with $lookup{'id'}, but somehow
I suspect that that will be slightly less efficient (because it has to
look up the hash element on every run through the loop). It would need
benchmarking to make sure though.
> The caveat to this is that depending on the table, the list of keys might
> be different. Thus, for $list_of_another_array[] the table might be
> altogether different, while still using the same code to process the
> list.
Not really a problem. As long as the thing that builds the list of
hashes or the lookup hash and the stuff that displays it know the
list of keys, there shouldn't be a problem.
> Essentially, the desire is to reference a position with something
> like this:
>
> $list_of_arrays[$num]->[*keyname from alternate source*] without
> having to force a look-up compare loop for each call.
It can only be a keyname if you build a list of hashes. If you want to
keep the old list of arrays, and use a lookup hash, you'll need to use
a number, or something like $lookup_hash{'key_name'}. Whichever works
best for you.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Very funny Scotty, now beam down my
Commercial Dynamics Pty. Ltd. | clothes.
NSW, Australia |
------------------------------
Date: Tue, 19 Jan 1999 17:30:17 -0800
From: Yogish Baliga <baliga@synopsys.com>
To: Brian Lavender <blavender@spk.usace.army.mil>
Subject: Re: variable scoping question
Message-Id: <36A531A8.F33788A2@synopsys.com>
The variables defined in FORMAT are global variables. If they are defined with my
they become local to the
block and are visible in FORMAT.
--- Baliga
Brian Lavender wrote:
> I am having some difficulty with "my". I have a while loop which grabs a list
> array from an object. I print the data using a format. In the "First
> Instance" I assign the variables which get sent to the format statement with
> "my". In the "Second Instance" I do not. The "Second Instance" works while
> the "First Instance" does not. The "First Instance" output from the write is
> blank. Why is this?
>
> brian
>
> First Instance
> ---------------
> while (my @row_ary = $sth->fetchrow_array) {
> my ($coemis, $wi_code,$sum_atp_amt,$sum_paid_amt) = @row_ary;
> # notice the my above
> $woruntotob += $sum_atp_amt; $woruntotpd += $sum_paid_amt;
> $~ = ACCOUNTS;
> write;
> }
>
> Second Instance
> ---------------
> while (my @row_ary = $sth->fetchrow_array) {
> ($coemis, $wi_code,$sum_atp_amt,$sum_paid_amt) = @row_ary;
> # notice the lack of my
> $woruntotob += $sum_atp_amt; $woruntotpd += $sum_paid_amt;
> $~ = ACCOUNTS;
> write;
> }
>
> format ACCOUNTS = @<<<<<<<<<<<<<<<<< @<<<<<<< @>>>>>>>>>> @>>>>>>>>>>
> @>>>>>>>>>> ___________ __________ __________ _____________ __________
> $coemis, $wi_code,$sum_atp_amt,$sum_paid_amt, $sum_atp_amt-$sum_paid_amt .
>
> Brian E. Lavender
> US Army Corps of Engineers -- Programmer / Systems Analyst
> Sacramento, CA (916) 557-6623
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 4694
**************************************