[22263] in Perl-Users-Digest
Perl-Users Digest, Issue: 4484 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 29 18:06:24 2003
Date: Wed, 29 Jan 2003 15:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 29 Jan 2003 Volume: 10 Number: 4484
Today's topics:
Re: alarm() implemented? - nevermind, different questio <spark@dcwis.nodurnspam.com>
Re: Assign New Values in Loop After Submit (Tad McClellan)
Re: file limitation and if -e option?!! <nobull@mail.com>
Re: GetOptions - Can you get the order of the options? (Johan Vromans)
how to print error messages to html (James Lee)
Re: Next problem. (Gary E. Ansok)
Re: Next problem. <abigail@abigail.nl>
OO problem <rajkothary@hotmail.com>
Re: OO problem <nobull@mail.com>
Re: perl data structure question (Tad McClellan)
Re: perl data structure question (Andrew Perrin (CLists))
Re: perl data structure question <nobull@mail.com>
Re: purpose of threads? <REMOVEsdnCAPS@comcast.net>
Re: purpose of threads? <Juha.Laiho@iki.fi>
Re: purpose of threads? (h\)
Redirection within Perl <demetros@edamail.fishkill.ibm.com>
Re: Redirection within Perl (Anno Siegel)
Re: Redirection within Perl (Ben Morrow)
Sorting Arrays of Hashes (Nishan Sathyanarayan)
Re: Sorting Arrays of Hashes <abigail@abigail.nl>
String to float casting? (Gomac)
Re: String to float casting? <penny1482@attbi.com>
Re: String to float casting? <glex_nospam@qwest.net>
Re: String to float casting? <abigail@abigail.nl>
why do I need to reload if I 'back' to my page? (James Lee)
Re: why do I need to reload if I 'back' to my page? <abigail@abigail.nl>
wondering why this doesn't work <swen@news.com>
Re: wondering why this doesn't work (h\)
Re: wondering why this doesn't work <glex@qwest.net>
Re: wondering why this doesn't work (Andrew Perrin (CLists))
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 29 Jan 2003 13:23:36 -0600
From: spark <spark@dcwis.nodurnspam.com>
Subject: Re: alarm() implemented? - nevermind, different question
Message-Id: <MPG.18a1e62f3ee36c31989697@news-central.giganews.com>
In article <3e382413$1@usenet.ugs.com>, mothra@nowhereatall.com says...
>
> > spark@dcwis.nodurnspam.com says...
> > > Is alarm() implemented for Win32 in the latest version of Perl?
> > >
> >
> > Nevermind, I see it isn't.
> What version of perl did you try? I am running version 5.8.0 and
> it is implemented.
Oh - I went to activestate and looked up the perlport page there. I
assumed it was for 5.8. If it's working for you, I'll try 5.8 (I'm on
5.6). Thanks!
spark
>
> use strict;
> use warnings;
>
> print " perl version is $]\n";
> $SIG{ALRM} = sub { die "timeout" };
>
> eval {
> alarm(3);
> sleep (6);
> alarm(0);
> };
>
> if ($@) {
> if ($@ =~ /timeout/) {
> print "Yep!! it timed out\n"; # timed out; do
> what you will here
> } else {
> alarm(0); # clear the still-pending alarm
> die; # propagate unexpected exception
> }
> }
>
> output isF:\scripts>time.pl
> perl version is 5.008
> Yep!! it timed out
>
> F:\scripts>
>
> Hope this helps
>
> Mothra
>
>
>
>
------------------------------
Date: Wed, 29 Jan 2003 13:05:00 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Assign New Values in Loop After Submit
Message-Id: <slrnb3g9es.bp3.tadmc@magna.augustmail.com>
Hunter <dave_h4@yahoo.com> wrote:
> Hi Group - I have users fill out a form and the values for the radio
> buttons are Y and N. When I display the confirmation screen to the
> user I want to display Yes or No based on their selections.
--------------------------
#!/usr/bin/perl
use strict;
use warnings;
my %p = (
question1 => 'Y',
question2 => 'N',
question3 => 'Y',
);
$p{$_} = $p{$_} eq 'N' ? 'No' : 'Yes' for keys %p;
print "$_ ==> $p{$_}\n" for sort keys %p;
--------------------------
Of rewritten so as to be easier to understand:
foreach ( keys %p ) {
if ( $p{$_} eq 'N' )
{ $p{$_} = 'No' }
else
{ $p{$_} = 'Yes' }
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 29 Jan 2003 19:35:43 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: file limitation and if -e option?!!
Message-Id: <u965s7vje8.fsf@wcl-l.bham.ac.uk>
ibm_97@yahoo.com (JZ) writes:
> Perl 5.6 on both Solaris 2.8 and Red Hat Linux 7.1
>
> I want to detect if a file exists or not in current directory:
> if (! -e "$filename") {
> ....
> }
> How to overcome this?
Rebuild Perl with large file support enabled.
More recently shipped binary distributions will probably have been
built this way already.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 29 Jan 2003 20:54:04 +0100
From: jvromans@squirrel.nl (Johan Vromans)
Subject: Re: GetOptions - Can you get the order of the options?
Message-Id: <m2u1fr4tr7.fsf@phoenix.squirrel.nl>
Ed Kulis <ekulis@apple.com> writes:
> I don't want to require an order I just what to know what it is.
Usually there's a deeper intent below a question like this.
What is it that you want to achieve? There may be a better way.
-- Johan
------------------------------
Date: 29 Jan 2003 14:18:08 -0800
From: csejl@yahoo.com (James Lee)
Subject: how to print error messages to html
Message-Id: <146277ca.0301291418.289aa799@posting.google.com>
Hi,
I'd appreciate it if someone could clarify this. I have a script that
runs off of cgi-bin on my web server. There are two places in this
snippet that could print out $dbh->errstr. How would I get this error
message to be printed to the web page. Right now, when it fails it
just displays a blank page. The whole thing below is inside
<html><body> tags. Thanks.
-j.
$dbh = DBI->connect($datasource, $username, $password)
or die "Can't connect to $datasource: $dbh->errstr\n";
@pieces = split(/ /, $st);
$tablename = $pieces[2];
if ($iteration > 0) {
for ($i=0; $i<$iteration; $i++) {
$dbh->do($st)
|| die "Couldn't execute statement: " . $dbh->errstr . "\n";
# if it's 'select' we don't need to modify anything
if (($st =~ /^create/i) || ($st =~ /^insert/i) || ($st =~
/^drop/i)) {
($name, $number) = $tablename =~
/^([a-zA-Z_]+)(\d+)$/;
$number++;
$pieces[2] = $tablename = $name.$number;
$st = join (" ", @pieces);
}
}
} else {
$now = time;
more code here...
------------------------------
Date: Wed, 29 Jan 2003 19:07:18 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Next problem.
Message-Id: <b198p6$j87$1@naig.caltech.edu>
Ben Morrow <mauzo@ux-ma160-13.csv.warwick.ac.uk> wrote:
>"Jürgen Exner" <jurgenex@hotmail.com> wrote:
>>Tad McClellan wrote:
>>>> Richard S Beckett wrote:
>>>
>>>>> next if ($_ eq ('Fred' || 'Wilma'));
>>>
>>> Nope, warnings won't catch that one.
>>
>>Hmm, I wonder if they should.
>>Considering that this mistake pops up about every month it may be worth
>>thinking about a change in warnings.
>
>But then
>my $var = shift || $ENV{PARAM} || 'default';
>wouldn't work.
If you limited it to cases where a constant is on the left side of
a || operator, there wouldn't be a warning here.
If this would apply to the || operator in general, I'd suggest limiting
it to string constants -- I occasionally use `if (1 || condition)' or
`if (0 && condition)' during debugging to force a test on or off without
losing track of the original condition code (quicker than commenting).
If this will only apply when the || operator is used on one side of
a comparison operator, then the above doesn't apply. We don't even
need to limit it to constants, really -- I'd say that
if ($_ eq ($marker1 || $marker2)))
could easily be correct or incorrect, and we can't tell just from this
line what the intent is. (Is $marker2 an alternative to, or a default for,
$marker1?)
As an alternative, perhaps the warning should be about using a string
*constant* in a Boolean context? Not a string value, of course --
`if ($var)' is documented and useful for all value types, but is
`if ("fred")' ever likely to appear in real code? Could this be
distinguished internally from a non-constant string? Should it?
Should `if ("$var")' cause a warning (useless quotes, but rarely
a problem)? Is there ever a use for something like `if ("0$var")'?
Gary
--
Rule #87: If the thought of something makes me giggle for longer than 15
seconds, I am to assume that I am not allowed to do it.
-- www.skippyslist.com
------------------------------
Date: 29 Jan 2003 21:45:57 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Next problem.
Message-Id: <slrnb3gisk.cp1.abigail@alexandra.abigail.nl>
Richard S Beckett (spikey-wan@bigfoot.com) wrote on MMMCDXXXVIII
September MCMXCIII in <URL:news:b18vsl$pbt$1@newshost.mot.com>:
::
:: I _always_ use strict and warnings.
Then you wouldn't be able to write modules like Exporter or Memoize.
Abigail
--
Wise programmers know that turning off strictures opens new ways.
------------------------------
Date: Wed, 29 Jan 2003 19:35:17 -0000
From: "Raj" <rajkothary@hotmail.com>
Subject: OO problem
Message-Id: <b19adl$9b6$1$8302bc10@news.demon.co.uk>
Hi,
I have been going through the Perltoot man page trying to get my classes
set-up and I think I have done an ok job, however I have a class Top and I
am having difficulty accessing it's methods from a class Bottom, which looks
like this:
use Top;
our @ISA = qw(Top);
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my (%params) = @_;
my $self = {};
bless($self, $class);
$self{'sid'} = $params{'sid'};
$self{'date'} = formatdate($params{'date'});
}
However I cannot get a return value from the formatdate method. I have
tried the following combinations:
Top::formatdate()
Top->formatdate()
$self->formatdate()
$self->Top::formatdate()
formatdate()
SUPER::formatdate()
but none of them seem to work...have I left something out elsewhere that I
require to use the methods?
Also, I would like to use the constructor of Top in Bottom. Do I still have
to shift in the object and bless it first? That is, do I (in Bottom):
sub new {
SUPER::new();
}
or:
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
SUPER::new();
}
Any help would be appreciated!
Thanks,
Raj
------------------------------
Date: 29 Jan 2003 20:02:27 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: OO problem
Message-Id: <u91y2vvi5o.fsf@wcl-l.bham.ac.uk>
"Raj" <rajkothary@hotmail.com> writes:
>
> I have been going through the Perltoot man page trying to get my classes
> set-up and I think I have done an ok job, however I have a class Top and I
> am having difficulty accessing it's methods from a class Bottom, which looks
> like this:
>
I assume you accidently deleted the line
package Bottom;
When you cut and pasted this.
> use Top;
>
> our @ISA = qw(Top);
>
> sub new {
> my $proto = shift;
> my $class = ref($proto) || $proto;
> my (%params) = @_;
>
> my $self = {};
> bless($self, $class);
Since Bottom is not a top-level class this is generally better written
as:
my $self = $proto->SUPER::new;
There are exceptions to this rule but unless you know why you are
breaking the rule, don't.
> $self{'sid'} = $params{'sid'};
> $self{'date'} = formatdate($params{'date'});
> }
>
> However I cannot get a return value from the formatdate method.
You do not call a formatdate() method. You call a plain subroutine
called formdate. Without seeing the definition formdate() I can't
guess if it should be called as a method or a subroutine.
> I have tried the following combinations:
>
> Top::formatdate()
> formatdate()
> $self->formatdate()
Without knowing where formatdate is defined and how it is intended to
be used it is impossible to say which, if any, of these would be
correct.
> Top->formatdate()
You probably should not specify the name of a parent package name in a
class method call. Always use $self (or in some cases __PACKAGE__).
There are exceptions to this rule but unless you know why you are
breaking the rule, don't.
> $self->Top::formatdate()
Do not specify an explict package name in a method call. Always use a
bare method name or SUPER::. There are exceptions to this rule but
unless you know why you are breaking the rule, don't.
> SUPER::formatdate()
Dont use SUPER:: in plain subroutine calls. For once I'm not aware of
any exceptions to this rule.
> but none of them seem to work...have I left something out elsewhere that I
> require to use the methods?
Probably but there's no way to tell. To quote the posting guidelines...
First make a short (less than 20-30 lines) and *complete* program
that illustrates the problem you are having. People should be able
to run your program by copy/pasting the code from your article. (You
will find that doing this step very often reveals your problem
directly. Leading to an answer much more quickly and reliably than
posting to Usenet.)
I suggest you go read the whole of the guidelines - they are very good.
> Also, I would like to use the constructor of Top in Bottom.
I have already addresses this above.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 29 Jan 2003 13:16:50 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl data structure question
Message-Id: <slrnb3ga52.brm.tadmc@magna.augustmail.com>
bad_knee <bl8n8r@yahoo.com> wrote:
> I've learned perl
> by gleaning from examples, source code, FAQs, and just
> plain "doing".
You should learn to always develop your code with these turned on:
use strict;
use warnings;
> So a couple questions:
> A - What type of data structure is this?
colloquial: LoH (list of hashes)
formal: List of references to hashes
Since it has only a single hash in it, I'd have to call
your choice of data structure "strange".
Why not just have a single real hash?
> B - What is the purpose of the "$xxxx" variable
> on the right side of the '=>' (I don't use
> it to address, nor reference the elements?)
Those are the hash values.
> @DirEnts =
my @DirEnts =
> {
> t => $type,
> n => $name,
> s => $size,
> a => $access,
> m => $modified,
> g => $groupid,
> u => $userid,
> r => $readable,
> w => $writable,
> f => $fileinfo
> };
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 29 Jan 2003 14:25:26 -0500
From: clists@perrin.socsci.unc.edu (Andrew Perrin (CLists))
Subject: Re: perl data structure question
Message-Id: <84n0ljg3mh.fsf@perrin.socsci.unc.edu>
bl8n8r@yahoo.com (bad_knee) writes:
> So a couple questions:
> A - What type of data structure is this?
@DirEnts is an array.
$DirEnts[0] (the first element of @DirEnts) is a reference to a hash.
>
> B - What is the purpose of the "$xxxx" variable
> on the right side of the '=>' (I don't use
> it to address, nor reference the elements?)
>
the fact that it's a variable (as opposed to a literal, reference,
etc.) is immaterial. It's the value to which the corresponding key in
the hash referred to by $DirEnts[0] points.
>
> ###############################################################
> # contents of path when GetDirEnts is called
> @DirEnts =
> {
> t => $type,
> n => $name,
> s => $size,
> a => $access,
> m => $modified,
> g => $groupid,
> u => $userid,
> r => $readable,
> w => $writable,
> f => $fileinfo
> };
Note that with this code, there will never be $DirEnts[1..n] where
n>=1; it's therefore unclear why you would want to store your hash
reference in the first element of an array instead of simply in a
scalar.
>
> print "name:$DirEnts[$i]->{n} type:$DirEnts[$i]->{t}\n";
With the code you gave us, both of these should be undef, since the
variables ($type..$fileinfo) are all undefined. Of course it's
possible you defined them before the code you posted.
--
----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists@perrin.socsci.unc.edu * andrew_perrin (at) unc.edu
------------------------------
Date: 29 Jan 2003 19:33:50 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: perl data structure question
Message-Id: <u9adhjvjhd.fsf@wcl-l.bham.ac.uk>
bl8n8r@yahoo.com (bad_knee) writes:
> I've often used the data structure below to store an array
> of "records" (for lack of a better word), although I'm
> not really sure if this is an array, or a hash as far
> as perl goes.
> @DirEnts =
> {
> t => $type,
> n => $name,
> s => $size,
> a => $access,
> m => $modified,
> g => $groupid,
> u => $userid,
> r => $readable,
> w => $writable,
> f => $fileinfo
> };
> The question was asked of me today just
> what exactly this is, and I realized I didn't know.
It is an array. That's the only thing one can say for sure.
It's provably an array of references to anonymous hashes that are being used as
records. But it's only got one element so I'm just guessing the other
elements of the array would be of the same form.
In shorthand terminolgy it's an "Array of hashes" or "AoH" but you
must remember that even though the phrase "references to anonymous" is
often ommited it is still part of the reality.
> I've learned perl by gleaning from examples, source code, FAQs, and
> just plain "doing".
Perhaps you should try reading some manuals.
In particular perldsc seems like a good one.
> B - What is the purpose of the "$xxxx" variable
> on the right side of the '=>' (I don't use
> it to address, nor reference the elements?)
They are just a sclar expressions providing the value for the elements
of the hash.
Perhaps perldsc would be a bit advanced. Perhaps you need to go back
to perldata to understand Perl's primative data types first.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 29 Jan 2003 13:06:18 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: purpose of threads?
Message-Id: <Xns93128FD1FDC05sdn.comcast@216.166.71.239>
jake@omnimode.com (jake johnson) wrote in
news:8897a0de.0301290959.33c92fed@posting.google.com:
The purpose of threads is to make Perl more like Java; to wit, to slow the
program down significantly.
;-)
--
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
------------------------------
Date: Wed, 29 Jan 2003 19:42:00 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: purpose of threads?
Message-Id: <b19aod$e7i$1@ichaos.ichaos-int>
jake@omnimode.com (jake johnson) said:
>I'm a relative perl newbie. I'm looking to advance my skills though
>and one of the things I keep bumping into is this idea of threads. I
>understand that they are needed mostly in server applications, right?
They're very usable in client applications as well.
>[...] This has piqued my curiosity about what threads are and why
>people are aching to use them. I haven't been able to find any 'threads
>for newbies' discussions,
... perhaps beause threads are not for newbies. In addition to being
a good tool, they also can be a great source of frustration.
>For one thing, are threads an alternative to fork?
In a way, yes. They're multiple simultaneous execution units. But threads
operate within a single process, so they all share the same memory space,
for example.
Where threads fit are situations where you're doing multiple tasks
simultaneously (in parallel), and the tasks have much data to interchange
with each other. You could do this with several processes and various
forms of IPC, too, but communication between processes is expensive
in terms of CPU use. So, threads lower the CPU utilization by reducing
the need for IPC, and can also reduce communications latency when
compared to multiple processes exchanging data.
I hope this gives you a starting point.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: Wed, 29 Jan 2003 23:11:19 +0100
From: "Michael Peuser \(h\)" <post@mpeuser.de>
Subject: Re: purpose of threads?
Message-Id: <b19jga$g5g$02$1@news.t-online.com>
"Brian McCauley" <nobull@mail.com> schrieb
> I've been programming for >25 years.
>
> Professionally for >15.
>
> (In Perl for >5).
>
> I've never yet used threads (for real) in any language.
So you have always been so lucky to put the burden on the operating system
;-)
Perl for sure is not a language for programming embedded systems, but there
are situations with highly interactive programs where some number
chrunching should go on in the background....
Or doing different simulations in multiple windows....
Kindly Mike
------------------------------
Date: Wed, 29 Jan 2003 14:42:12 -0500
From: "George C. Demetros" <demetros@edamail.fishkill.ibm.com>
Subject: Redirection within Perl
Message-Id: <3E382E94.952E4CB6@edamail.fishkill.ibm.com>
Hi.
Is it possible to redirect STDIN, STDOUT, and STDERR to FIFO files within Perl?
I know I can do the following from a shell window:
myProgram <fifoInFile 2>fifoOutFile 1>&2
But can I do this within Perl:
print(STDOUT "hi mom\n");
and have the message go to my fifoOutFile?
Thanks in advance!
George
------------------------------
Date: 29 Jan 2003 20:46:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Redirection within Perl
Message-Id: <b19eig$dcu$1@mamenchi.zrz.TU-Berlin.DE>
George C. Demetros <demetros@edamail.fishkill.ibm.com> wrote in comp.lang.perl.misc:
> Hi.
>
> Is it possible to redirect STDIN, STDOUT, and STDERR to FIFO files within Perl?
> I know I can do the following from a shell window:
>
> myProgram <fifoInFile 2>fifoOutFile 1>&2
>
> But can I do this within Perl:
>
> print(STDOUT "hi mom\n");
>
> and have the message go to my fifoOutFile?
Do "open STDOUT, '>', '/any/file/you/want'". It's just a filehandle,
after all.
Anno
------------------------------
Date: Wed, 29 Jan 2003 21:44:07 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Redirection within Perl
Message-Id: <b19hv7$j8f$1@wisteria.csv.warwick.ac.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>George C. Demetros <demetros@edamail.fishkill.ibm.com> wrote in comp.lang.perl.misc:
>> Hi.
>>
>> Is it possible to redirect STDIN, STDOUT, and STDERR to FIFO files within Perl?
>> I know I can do the following from a shell window:
>>
>> myProgram <fifoInFile 2>fifoOutFile 1>&2
>>
>> But can I do this within Perl:
>>
>> print(STDOUT "hi mom\n");
>>
>> and have the message go to my fifoOutFile?
>
>Do "open STDOUT, '>', '/any/file/you/want'". It's just a filehandle,
>after all.
And, of course, you can use POSIX::mkfifo to make the fifo in the first place.
Ben
------------------------------
Date: 29 Jan 2003 14:10:27 -0800
From: nishan@loudcloud.com (Nishan Sathyanarayan)
Subject: Sorting Arrays of Hashes
Message-Id: <d60195b3.0301291410.5e3eeea1@posting.google.com>
I've created a structure which is a Hash of (Array of Hashes). I know
that @{ $HoA{$domain} } is an Array of Hashes and $href represents
each Hash of the array. I want to sort each Hash in the Array of
Hashes by their keys and print them out. I know this attempt to sort
the keys doesn't work. I'm fairly certain I'm missing something
fundamental, can someone shed some light on this?
sub printEntireHash {
foreach my $domain ( sort keys %HoA ) {
for my $href ( @{ $HoA{$domain} } ) {
for my $url ( sort {$b cmp $a } keys %{$href} ) {
print "URL=$url Redirect=$href->{$role}\n";
}
}
}
Thanks,
Nishan
------------------------------
Date: 29 Jan 2003 22:45:47 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Sorting Arrays of Hashes
Message-Id: <slrnb3gmcr.cp1.abigail@alexandra.abigail.nl>
Nishan Sathyanarayan (nishan@loudcloud.com) wrote on MMMCDXXXVIII
September MCMXCIII in <URL:news:d60195b3.0301291410.5e3eeea1@posting.google.com>:
`' I've created a structure which is a Hash of (Array of Hashes). I know
`' that @{ $HoA{$domain} } is an Array of Hashes and $href represents
`' each Hash of the array. I want to sort each Hash in the Array of
`' Hashes by their keys and print them out. I know this attempt to sort
`' the keys doesn't work. I'm fairly certain I'm missing something
`' fundamental, can someone shed some light on this?
`'
`' sub printEntireHash {
`' foreach my $domain ( sort keys %HoA ) {
`'
`' for my $href ( @{ $HoA{$domain} } ) {
`'
`' for my $url ( sort {$b cmp $a } keys %{$href} ) {
`'
`' print "URL=$url Redirect=$href->{$role}\n";
So, what's in '$role'? Shouldn't that be '$url'?
In general, "it doesn't work" question don't work if you don't tell
us what "doesn't work". Do you get any output? Do you get output you
don't expect? Does the datastructure actually contain what you
think it contains?
I would be useful if you beside the code fragment also tell us
what is in %HoA, what the code prints, and what you expect it
to print. Otherwise, it's just a guessing game.
Abigail
--
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_=sub{print/::(.*)/};
$\=$/;q<Just another Perl Hacker>->();
------------------------------
Date: 29 Jan 2003 13:57:31 -0800
From: gomac_the_1st@yahoo.co.uk (Gomac)
Subject: String to float casting?
Message-Id: <90777696.0301291357.3188ac57@posting.google.com>
is it possible to cast a string to a float so I can do operations such
as
if($n>=0 && $n<=16)
I know how to cast to an int, I was just wondering if it was possible
to cast to a float.
Thanks for your time.
------------------------------
Date: Wed, 29 Jan 2003 22:03:46 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Re: String to float casting?
Message-Id: <5dYZ9.89914$AV4.3428@sccrnsc01>
"Gomac" <gomac_the_1st@yahoo.co.uk> wrote in message
news:90777696.0301291357.3188ac57@posting.google.com...
> is it possible to cast a string to a float so I can do operations such
> as
>
> if($n>=0 && $n<=16)
>
I struggled with this a long time and thru many experiments. Casting is NOT
NEEDED in Perl. Do not worry about it, do not even think about it.
Dick Penny
------------------------------
Date: Wed, 29 Jan 2003 16:08:35 -0600
From: Jeff D Gleixner <glex_nospam@qwest.net>
Subject: Re: String to float casting?
Message-Id: <YfYZ9.155$TG3.110242@news.uswest.net>
Gomac wrote:
> is it possible to cast a string to a float so I can do operations such
> as
>
> if($n>=0 && $n<=16)
>
> I know how to cast to an int, I was just wondering if it was possible
> to cast to a float.
Why not try it before you post the question?
------------------------------
Date: 29 Jan 2003 22:48:26 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: String to float casting?
Message-Id: <slrnb3gmhq.cp1.abigail@alexandra.abigail.nl>
Gomac (gomac_the_1st@yahoo.co.uk) wrote on MMMCDXXXVIII September
MCMXCIII in <URL:news:90777696.0301291357.3188ac57@posting.google.com>:
() is it possible to cast a string to a float so I can do operations such
() as
()
() if($n>=0 && $n<=16)
()
() I know how to cast to an int, I was just wondering if it was possible
() to cast to a float.
Really? Considering this is Perl, not C, how do you "cast"?
Perl will treat scalars as strings, if you use them as strings.
It will consider scalars to be numbers (usually doubles, but ints
if the context demands ints), if you use them as numbers.
In the code above, you use $n as it were a number. In that case.
Perl will do as if $n is a number.
Abigail
--
perl -we '$_ = q ?4a75737420616e6f74686572205065726c204861636b65720as?;??;
for (??;(??)x??;??)
{??;s;(..)s?;qq ?print chr 0x$1 and \161 ss?;excess;??}'
------------------------------
Date: 29 Jan 2003 14:21:37 -0800
From: csejl@yahoo.com (James Lee)
Subject: why do I need to reload if I 'back' to my page?
Message-Id: <146277ca.0301291421.4374f51@posting.google.com>
Hi,
I have a script (script 1) that gets all the information and calls
another script (script 2) do the real work. After script 2 has
successfully run, I press back button on my browser to go back to
script 1. For some reason, I can't just run it again right away. I
have to reload the page (it resets all the values) and then fill out
all the information again. Can someone shed some light on this?
Thanks.
-j.
------------------------------
Date: 29 Jan 2003 22:51:50 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: why do I need to reload if I 'back' to my page?
Message-Id: <slrnb3gmo6.cp1.abigail@alexandra.abigail.nl>
James Lee (csejl@yahoo.com) wrote on MMMCDXXXVIII September MCMXCIII in
<URL:news:146277ca.0301291421.4374f51@posting.google.com>:
== Hi,
==
== I have a script (script 1) that gets all the information and calls
== another script (script 2) do the real work. After script 2 has
== successfully run, I press back button on my browser to go back to
== script 1. For some reason, I can't just run it again right away. I
== have to reload the page (it resets all the values) and then fill out
== all the information again. Can someone shed some light on this?
Go read the HTTP RFC. Going "back" typically doesn't result in the browser
re-requesting the object from the server. But this has absolutely nothing
to do with Perl.
Followups set.
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
!$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCIII=>=>=>=>=>=>=>=>'
------------------------------
Date: Wed, 29 Jan 2003 12:19:14 -0800
From: swen <swen@news.com>
Subject: wondering why this doesn't work
Message-Id: <3E383742.429F9A60@news.com>
file A.pm:
----------
package A;
$var = "I was set in A";
1;
file B.pm:
----------
package B;
use A;
$A::var = "I was set in B";
1;
file C.pm:
----------
package C;
use A;
require B;
sub print {
print "value was set to: ".$A::var;
}
1;
file run.pl:
----------
use C;
&C::print();
running run.pl prints "value was set to: I was set in A". so when print
is called it doesn't read the value of $A::var as modified in package B.
why not?
------------------------------
Date: Wed, 29 Jan 2003 22:18:53 +0100
From: "Michael Peuser \(h\)" <post@mpeuser.de>
Subject: Re: wondering why this doesn't work
Message-Id: <b19ge2$887$07$1@news.t-online.com>
"swen" <swen@news.com> schrieb im Newsbeitrag
news:3E383742.429F9A60@news.com...
> file A.pm:
> ----------
> package A;
> $var = "I was set in A";
> 1;
>
> file B.pm:
> ----------
> package B;
> use A;
> $A::var = "I was set in B";
> 1;
>
> file C.pm:
> ----------
> package C;
> use A;
> require B;
> sub print {
> print "value was set to: ".$A::var;
> }
> 1;
>
> file run.pl:
> ----------
> use C;
> &C::print();
>
>
> running run.pl prints "value was set to: I was set in A". so when print
> is called it doesn't read the value of $A::var as modified in package B.
> why not?
>
Funny - seems that another modul B is used - if you call the modul BB ratehr
than B it works as expected.
Kindly Mike
------------------------------
Date: Wed, 29 Jan 2003 15:51:21 -0600
From: Jeff D Gleixner <glex@qwest.net>
Subject: Re: wondering why this doesn't work
Message-Id: <O%XZ9.150$TG3.108118@news.uswest.net>
> Funny - seems that another modul B is used - if you call the modul BB ratehr
> than B it works as expected.
> Kindly Mike
Right. Do a "perldoc B" to see what it does.
--
Jeff Gleixner
Bumper Sticker of the moment:
Keep honking while I reload.
------------------------------
Date: 29 Jan 2003 16:50:59 -0500
From: clists@perrin.socsci.unc.edu (Andrew Perrin (CLists))
Subject: Re: wondering why this doesn't work
Message-Id: <84isw7fwvw.fsf@perrin.socsci.unc.edu>
swen <swen@news.com> writes:
[snip]
> require B;
That's because there's a standard B.pm which is part of the perl package:
aperrin@perrin:~$ perldoc B
B(3) User Contributed Perl Documentation B(3)
NAME
B - The Perl Compiler
SYNOPSIS
use B;
Summary: use a different name (not B.pm).
--
----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists@perrin.socsci.unc.edu * andrew_perrin (at) unc.edu
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4484
***************************************