[13932] in Perl-Users-Digest
Perl-Users Digest, Issue: 1342 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 10 18:05:56 1999
Date: Wed, 10 Nov 1999 15:05:20 -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: <942275120-v9-i1342@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 10 Nov 1999 Volume: 9 Number: 1342
Today's topics:
Absolute path <andrv@yesic.com>
ActivePerl from a network drive? cs2400@my-deja.com
Re: Batch Program Execution <cassell@mail.cor.epa.gov>
Re: calling my own modules (Kragen Sitaker)
Re: Can perl access COM port?? <cassell@mail.cor.epa.gov>
Re: command line args to "perl" (Tad McClellan)
Re: Don't know how to grep ... help! (David H. Adler)
Re: Don't know how to grep ... help! (Tad McClellan)
Re: FAQ 5.19: I still don't get locking. I just want t (Kragen Sitaker)
Re: Form that writes to file, emails, sends attachments <cassell@mail.cor.epa.gov>
Re: Function that can change it's parameter raju_k@iname.com
Re: Function that can change it's parameter (Tad McClellan)
Re: grep problem (Greg Bacon)
Has anybody tried making Active Server Pages (IIS 4.0) <cbeaver@shl.com>
Image type conversion??? <darrell.r.hougenNOdaSPAM@lmco.com.invalid>
Re: Is $$variable allowed like in PHP ? (David H. Adler)
Re: It is always like this here? <gellyfish@gellyfish.com>
Re: list (array) programming question <cassell@mail.cor.epa.gov>
LWP for retrieving web file data? <a.r.mccoy@larc.nasa.gov>
Re: LWP for retrieving web file data? (Martien Verbruggen)
Module File:Find problem <zeng@stat.Berkeley.EDU>
Re: New Perl and CGI Resource site <cassell@mail.cor.epa.gov>
NEWBIE WHO Please requires help with hashes PLEASE <JSH@cs.stir.ac.uk>
Re: NEWBIE WHO Please requires help with hashes PLEASE <AgitatorsBand@yahoo.com>
Re: OO question again (Kragen Sitaker)
Re: perl & permission <cassell@mail.cor.epa.gov>
perl + AI <ampanman@bigfoot.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 10 Nov 1999 16:36:10 +0300
From: "Andrei Rjeousski" <andrv@yesic.com>
Subject: Absolute path
Message-Id: <FxlW3.15$_15.337@news2.randori.com>
is it possible to find absolute path of the directory without asking the
administrator?
------------------------------
Date: Wed, 10 Nov 1999 20:45:15 GMT
From: cs2400@my-deja.com
Subject: ActivePerl from a network drive?
Message-Id: <80clgp$ei7$1@nnrp1.deja.com>
hello,
At the school i attend, Perl 4 is installed on a
"network drive" (U:\) that has a number of
utilities on it, you can get to perl by typing
"perl" at the command prompt since all workstation
have the U: drive in their PATH.
As it is now, Perl 4 is just a single binary file
at the root of the U: drive. There are no perl
directory.
I would like to ask the network admin to upgrade
to Perl 5. But that would require "U:\perl\bin" to
by added to the PATH of all machines.
So my question is, can ActivePerl be installed
like so:
A few perl files at the root...
U:\perl.exe
U:\perldoc.bat
U:\ppm.bat
*all* other perl files in a subdirectory...
U:\perl\whatever\...
Thanks,
:-)
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 10 Nov 1999 14:21:56 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Batch Program Execution
Message-Id: <3829F004.461AE425@mail.cor.epa.gov>
Vijay N Rao wrote:
>
> Yes David, you are right. I don't need a contionous connection. I need to do FTP
> only frequently. I tried Net::FTP but that works only in unix environment. I am
> using perl on win95.
> Now can you tell me how can I do this?
Ummm, are you sure? ActiveState supplies Net::FTP for all the
win32 platforms. It comes in the libnet bundle. Try some code
like that for your unix environment, and see how it goes.
Just don't try to use fork() also. Or flock(). They don't
run on win95.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 10 Nov 1999 20:04:35 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: calling my own modules
Message-Id: <ndkW3.64691$23.2536623@typ11.nn.bcandid.com>
In article <3829AF4B.E66753E7@ccrs.nrcanDOTgc.ca>,
Tom Kralidis <tom.kralidis@ccrs.nrcanDOTgc.ca> wrote:
>How can I call my own modules, in cases where I do not want them in the
>default lib?
perldoc -q own says:
=head1 Found in /usr/local/lib/perl5/5.00503/pod/perlfaq8.pod
=head2 How do I keep my own module/library directory?
When you build modules, use the PREFIX option when generating
Makefiles:
perl Makefile.PL PREFIX=/u/mydir/perl
then either set the PERL5LIB environment variable before you run
scripts that use the modules/libraries (see L<perlrun>) or say
use lib '/u/mydir/perl';
This is almost the same as:
BEGIN {
unshift(@INC, '/u/mydir/perl');
}
except that the lib module checks for machine-dependent subdirectories.
See Perl's L<lib> for more information.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 10 Nov 1999 14:27:32 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Can perl access COM port??
Message-Id: <3829F154.101D5BFE@mail.cor.epa.gov>
Calvin wrote:
>
> Hi,
> Just a quick question to see i want to use perl in my college project or
> not. Can perl access the COM port and send signals through it???
[1] yes
[2] it's a FAQ
[3] get Win32::SerialPort by Bill Birthisel
[4] if TomC wasn't blocking out all aol.com addresses, he
might have this patched in the FAQ by now. Poor Bill...
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 10 Nov 1999 10:34:46 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: command line args to "perl"
Message-Id: <slrn82j44m.s71.tadmc@magna.metronet.com>
On Tue, 09 Nov 1999 22:44:46, Seshadri Sriperumbudur
<seshadri9@worldnet.att.net> wrote:
>Where can I find more about all the command line args to "perl"; I mean,
>
>shell % perl -p -i -e ....
perldoc perlrun
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 10 Nov 1999 15:03:50 -0500
From: dha@panix.com (David H. Adler)
Subject: Re: Don't know how to grep ... help!
Message-Id: <slrn82jjt5.5av.dha@panix.com>
On Wed, 10 Nov 1999 11:34:57 -0500, Mark E. Drummond
<drummond-m@rmc.ca> wrote:
>Hi all. Tring to use perl's built in grep to search some emails for a
>particular "to" or "cc". Here's my, wrong, code:
I hate to be the one to point this out to you, but you aren't. You
don't use grep anywhere in your code.
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Your pluck is admirable. However, arguing for a 'pure computer
science' approach in the perl5-porters mailing list is somewhat like
inquiring about mileage in a Maserati dealership. People are given to
drop their champagne glasses and stare. - Felix Gallo, p5p
------------------------------
Date: Wed, 10 Nov 1999 10:20:41 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Don't know how to grep ... help!
Message-Id: <slrn82j3a9.s5h.tadmc@magna.metronet.com>
On Wed, 10 Nov 1999 11:34:57 -0500, Mark E. Drummond <drummond-m@rmc.ca> wrote:
>Hi all. Tring to use perl's built in grep to search some emails for a
^^^^^^^^^^^^^^^^^^^^
Where are you trying that?
Not in any code that you have shown us...
>particular "to" or "cc". Here's my, wrong, code:
>
>#!/usr/bin/perl -w
warnings enabled, good!
you should have a 'use strict;' pragma right about here though...
>opendir(SINGLE,"/var/mail/mailbox/.s0000") ||
> die "Could not open single copy store volume: $!";
checked return value, very good!
using double quotes when single quotes will do, bad!
>chdir "/var/mail/mailbox/.s0000";
no check of return value, bad!
using double quotes when single quotes will do, bad!
chdir '/var/mail/mailbox/.s0000' or die "could not chdir() $!";
># I specify on the command line the number of days "old" for
># the find command's -ctime value (below).
>($old) = @ARGV;
you can do the same thing with less visual clutter:
my $old = shift;
>foreach (sort readdir(SINGLE)) {
># for each dir we want to see if a message is a) directed
># to staff or student master and b) if it is older than
># $old days.
> next if ($_ =~ /^\./);
you can do the same thing with less visual clutter:
next if /^\./;
> chdir $_;
no check of return value, bad!
> print "Processing $_:\n";
> open (FIND,"/usr/bin/find . -name \".blk\" -prune -o -name
>\"__*__\" -prune -o -ctime +$old -print|") ||
you can do the same thing with less visual clutter:
#UNTESTED, look ma, no backslashes!
open (FIND, '/usr/bin/find . -name ".blk" -prune -o ' .
qq/-name "__*__" -prune -o -ctime +$old -print|/) ||
> die "Could not open pipe from find: $!";
You should also have a look at the Perl FAQ, part 8:
"Why doesn't open() return an error when a pipe open fails?"
> while (<FIND>) {
> if (/(staff|student)\.master/i) { print };
> }
> chdir "..";
no check of return value, bad!
>}
>But this ain't working.
What does that mean?
Does not find enough matches?
Finds too many matches?
Finds the wrong matches?
Program hangs?
Dumps core?
Finds the right ones along with some wrong ones?
...
???
> I figure my regex is wrong but I can't see how.
>Any ideas?
Check your return values. Maybe you aren't in the directory
that you think you are in, the pattern match looks OK to me...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 10 Nov 1999 20:16:16 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: FAQ 5.19: I still don't get locking. I just want to increment the number in the file. How can I do this?
Message-Id: <kokW3.64727$23.2538700@typ11.nn.bcandid.com>
In article <38293fdc@cs.colorado.edu>,
Tom Christiansen <perlfaq-suggestions@perl.com> wrote:
>(This excerpt from perlfaq5 - Files and Formats
> ($Revision: 1.38 $, $Date: 1999/05/23 16:08:30 $)
>
> I still don't get locking. I just want to increment the number in the file. How
>can I do this?
>
> (print FH $num+1, "\n") or die "can't write numfile: $!";
> # Perl as of 5.004 automatically flushes before unlocking
> flock(FH, LOCK_UN) or die "can't flock numfile: $!";
> close FH or die "can't close numfile: $!";
Why are we explicitly unlocking before we close? This should be explained.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 10 Nov 1999 14:53:03 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Form that writes to file, emails, sends attachments
Message-Id: <3829F74F.B36A055B@mail.cor.epa.gov>
Jacky Childs wrote:
>
> Greetings:
>
> As the subject states, I need a form that writes to file, emails, and
> can send file attachments. Two out of three would be good.
Umm, this newsgroup is really targeted at writing Perl code,
and helping people debug Perl code. If you just want a
Perl program, you'd do a lot better to go to some search
engine like Yahoo and search for a few keywords like Perl,
CGI, form, mail, etc. But the CGI formmail Perl scripts I
have seen on the web are dreck. I wouldn't use them unless
I *wanted* to permit major security holes and other bad
things.
But this is something you could write in Perl yourself
if you took a couple weeks to learn a little Perl. Try
reading "Elements of Programming with Perl" by Andrew
Johnson. Then you should be ready to write this. Use
the CGI.pm module to handle the parsing of the form;
open() and print() to write to files; Mail::Mailer or
Mail::Sender to fire off the e-mail; and MIME::Lite
to handle any attachments.
> Am I looking for miracles?
No. If you can't do it in Perl, you probably didn't
need to do it in the first place. :-)
> Does such a thing exist?
Perhaps not in a freely-available spot on the web.. yet.
> Does a partial thing exist?
See my comments above.
Good luck,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 10 Nov 1999 19:00:47 GMT
From: raju_k@iname.com
Subject: Re: Function that can change it's parameter
Message-Id: <80cfcu$9hs$1@nnrp1.deja.com>
ryanngi@hotmail.com (Ryan Ngi) wrote:
>
> the return style function make my code more spagehttier,
>
> how to implement a function that can change it's parameter variables,
> for example chop, shift, etc.?
>
> --- in C ,we can pass the pointer variable so we can do that job ,but
> perl we can't, is it possible?
>
If i understand you correctly, you want to pass a variable by
reference. Have a look at the perlref man pages, here's an example that
might help.
--raju
my $foo = "foobar";
print "Before: ", $foo, "\n";
doit(\$foo);
print "After: ", $foo, "\n";
sub
doit {
my $arg = shift;
$$arg =~ s/bar//;
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 10 Nov 1999 10:26:00 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Function that can change it's parameter
Message-Id: <slrn82j3k8.s5h.tadmc@magna.metronet.com>
On Wed, 10 Nov 1999 16:58:58 GMT, Ryan Ngi <ryanngi@hotmail.com> wrote:
>
>the return style function make my code more spagehttier,
>
>how to implement a function that can change it's parameter variables,
>for example chop, shift, etc.?
>
>--- in C ,we can pass the pointer variable so we can do that job ,but
>perl we can't, is it possible?
Yes.
--------------
#!/usr/bin/perl -w
use strict;
my $foo = 'bar';
print "$foo\n";
add_stars($foo);
print "$foo\n";
sub add_stars {
$_[0] = "***$_[0]***";
}
--------------
Subroutines (functions) are documented in the 'perlsub.pod'
man page.
The third paragraph there says how to do what you want to do.
Don't start up again with that "read the docs to me" shit that
you did a few months ago.
Use the docs Luke.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 10 Nov 1999 19:25:08 GMT
From: gbacon@ruby.itsc.uah.edu (Greg Bacon)
Subject: Re: grep problem
Message-Id: <80cgqk$qff$4@info2.uah.edu>
In article <80cf68$jkk@romeo.logica.co.uk>,
"Nobody" <nobody@logica.com> writes:
: I am using the following command in two versions of perl :
:
: $results = grep (!/^#/, $output);
:
: where $output is a string
What are you trying to do? $results is only going to be 0 or 1.
Why don't you just test the regular expression directly (and more
clearly) like
if ($output !~ /^#/) {
...;
}
else {
...;
}
: In perl 4 it runs but in perl 5 it doesn't seem to work ...
What do you mean? "Doesn't work" doesn't work well as a phrase to
describe a problem. :-) Please explain what you're trying to do, the
behavior you expected, the behavior you observed, and how that was
different from what you expected.
Greg
--
Isn't it a bit unnerving that doctors call what they do "practice"?
-- George Carlin
------------------------------
Date: Wed, 10 Nov 1999 17:18:20 -0500
From: "Chris Beaver" <cbeaver@shl.com>
Subject: Has anybody tried making Active Server Pages (IIS 4.0) in active Perl?
Message-Id: <80cr70$8eu$1@news.storm.ca>
Just looking for some feedback in regards to making IIS 4.0 Active Server
Pages with ActivePerl?
How does it compare with VBscript?
Any insight that anyone can provide would be greatly apprectiated.
cbeaver@shl.com
------------------------------
Date: Wed, 10 Nov 1999 13:18:47 -0800
From: Darrell <darrell.r.hougenNOdaSPAM@lmco.com.invalid>
Subject: Image type conversion???
Message-Id: <0a0133f8.5549bc62@usw-ex0101-006.remarq.com>
I am trying to find a perl module that performs image type conversion.
I scanned the CPAN site but couldn't find what I was looking for. In
particular, I'd like to be able to convert from pgm to jpg (but gif
output would be ok).
I'd like to find a standalone module that takes the name of the pgm and
jpg files as arguments so that I can embed the perl script in a loop
that converts a whole directory of images from one type to another.
I noticed a module that uses ImageMagick to perform the conversion, but
I don't have ImageMagick. Does anyone know of a standalone module for
performing this task?
Many thanks in advance.
Darrell
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: 10 Nov 1999 15:09:50 -0500
From: dha@panix.com (David H. Adler)
Subject: Re: Is $$variable allowed like in PHP ?
Message-Id: <slrn82jk8e.5av.dha@panix.com>
On 10 Nov 1999 10:55:57 +0000 (GMT), Ben Evans
<bene@chiark.greenend.org.uk> wrote:
>The perl version running is 5.004_03. Any thoughts, anyone?
I've got one: upgrade. :-) latest is 5.005_03 (unless you wish to
muck about with the development version, of course...)
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"You can't give a 4 to truth." - Saul Williams
------------------------------
Date: 9 Nov 1999 21:37:16 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: It is always like this here?
Message-Id: <80a46c$h97$1@gellyfish.btinternet.com>
On 9 Nov 1999 11:23:50 GMT Malcolm Ray wrote:
> On 08 Nov 1999 11:00:28 -0700, Eric The Read <emschwar@rmi.net> wrote:
>>But presence of quantity does not mean high quality. The argument of
>>high quality cannot be based on volume.
>>
>>All I was saying was that Perl has an Imperial buttload of documentation,
>
> It's been a *metric* buttload since 5.005_03. Upgrade!
>
Isnt a buttload by definition Imperial ?
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Wed, 10 Nov 1999 14:16:23 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: list (array) programming question
Message-Id: <3829EEB7.2E8D5FF@mail.cor.epa.gov>
Craig Berry wrote:
>
> Another WTDI, based on binary counting with bits corresponding to set
> membership:
>
> #!/usr/bin/perl -w
> # combine - display all nonempty combinations of the arguments
> # Craig Berry (19991109)
>
> use strict;
>
> my @combos = combine(@ARGV);
>
> foreach my $ar (@combos) {
> print join(' : ', @$ar), "\n" if @$ar;
> }
>
> sub combine {
> my @combos;
>
> for (my $pattern = 0; $pattern < 2 ** @_; $pattern++) {
> my @set;
>
> for (my $bit = 0; $bit < @_; $bit++) {
> push @set, $_[$bit] if $pattern & (1 << $bit);
> }
>
> push @combos, [ @set ];
> }
>
> return @combos;
> }
Interesting. But if you want to do it like this, you may
be able to speed up the process using Bit::Vector .
[no Benchmark done to make this statement, hence the
nebulous 'may be able to' weasel-words]
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 10 Nov 1999 16:53:04 -0500
From: "Alan McCoy" <a.r.mccoy@larc.nasa.gov>
Subject: LWP for retrieving web file data?
Message-Id: <80cpcm$6qo$1@reznor.larc.nasa.gov>
Does anyone know if LWP can be used to retrieve the last saved date for a
url? For example, I'd like to find out when
http://www.anyserver.com/anyfile.html was last saved. Does LWP allow that
kind of information to be accessed, or is there another Perl module that can
be used to gather this data?
Alan McCoy
a.r.mccoy@larc.nasa.gov
------------------------------
Date: Wed, 10 Nov 1999 22:54:45 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: LWP for retrieving web file data?
Message-Id: <slrn82jttl.4hc.mgjv@verbruggen.comdyn.com.au>
On Wed, 10 Nov 1999 16:53:04 -0500,
Alan McCoy <a.r.mccoy@larc.nasa.gov> wrote:
> Does anyone know if LWP can be used to retrieve the last saved date for a
> url? For example, I'd like to find out when
> http://www.anyserver.com/anyfile.html was last saved. Does LWP allow that
> kind of information to be accessed, or is there another Perl module that can
> be used to gather this data?
LWP implements the normal HTTP request methods. LWP also gives you
access to the HTTP headers in the response.
# perldoc LWP
# perldoc lwpcook
Of course, if the server on the other end doesn't tell you when the
document was last saved, there is nothing LWP can do about that. And
there's nothing that Perl can do about that. To talk about things like
that, you need to be somewhere in the comp.infosystems.www.*
hierarchy.
Martien
--
Martien Verbruggen |
Interactive Media Division | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Wed, 10 Nov 1999 12:43:14 -0800
From: Bin Zeng <zeng@stat.Berkeley.EDU>
Subject: Module File:Find problem
Message-Id: <Pine.SOL.4.10.9911101230450.7495-100000@fangorn.Berkeley.EDU>
The Module File:Find can be used to process files in a
directory recursively. But I got a problem with the linked directory.
Take a look at the following code:
#!/usr/bin/perl
use File::Find;
@d = '/bin';
find ( sub { print $File::Find::name, "\n"} , @d );
This code works fine for regular directory. But if the directory
'/bin' is a symbolic link, (I mean when 'ls -l /bin', the result is
something like
lrwxrwxrwx 1 root root Jul 8 21:54 /bin -> ./usr/bin
Then the code fails to work. What I mean by this is that the code
is supposed to print out the names of all the files in the directory
/bin. But if /bin is a linked directory, the output for the code is
just '/bin'.
Anyone has a fix for this?
Thank you.
------------------------------
Date: Wed, 10 Nov 1999 14:26:02 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: New Perl and CGI Resource site
Message-Id: <3829F0FA.87076726@mail.cor.epa.gov>
Jonathan Stowe wrote:
[snip]
> Heih perlcoders.com describe themselves as the 'Adult Webmasters CGI
> Resource' - well thats alright we wouldnt want kids getting any bad ideas ...
Oh. I thought 'Adult Webmasters CGI Resource' meant that they
catered to those porn sites who crop up here now and then begging
for CGI help.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 10 Nov 1999 20:26:38 +0000
From: James Sheffield <JSH@cs.stir.ac.uk>
Subject: NEWBIE WHO Please requires help with hashes PLEASE
Message-Id: <3829D4FE.A0BF3416@cs.stir.ac.uk>
How do I stick two values into the key. In this code that I am working
on both the studno and studgr
are primary keys and so I am thinking that they have to be put in like
this :
$key = "$studno\t$uncode" ;
Then do I do this
$grade{$key} = $studgr ;
Also what happens if a table has got two primary keys and I am wanting
to make two values the key and I
have nothing to compare it to.
The code is listed below.
if ($line =~ /:/)
{
#print $line ;
chomp($line) ;
#------------------------------------------------------------------------------------------------
$pos1 = index($line, ":") ;
$pos2 = index($line, "-") ;
#------------------------------------------------------------------------------------------------
$uncode = substr($line, 0, $pos1) ;
}
if ($line =~ / 9/)
{
$number = index($line, " 9") ;
$studno = substr($line, ($number+1), ($number+4)) ;
$studgr = substr($line, ($number+39), ($number+2)) ;
print "The Unit Number is : $uncode\n" ;
print "Student Number is : $studno\n" ;
print "Students Grade is : $studgr\n" ;
$key = "$studno\t$uncode" ;
$grade{$key} = $studgr ;
$outfilename = "Grade.txt" ;
open (GFILE, ">$outfilename") ;
while (($key, $studgr) = each(%grade))
{
print GFILE "$studno\t$uncode\t$studgr\n" ;
}
}
------------------------------
Date: Wed, 10 Nov 1999 21:06:37 GMT
From: Scratchie <AgitatorsBand@yahoo.com>
Subject: Re: NEWBIE WHO Please requires help with hashes PLEASE
Message-Id: <x7lW3.232$wJ6.47240@news.shore.net>
James Sheffield <JSH@cs.stir.ac.uk> wrote:
: How do I stick two values into the key.
[snip]
: $key = "$studno\t$uncode" ;
: $grade{$key} = $studgr ;
If you actually want to have two separate keys, you want to use a "hash of
hashes". What this really is is a hash whose values are references to
another hash, but in many cases you can use it just like a
"multi-dimensional" hash:
$new_grade{$studno}{$uncode} = $studgr;
See the perlref and perllol pages in the documentation for more
information on this useful feature.
: $pos1 = index($line, ":") ;
: $pos2 = index($line, "-") ;
: $uncode = substr($line, 0, $pos1) ;
I notice a lot of things like this in your code. I suspect that you may
not be familiar with perl's pattern matching operator. For example, to
extract everything up to the first ':', you might find it easier to write
if ($line =~/^([^:]*):/) {
$uncode = $1;
}
or even
$uncode = ( split(/:/,$line) )[0];
Depending on your needs. perlop, perlre and the 'split' section of
perlfunc will provide more info on this syntax.
Hope this helps,
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Wed, 10 Nov 1999 20:07:15 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: OO question again
Message-Id: <TfkW3.64697$23.2537176@typ11.nn.bcandid.com>
In article <80cc22$3do$2@newsmaster01.magnet.at>,
Thomas Schmickl <schmickl@magnet.at> wrote:
>I have mixed OO / Tk question:
>
>I have now written Get/Set methods instead of direct attribute access.
>
>But some Tk widgets need references to variables passed in their constructors.
>
>Before restructuring I had used ... -textvariable=>\$self->{'filename'} ...
>but now I have $self->filename() which returns the value of $self->{'filename'}.
>
>How can I handle this thing.
Just keep with the old way. The purpose of hiding your attributes is
to make sure you know where they're being modified. If you're handing
out the refs to the attributes to Tk widgets, you know.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 10 Nov 1999 14:45:46 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: perl & permission
Message-Id: <3829F59A.69855D2D@mail.cor.epa.gov>
[please fix your newsreader - there is something wrong about
your line lengths. thanks in advance]
Shlomit Afgin wrote:
>
> I write a perl script and I use the -r and -x. when I run the script
> from
> my userid it give me a list of all the problematics files that dont have
> read
> or executable permision. but when I run it as root it NOT give me that
> list
> even that when I tried to see a specific file, as root, it's gave me
> permission denaid.
> What can I use in my perl script to make root to inform me about files
> that it
> has no permission to them.
> (the file permission is usually: -rwx------)
If you read the section in perlfunc on the -X operators [that's
what it's under, don't blame me], you'll see that -r and -w tell
you about the status for the *effective* uid. Change your
uid, and then try it.
> my script contain:
> if ((-e $files[$i]) &&
> (((-f $files[$i])&&(! -r $files[$i]))||((-d $files[$i])&&( !-x
> $files[$i])))){
> print BAD "$files[$i]\n";
> }
Ugh. All those parens make my eyes hurt. Check out the
precedence of the -X functions vs. && [or 'and'] and you
can make this easier to read.
> Please send your answer also to : vshlomit@wicc.weizmann.ac.il
Sorry, but Usenet is a threaded medium. Sending e-mails
ruins the thread structure, prevents messages from getting
archived at deja.com, and most importantly, keeps people
from correcting bad or sub-optimal answers. It is important
to post and use a newsreader.
Shalom,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 10 Nov 1999 19:07:48 -0000
From: "GB" <ampanman@bigfoot.com>
Subject: perl + AI
Message-Id: <3829c386_1@newsread3.dircon.co.uk>
Im looking for a programmer with a good inside knowledge of PERL/CGI and an
understanding of the basics of AI to team up with for a business venture
involving internet advertising. Im based in London so it would be mutually
beneficial if you were too.
Drop me a line and let's talk
Graham
--
#################################
------------------------------
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 V9 Issue 1342
**************************************