[17113] in Perl-Users-Digest
Perl-Users Digest, Issue: 4525 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 5 00:05:30 2000
Date: Wed, 4 Oct 2000 21:05:10 -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: <970718709-v9-i4525@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 4 Oct 2000 Volume: 9 Number: 4525
Today's topics:
Re: embedding in HTML <elephant@squirrelgroup.com>
making a HASH up <bcanning@netresults-media.co.uk>
Re: making a HASH up (Martien Verbruggen)
multiple forms FAQ <pdmos23@geocities.com>
Re: multiple forms FAQ (Chris Fedde)
Re: Multiple TIEs on a hash? <mark@gmi2.com>
new <joeri.grandry@skynet.be>
Re: new <elephant@squirrelgroup.com>
Re: new (Martien Verbruggen)
Re: newFromPng <elephant@squirrelgroup.com>
Re: newFromPng (Martien Verbruggen)
Re: Programming Perl 3rd & Perl 6.0 <ren.maddox@tivoli.com>
Re: Programming Perl 3rd & Perl 6.0 <jeff@vpservices.com>
Quirk of strict ?? <barry.allebone@DB.COM>
Re: Quirk of strict ?? <david.obrien@ssmb.com.au>
Re: Quirk of strict ?? <tony_curtis32@yahoo.com>
Re: Quirk of strict ?? <jeffp@crusoe.net>
Re: Quirk of strict ?? <uri@sysarch.com>
Re: Quirk of strict ?? <peter.sundstrom@eds.com>
Re: Reverse by paragraphs - NOT! <ren.maddox@tivoli.com>
Re: Reverse by paragraphs - NOT! <uri@sysarch.com>
Re: serial connection & perl (David Efflandt)
sort <jrutled@home.com>
Re: Sort (Martien Verbruggen)
Re: Sort <bwalton@rochester.rr.com>
Re: splitting an array into a hash of sub-arrays <ren.maddox@tivoli.com>
Re: SSI in a CGI (David Efflandt)
Re: Strange behavior with DESTROY and END <bwalton@rochester.rr.com>
Re: Threads and SMP <philipg@atl.mediaone.net>
timeout on user input on NT <altitude@iname.com>
Re: What's the differences between perl4 and perl5 (Otto Wyss)
Re: Win32::SerialPort Tutorial? (David Efflandt)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 5 Oct 2000 12:16:15 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: embedding in HTML
Message-Id: <MPG.14468f77e4aaf18c9897fa@localhost>
N wrote ..
>Is there a way you embed perl script in the html files like PHP's <?php ....
>> method besides using SSI's? If it is too complicated an answer I would be
>happy with the name of this function (if exists) so I could look it up.
several .. take a look at the large number of modules at CPAN
http://search.cpan.org/
and search for embed*HTML in the Documentation
see the Help for more information on how to use this tool
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Thu, 5 Oct 2000 04:05:40 +0100
From: "Brian Canning" <bcanning@netresults-media.co.uk>
Subject: making a HASH up
Message-Id: <8rgrm8$gs3$1@newsg1.svr.pol.co.uk>
Hi All I am trying to make hash (very new to the hash thingy)
by reading in a file and using the push to create it.
I have just spent the last 2 hours trying all sort of way
to get this to work, but can't.
any help would be great
Brian
open (ADB, "Answers.txt") || die "Can't Open Answers.txt(r): $!\n";
@thelist = ();
while($ADataIn = <ADB>){
@AData = split(/\|/,$ADataIn);
$thedata = "$AData[0] => $AData[1]";
%thelist = push(@thelist, $thedata);
}
close ADB;
print "174 = $thelist{174}<BR>";
print "36 = $thelist{36}<BR>";
------------------------------
Date: Thu, 05 Oct 2000 03:28:53 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: making a HASH up
Message-Id: <slrn8tntb9.1kv.mgjv@verbruggen.comdyn.com.au>
On Thu, 5 Oct 2000 04:05:40 +0100,
Brian Canning <bcanning@netresults-media.co.uk> wrote:
> Hi All I am trying to make hash (very new to the hash thingy)
> by reading in a file and using the push to create it.
push is used to add elements to an array, not to create hashes.
> I have just spent the last 2 hours trying all sort of way
> to get this to work, but can't.
> any help would be great
>
> Brian
>
> open (ADB, "Answers.txt") || die "Can't Open Answers.txt(r): $!\n";
> @thelist = ();
> while($ADataIn = <ADB>){
> @AData = split(/\|/,$ADataIn);
This splits the line up. The last element still contains a newline.
> $thedata = "$AData[0] => $AData[1]";
This makes a string of the first two elements, with ' => ' between
them.
> %thelist = push(@thelist, $thedata);
And this is nonsensical, and should have set off quite a few warnings.
You do have the -w flag on, don't you? If not, make sure you do.
It pushes that string you just created on to the end of the @thelist
array, and assigns the result of that push to %thelist. Since push
returns the number of elements in the array after the push, this is
equivalent to something like:
%thelist = 12;
Which is hardly useful, isn't it? :)
I don't even know why you are using that array at all, or why you are
using the hash at all. Which if the two do you want?
> }
> close ADB;
> print "174 = $thelist{174}<BR>";
> print "36 = $thelist{36}<BR>";
I am not sure what you are trying to do. Let me try to guess. You have
a file that has a number of lines. Each line has two fields, separated
by a '|'. You now want to create a hash that contains the first fields
as keys, and the second as values? Is that correct?
#!/usr/local/bin/perl -w
use strict;
my $file = 'Answers.txt';
my %list;
open(ADB, $file) || die "Can't open $file for read: $!";
while (my $line = <ADB>)
{
chomp $line;
my ($key, $val) = split /\|/, $line, 2;
$list{$key} = $val;
}
close ADB;
The split is explicitly limited to split no more than two elements,
just in case the second field (which I assume to be the 'answer')
contains a '|'.
Literature:
# perldoc -f split
# perldoc -f chomp
# perldoc perldata
and to read about what push really is:
# perldoc -f push
Martien
--
Martien Verbruggen |
Interactive Media Division | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Thu, 05 Oct 2000 03:34:35 GMT
From: Pasquale <pdmos23@geocities.com>
Subject: multiple forms FAQ
Message-Id: <39DBF774.4AF407E@geocities.com>
I'm sure I've seen this question in the FAQ's or the documentation
somewhere, but I can't remember where. Can someone please tell me where
it is or was I hallucinating?
Thanks
Pasquale
------------------------------
Date: Thu, 05 Oct 2000 04:01:27 GMT
From: cfedde@u.i.sl3d.com (Chris Fedde)
Subject: Re: multiple forms FAQ
Message-Id: <r2TC5.133$D4.190387200@news.frii.net>
In article <39DBF774.4AF407E@geocities.com>,
Pasquale <pdmos23@geocities.com> wrote:
>I'm sure I've seen this question in the FAQ's or the documentation
>somewhere, but I can't remember where. Can someone please tell me where
>it is or was I hallucinating?
>Thanks
>Pasquale
>
Is this a perl question? man perlform.
chris
--
This space intentionally left blank
------------------------------
Date: Thu, 05 Oct 2000 02:00:23 GMT
From: "Mark A. Wadden" <mark@gmi2.com>
Subject: Re: Multiple TIEs on a hash?
Message-Id: <XgRC5.83940$dZ2.32307090@news3.rdc1.on.home.com>
Thanks... i appreciate the help!
-mark
Ben Kennedy wrote in message ...
>
...
>I don't know if you would actually be able to add functionality since the
>entire functionality of tie() is encapsulated in method calls, which would
>be directly inherited by your new class - you can't add code to them. What
>you can do is just create and use a reference to a tied dbm hash in your
own
>pacakge's code - this would let you intercept calls and returns to the
>SDBM_File methods.
>
>
>--Ben Kennedy
>
------------------------------
Date: Thu, 05 Oct 2000 03:11:04 +0200
From: Joeri Grandry <joeri.grandry@skynet.be>
Subject: new
Message-Id: <39DBD528.943FC3BD@skynet.be>
hi i have never used perl before, what is the best way to start with it
any program i need or so
------------------------------
Date: Thu, 5 Oct 2000 13:03:07 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: new
Message-Id: <MPG.14469a73bd8f96c9897fb@localhost>
Joeri Grandry wrote ..
>hi i have never used perl before, what is the best way to start with it
>any program i need or so
read the FAQ .. read the docs
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Thu, 05 Oct 2000 02:29:38 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: new
Message-Id: <slrn8tnps7.1hv.mgjv@verbruggen.comdyn.com.au>
On Thu, 05 Oct 2000 03:11:04 +0200,
Joeri Grandry <joeri.grandry@skynet.be> wrote:
> hi i have never used perl before, what is the best way to start with it
> any program i need or so
Yes, you will need perl.
Start reading at http://www.perl.com/. http://www.perl.org/ also has
useful information.
Martien
--
Martien Verbruggen |
Interactive Media Division | I'm just very selective about what I
Commercial Dynamics Pty. Ltd. | accept as reality - Calvin
NSW, Australia |
------------------------------
Date: Thu, 5 Oct 2000 12:08:03 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: newFromPng
Message-Id: <MPG.14468d8d6126e739897f9@localhost>
Stig Vilholm Petersen wrote ..
>I've made a script that reads in a .png file and display text using true
>type fonts on top of it.
>
>It works fine on my Solaris box, but when I run it under Apache on NT
>perl.exe crashes - even when I run it from the command prompt!
>
>This only happens if I include newFromPng() in my script. If I use new() to
>create a blank image instead it works fine too!
>
>What can be wrong? has anybody had similar problem?.
>
>PS - I don't get any information in my apache log file. Perl just crashes.
only in this last line do you give any clue that this is a CGI program
.. even then we're pretty much guessing
provide more detailed information .. no one knows what this newFromPng()
method does .. how can you expect people to guess what you're doing
wrong ?
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Thu, 05 Oct 2000 01:41:29 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: newFromPng
Message-Id: <slrn8tnn1t.1hv.mgjv@verbruggen.comdyn.com.au>
On Wed, 4 Oct 2000 10:34:01 -0500,
Stig Vilholm Petersen <svp@mail.dk> wrote:
> Hi,
>
> I've made a script that reads in a .png file and display text using true
> type fonts on top of it.
>
> It works fine on my Solaris box, but when I run it under Apache on NT
> perl.exe crashes - even when I run it from the command prompt!
And what is the error message? How does it 'crash'? Something must
happen.
> This only happens if I include newFromPng() in my script. If I use new() to
> create a blank image instead it works fine too!
From this I deduce that you are using the GD module. It would have
been helpful if you had mentioned this.
Anyway, this is not a perl problem. If anything it's a problem with
the particular version of the GD module you use. If you got it from
ActiveState, maybe they did something wrong when compiling. Maybe the
PNG image you're using is corrupt. Does the image display correctly
with another decent viewer?
> What can be wrong? has anybody had similar problem?.
Not me. I deal with quite a few people that use the GD module, and I
haven't heard of anyone yet who had troubles reading PNG images with
it. But that doesn't mean it doesn't happen.
> PS - I don't get any information in my apache log file. Perl just crashes.
Never, ever try to debug a problem by running CGI scripts. Run the
stuff from the command line, and see what happens.
Martien
--
Martien Verbruggen |
Interactive Media Division | This matter is best disposed of from
Commercial Dynamics Pty. Ltd. | a great height, over water.
NSW, Australia |
------------------------------
Date: 04 Oct 2000 18:31:18 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Programming Perl 3rd & Perl 6.0
Message-Id: <m3zokkfak9.fsf@dhcp11-177.support.tivoli.com>
faatdilac@my-deja.com writes:
> Since Perl 6.0 is going to be rewritten from scratch, is it worth
> buying Programming Perl 3rd?
Yes. Perl 6.0 is still a long way off, and there is much to be
learned from PP that will still apply.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 04 Oct 2000 18:35:51 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Programming Perl 3rd & Perl 6.0
Message-Id: <39DBDAF7.DF1EC697@vpservices.com>
Ren Maddox wrote:
>
> faatdilac@my-deja.com writes:
>
> > Since Perl 6.0 is going to be rewritten from scratch, is it worth
> > buying Programming Perl 3rd?
>
> Yes. Perl 6.0 is still a long way off, and there is much to be
> learned from PP that will still apply.
And figure it this way -- as long off as Perl 6.0 is, PP4 is probably
even further off than that. :-)
--
Jeff
------------------------------
Date: Thu, 05 Oct 2000 13:26:52 +1100
From: Barry <barry.allebone@DB.COM>
Subject: Quirk of strict ??
Message-Id: <39DBE6EC.D1CCAE80@DB.COM>
I'm on an NT 4 box running cygwin 1.1.2 and perl 5.6.0.
I have a small test file called t1.pl:
#!/usr/local/bin/perl -w
use strict;
$a = "thing1";
$b = "thing2";
$c = "thing3";
When executed the compilation is terminated because of errors and Perl
produces the following error message:
Global symbol $c requires explicit package name at ./t1.pl line 6.
This I understand but why not similar error messages for $a and $b ?
------------------------------
Date: Thu, 05 Oct 2000 13:58:56 +1000
From: Dave O'Brien <david.obrien@ssmb.com.au>
Subject: Re: Quirk of strict ??
Message-Id: <39DBFC80.359BF506@ssmb.com.au>
Barry wrote:
>
> I'm on an NT 4 box running cygwin 1.1.2 and perl 5.6.0.
>
> I have a small test file called t1.pl:
>
> #!/usr/local/bin/perl -w
> use strict;
> $a = "thing1";
> $b = "thing2";
> $c = "thing3";
>
> When executed the compilation is terminated because of errors and Perl
> produces the following error message:
>
> Global symbol $c requires explicit package name at ./t1.pl line 6.
>
> This I understand but why not similar error messages for $a and $b ?
You have to declare variables with the my operator e.g.
my $c = "thing3";
------------------------------
Date: 04 Oct 2000 22:08:47 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Quirk of strict ??
Message-Id: <87bsx0ougw.fsf@limey.hpcc.uh.edu>
>> On Thu, 05 Oct 2000 13:26:52 +1100,
>> Barry <barry.allebone@DB.COM> said:
> I'm on an NT 4 box running cygwin 1.1.2 and perl 5.6.0.
> I have a small test file called t1.pl:
> #!/usr/local/bin/perl -w use strict; $a = "thing1"; $b
> = "thing2"; $c = "thing3";
> Global symbol $c requires explicit package name at
> ./t1.pl line 6.
> This I understand but why not similar error messages for
> $a and $b ?
"perldoc -f sort". Recognise any of the variable names
near the end of the description? :-)
hth
t
--
Namaste!
And an "oogabooga" to you too!
-- Homer Simpson
------------------------------
Date: Wed, 4 Oct 2000 23:31:47 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Quirk of strict ??
Message-Id: <Pine.GSO.4.21.0010042329560.14163-100000@crusoe.crusoe.net>
[posted & mailed]
On Oct 5, Barry said:
> #!/usr/local/bin/perl -w
> use strict;
> $a = "thing1";
> $b = "thing2";
> $c = "thing3";
>
>Global symbol $c requires explicit package name at ./t1.pl line 6.
>This I understand but why not similar error messages for $a and $b ?
$a and $b are safe from strict vars because they are globals used in
sort().
perldoc -f sort
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Thu, 05 Oct 2000 03:37:25 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Quirk of strict ??
Message-Id: <x7n1gk3qmi.fsf@home.sysarch.com>
>>>>> "DO" == Dave O'Brien <david.obrien@ssmb.com.au> writes:
>> use strict;
>> $a = "thing1";
>> $b = "thing2";
>> $c = "thing3";
>>
>> Global symbol $c requires explicit package name at ./t1.pl line 6.
>>
>> This I understand but why not similar error messages for $a and $b ?
DO> You have to declare variables with the my operator e.g.
DO> my $c = "thing3";
you missed his point. he asked why only $c and not $a and $b generated
the error message. another poster gave the correct answer.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Thu, 5 Oct 2000 16:24:28 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Quirk of strict ??
Message-Id: <8rgsgs$sdc$1@hermes.nz.eds.com>
Dave O'Brien wrote in message <39DBFC80.359BF506@ssmb.com.au>...
>
>
>Barry wrote:
>>
>> I'm on an NT 4 box running cygwin 1.1.2 and perl 5.6.0.
>>
>> I have a small test file called t1.pl:
>>
>> #!/usr/local/bin/perl -w
>> use strict;
>> $a = "thing1";
>> $b = "thing2";
>> $c = "thing3";
>>
>> When executed the compilation is terminated because of errors and Perl
>> produces the following error message:
>>
>> Global symbol $c requires explicit package name at ./t1.pl line 6.
>>
>> This I understand but why not similar error messages for $a and $b ?
>You have to declare variables with the my operator e.g.
>
>my $c = "thing3";
Barry knew that. Read the question again.
The answer can be found if you use 'perldoc -f sort'.
If you're using strict, you <MUST NOT> declare $a
and $b as lexicals. They are package globals.
------------------------------
Date: 04 Oct 2000 19:08:34 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <m3n1gkf8u5.fsf@dhcp11-177.support.tivoli.com>
ollie_spencer@my-deja.com writes:
> I think now I need to express the file I need to "reverse by paragraph"
> as one long "super"string, not as an array at all, and reverse that
> string on a chosen delimiter, rather than try to do it with an array
> whose components are strings(if I can do it in a perl-ish manner). In
> other posts I noted that I have code(2 approaches, actually) that does
> what I desire, buth both are clumsy and, if you would, non-perlish.
#!/usr/local/bin/perl -w
use strict;
my $string = "This is a string*BOO*that has groups of
text and *BOO*uses a rather *BOO*interesting delimiter*BOO*(at
least I think*BOO*so)";
my $delimiter = "*BOO*";
my $new_string = join $delimiter, reverse split /\Q$delimiter/, $string;
print $new_string, "\n";
__END__
It's amazing how easy problems can get once there is a clear
specification of the problem.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 05 Oct 2000 03:33:10 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <x7r95w3qtl.fsf@home.sysarch.com>
>>>>> "os" == ollie spencer <ollie_spencer@my-deja.com> writes:
os> Thanks for your reply.
os> Nope, the headers ( there are 500 of them, each about 9 lines long, in
os> the file. I get rid of them successfully before I ever try to reverse
os> the file> They are gone, nada, zip --they are "dead parrots".
as others have stated, your usenet skills are VERY poor. stop jeopardy
posting and stop beating around the bush with your moving spec.
os> Loudly: WHAT I WANTED TO KNOW: Why can't I do something directly to the
os> original array so I get @ROF directly?
os> NOBODY HAS ANSWERED THAT ONE.
how about showing some sample data and sample result data? you keep
saying no one has answered your problem but i say you have never clearly
specified it. i think i am right here. i showed you another way to read
the file backwards (much faster than the cookbook method you quote) and
you don't try it.
os> But I think now *I* can.
os> When written to disk, a file is a long string with lines delineated by
os> whatever "$\" is, or by "\n". A file in an array is ALREADY delineated!
os> (I think)I should write the file to a long string variable, not an array
os> then reverse that on whatever delineator I choose.
all files are just a long string. BFD. you keep saying paragraph without
defining it. you claim you use the wrong terms but that is not ok. you
claim to be a physicist, so how would you like if i used pounds instead
of newtons? you might just crash a rocket on mars (oh, that has been
done!)
so when you post here, you follow this groups conventions: you quote
with editing and THEN you write your reply. you show code and data and
expected results. you don't keep rambling on about how no one has solved
your problem and then keep moving the problem.
your basic problem is trivial. you are making it much harder than it
is. this is all your doing, not this group so stop blaming us. post a
COMPLETE AND PROPER SPECIFICATION OF YOUR PROBLEM and maybe we can help
you.
until then, you have definitely exhausted your potential well of help
here.
(see i do know wher the shift key is. he yelled, so i yelled back)
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Thu, 5 Oct 2000 02:01:42 +0000 (UTC)
From: efflandt@efflandt.xnet.com (David Efflandt)
Subject: Re: serial connection & perl
Message-Id: <slrn8tno93.2f0.efflandt@efflandt.xnet.com>
On Wed, 04 Oct 2000 18:57:47 +0200, Joe <josef.zellner@aon.at> wrote:
>hi all!
>how can i use the serial port (e.g. data transfering via serial port)
>with perl?
>thx
Depending upon your platform either Win32::SerialPort, or that module has
been ported for Unix (Linux) as Device::SerialPort.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
------------------------------
Date: Thu, 05 Oct 2000 03:05:25 GMT
From: "Jeff Rutledge" <jrutled@home.com>
Subject: sort
Message-Id: <VdSC5.7379$6O5.619018@news1.rdc1.mb.home.com>
I would like to create a flat file in UNIX with one or more ' ls -al'
commands and alphabetically sort each line by the right-most field example:
/../../../.../filename
Some directories will be deeper than others so I will not be able to specify
a field number. My objective is determine whether or not there are
duplicate files in a file system. Any help would be greatly appreciated.
Thanks
Jeff Rutledge
------------------------------
Date: Thu, 05 Oct 2000 01:46:55 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Sort
Message-Id: <slrn8tnnc3.1hv.mgjv@verbruggen.comdyn.com.au>
On Thu, 04 Oct 2007 16:53:51 -0400,
jtjohnston <jtjohnston@courrier.usherb.ca> wrote:
> I'm using this to sort the lines in a db file. The problem is each line
> begins with a number.
>
> When the number is below 10, it sorts like this:
# perldoc -q sort
Found in /opt/perl/lib/5.6.0/pod/perlfaq4.pod
How do I sort an array by (anything)?
[snip]
How do I sort a hash (optionally by value instead of key)?
[snip]
# perldoc -f sort
Please, for your own sake, learn to use the documentation. Both of the
two little queries above would have given you the answer you need in a
few seconds. get yourself to a shell prompt, and type
# perldoc perldoc
# perldoc perl
If you have the ActiveState distribution, the documentation is also
available as HTML, which IMO is inferior, but usable.
> foreach $key (sort keys %DB){
> ($db_contact_name, $db_email, $db_title, $db_url, $db_desc,
> $db_keywords, $db_hits, $db_flag, $db_date, $db_time)
> = split (/\t/, $DB{$key});
>
> #...etc here I print html code
> }
So, I assume that you have the numbers as the keys in the hash? You're
not really clear about that, but ok..
foreach my $key (sort {$a <=> $b} keys %DB)
{
# do stuff
}
Martien
--
Martien Verbruggen |
Interactive Media Division | 42.6% of statistics is made up on the
Commercial Dynamics Pty. Ltd. | spot.
NSW, Australia |
------------------------------
Date: Thu, 05 Oct 2000 02:14:09 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Sort
Message-Id: <39DBE3F8.2C308F3D@rochester.rr.com>
jtjohnston wrote:
>
> I'm using this to sort the lines in a db file. The problem is each line
> begins with a number.
>
> When the number is below 10, it sorts like this:
>
> 1 asdasd
> 10 asdasd
> 2 asdasda
> 3 wsfdsdfs
>
> etc
>
> I would like to sort so that it would come out like:
>
> 1 asdasd
> 2 asdasda
> 3 wsfdsdfs
> 10 asdasd
>
> What do I have to do differently?
>
> Thanks,
>
> John
>
> ---------snip----------
>
> foreach $key (sort keys %DB){
You have to make it a numerical rather than lexical sort, like so:
foreach $key (sort {$a<=>$b} keys %DB){
See:
perldoc -q sort
> ($db_contact_name, $db_email, $db_title, $db_url, $db_desc,
> $db_keywords, $db_hits, $db_flag, $db_date, $db_time)
> = split (/\t/, $DB{$key});
>
> #...etc here I print html code
> }
--
Bob Walton
------------------------------
Date: 04 Oct 2000 18:49:25 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: splitting an array into a hash of sub-arrays
Message-Id: <m3vgv8f9q2.fsf@dhcp11-177.support.tivoli.com>
post_to_group <already_seen@my-deja.com> writes:
> I have 40+ hosts that I want to fork (see other post about problems
> there). Since I don't know how many hosts I will have (hosts come and
> go) and I wanted to be able to control the number of hosts per fork, I
> wrote the code below to create a series of arrays, each containing the
> set number of hosts. Except the last array would contain those left
> over. The code works fine. I was just wondering if there were a more
> efficient or better way to do this?
#!/usr/local/bin/perl -w
use strict;
my @hosts=qw(one two three four five six seven eight nine ten eleven);
print "Hosts: @hosts\n";
for my $hosts_per_group (3..6) { # Demonstrate at various sizes
my @hosts = @hosts; # make a copy to destroy
my @hostgroups;
# This is it:
push @hostgroups, [ splice(@hosts, 0, $hosts_per_group) ] while @hosts;
# Show that it worked:
print "\nWith a group size of $hosts_per_group:\n";
print "@$_\n" for @hostgroups;
}
__END__
Note that most of this code is just to demonstrate that it works. The
actual code that does what you want is just the:
push @hostgroups, [ splice(@hosts, 0, $hosts_per_group) ] while @hosts;
(Well, it doesn't do exactly what you asked for as it doesn't use a
hash, but I believe it should meet your needs. If not, let me
know....)
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 5 Oct 2000 02:09:10 +0000 (UTC)
From: efflandt@efflandt.xnet.com (David Efflandt)
Subject: Re: SSI in a CGI
Message-Id: <slrn8tnon2.2f0.efflandt@efflandt.xnet.com>
On Wed, 4 Oct 2000 16:07:35 -0500, Cernava <cernava@itexas.net> wrote:
>Well what I'm trying to do is have a ssi page execute a cgi then the cgi out
>put html with ssi tag(s) for other cgi programs that will need to be
>executed to make up a complete html page...
>
>I can't seem to get this done. The ssi page seems not to parse the out put
>of the cgi only the stuff that was in the original ssi page.
>
>By the way the server is a apache running on redhat.
CGI is not parsed for SSI because it is rather silly and inefficient to
spawn multiple processes to do what you could do from a single CGI.
Anything you need to include, be it a variable or file contents is quite
easy to do in Perl. Although, the question has nothing at all to do with
Perl, since the answer is the same in any language.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
------------------------------
Date: Thu, 05 Oct 2000 02:08:36 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Strange behavior with DESTROY and END
Message-Id: <39DBE2AA.2ED78660@rochester.rr.com>
sh_kell@my-deja.com wrote:
...
> > Well, the DESTROY method gets called when an object gets destroyed.
> > Destruction of the lexical variable my $test occurs when $test goes
> out
> > of scope. That is right after it is created, and before the program
> > ends. The global variable $test, on the other hand, persists until it
> > is destroyed in the END processing. To see this even more clearly,
> add
> > a block around the my $test=... and a print statement afterwards, like
> > so:
> >
> > use Test;
> > {
> > my $testlexical=new Test;
> > $testglobal=new Test;
> > }
> > print "Hi from after the block\n";
> >
> > --
> > Bob Walton
>
> I understand that an object's destructor is called when the object goes
> out of scope. My whole question is why does the class END block get
> called before the DESTROY is issued for all instantiated objects of
> that class?
>
> It seems to me that the END block (being a class wide destructor)
> should ALWAYS be executed after the DESTROY for the last object of that
> class else all class variables cease to exist and are not available to
> be used by the other remaining objects of that class.
>
> The example above was a simplified version of my entire, more complex
> problem. In the module I have, in the DESTROY method it has something
> similar to:
>
> DESTROY{
> my $self = shift;
> $self->_flush() if $objectCount == 0;
> }
>
> Where _flush() writes the latest info to the database (in this case a
> number that all objects in the class update to get a unique ID). Now
> since the database handle is class-wide once I reach the end of my
> program it calls main::END, Class::END then DESTROY for objects (if
> objects were not instantiated via 'my')
>
> This means that once _flush() is called it cannot update the database
> since the handle has been destroyed and made inaccessible.
>
> Now in the perltoot manpage it states:
>
> "The object destructor handles the death of each distinct object. But
> sometimes you want a bit of cleanup when the entire class is shut down,
> which currently only happens when the program exits. To make such a
> class destructor, create a function in that class's package named END.
> This works just like the end function in traditional modules, meaning
> that it gets called whenever your program exits unless it execs or dies
> of an uncaught signal."
>
> I guess the exact time a program is deemed 'exited' is at the time
> main::END is called which does not care that there may be other objects
> of a given class left and immediately calls all ENDs on down the line
> thereby destroying any class variables that those objects may have
> needed.
...
Hmmmmm...well, at the risk of delving in where I don't really know very
much, it seems to me like you have created objects that don't really
follow the object-oriented paradigm. If each and every one of your
objects contained a reference to the filehandle variable that you say
goes out of scope before DESTROY gets called for that object, then the
filehandle wouldn't be trashed, since it would still be referenced. The
paradigm, as I understand it, is that an object should contain
*everything* about itself, and that nothing it needs should exist
without dependence upon the object -- that is, it shouldn't be permitted
to go out of scope until the object itself is out of scope. A global
filehandle that does not have a reference to it in the object would be a
prime example. The reference might be just for the purpose of keeping
the filehandle around for DESTROY -- but then if a reference to the
filehandle is maintained, then it wouldn't be necessary to use a global
variable to reference the filehandle in the DESTROY method, thereby
making it more general. By maintaining a reference, the destruction
order shouldn't matter. I doubt that Perl or anything else could grok
the "correct" destruction order in complicated situations anyway. HTH.
--
Bob Walton
------------------------------
Date: Thu, 05 Oct 2000 04:03:21 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: Threads and SMP
Message-Id: <d4TC5.16884$cW3.3397527@typhoon.southeast.rr.com>
Louis Z <louis@trapezoid.com> wrote in message
news:39db8787$1_3@goliath2.newsfeeds.com...
> Is there any way for Perl to take advantage of dual CPUs? Using threads?
> Ideally, I'd be able to run some simulation programs twice as fast if they
> could' use both CPUs. Thanks.
Perl includes thread support as an experimental feature. See perldoc
perlthrtut for more information.
hth,
p
------------------------------
Date: Thu, 05 Oct 2000 02:21:24 -0000
From: Alex Tang <altitude@iname.com>
Subject: timeout on user input on NT
Message-Id: <stnpd425h56v98@corp.supernews.com>
Hi folks.
I was wondering.
Is it possible to timeout on user input using Perl on NT (command line)?
What I'm trying to do is have the user input some data. If after a
certain period of time (10 seconds for now), the user doesn't enter any
data, I want the program to continue on its way.
is this possible?
Thanks.
...alex...
--
Alex Tang: altitude@iname.com
------------------------------
Date: Thu, 5 Oct 2000 03:07:38 +0200
From: otto.wyss@bluewin.ch (Otto Wyss)
Subject: Re: What's the differences between perl4 and perl5
Message-Id: <1ei0dgt.12eb2l4qyiepsN%otto.wyss@bluewin.ch>
Elaine Ashton <elaine@chaos.wustl.edu> wrote:
> in article m1bsx1fwf6.fsf@halfdome.holdit.com, Randal L. Schwartz at
> merlyn@stonehenge.com quoth:
> >>>>>> "Otto" == Otto Wyss <otto.wyss@bluewin.ch> writes:
> > Otto> I have to fix a perl-script and are restricted to use perl4. What are
> > Otto> the restrictions between those versions and are they anywhere
> > Otto> documented?
> >
> > Perl4 is what people use when they don't know the difference.
>
> Or when they have no compelling need to know.
>
> > All versions of perl prior to 5.004 are known to have demonstrable
> > security errors (at least buffer overflows).
>
I don't know the difference :-( and hopefully probably dont't have to
:-) since I just have to fix one script on a standalone machine, which
will get out of service the next year. Unforunatly I mustn't upgrade it
to perl5.
O. Wyss
------------------------------
Date: Thu, 5 Oct 2000 02:27:28 +0000 (UTC)
From: efflandt@efflandt.xnet.com (David Efflandt)
Subject: Re: Win32::SerialPort Tutorial?
Message-Id: <slrn8tnppc.2f0.efflandt@efflandt.xnet.com>
On Mon, 02 Oct 2000 21:45:46 -0400, MC <mc@backwoods.org> wrote:
>Can anyone point me to a tutorial or reference on the Win32::SerialPort module
>other than the POD material. The POD material just ~barely~ covers the bones of
>it and is rather less than clear as to the usage of many of the functions. I've
>managed, ~finally~, to make a basic script work, but thats as far as I can go
>w/o better documentation.
Device::SerialPort for Unix based on Win32::SerialPort comes with numerous
examples in an 'eg' subdir of the module source. I wonder where similar
examples end up when you install Win32::SerialPort:
eg/any_os.plx - cross-platform "conditional use" demo
eg/demo1.plx - talks to a "really dumb" terminal
eg/demo2.plx - "poor man's" readline and chatV
eg/demo3.plx - looks like a setup menu - but only looks :-(
eg/demo4.plx - simplest setup: "new", "required param"
eg/demo5.plx - "waitfor" and "nextline" using lookfor
eg/demo6.plx - basic tied FileHandle operations, record separators
eg/demo7.plx - a Perl/Tk based terminal, event loop and callbacks
eg/demo8.plx - command line terminal emulator with Term::Readkey
eq/options.plx - post-install test that prints available options
eg/example1.txt - examples from The Perl Journal #13
eg/example2.txt - (minimal mods for cross-platform use)
eg/example3.txt
eg/example4.txt
eg/example5.txt
eg/example6.txt
eg/example7.txt
eg/example8.txt
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
------------------------------
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 4525
**************************************