[22262] in Perl-Users-Digest
Perl-Users Digest, Issue: 4483 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 29 14:06:53 2003
Date: Wed, 29 Jan 2003 11: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: 4483
Today's topics:
Re: alarm() implemented? - nevermind, different questio <spark@dcwis.nodurnspam.com>
Re: alarm() implemented? - nevermind, different questio <mothra@nowhereatall.com>
alarm() implemented? <spark@dcwis.nodurnspam.com>
Re: APL's relation to perl (Kevin Cline)
Re: array slicing (Anno Siegel)
Assign New Values in Loop After Submit (Hunter)
Re: Assign New Values in Loop After Submit <glex_nospam@qwest.net>
file limitation and if -e option?!! (JZ)
Re: hash ordering. <spikey-wan@bigfoot.com>
Re: How to search a file (newbie) (Ben Morrow)
Re: How to search a file (newbie) <usenet@dwall.fastmail.fm>
Re: How to search a file (newbie) <REMOVEsdnCAPS@comcast.net>
Re: Need help with sendmail routine <file attachments> (Tara)
Re: Next problem. <usenet@tinita.de>
Re: Next problem. (Tad McClellan)
Re: Next problem. <spikey-wan@bigfoot.com>
Re: Next problem. <jurgenex@hotmail.com>
Re: Next problem. (Ben Morrow)
perl data structure question (bad_knee)
purpose of threads? (jake johnson)
Re: purpose of threads? <nobull@mail.com>
Re: purpose of threads? (Ben Morrow)
Tie::IxHash <spikey-wan@bigfoot.com>
Re: Tie::IxHash <nobull@mail.com>
Re: Tie::IxHash <bigj@kamelfreund.de>
Re: Timestamps to thousandths of a second. <uri@stemsystems.com>
Re: XML parser (Tad McClellan)
Re: XML parser (Ben Morrow)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 29 Jan 2003 10:56:17 -0600
From: spark <spark@dcwis.nodurnspam.com>
Subject: Re: alarm() implemented? - nevermind, different question
Message-Id: <MPG.18a1c392900105c4989696@news-central.giganews.com>
In article <MPG.18a1bbf086a3da8a989695@news-central.giganews.com>,
spark@dcwis.nodurnspam.com says...
> Is alarm() implemented for Win32 in the latest version of Perl?
>
Nevermind, I see it isn't.
I have a script that uses system() to execute a command line which
compacts an Access database. This command never returns anything other
than 0, on success or failure. Generally though, if the task fails it
will just hang (return nothing). What I would like to do is create some
kind of alarm process which will wait so long for that 0 return value,
and if it doesn't get it in that time, just continue with the rest of
the script. If anyone can tell me of a way I might do that or a module
that will help me, I'd appreciate it.
thanks in advance
spark
------------------------------
Date: Wed, 29 Jan 2003 11:01:00 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: alarm() implemented? - nevermind, different question
Message-Id: <3e382413$1@usenet.ugs.com>
> 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.
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 10:23:37 -0600
From: spark <spark@dcwis.nodurnspam.com>
Subject: alarm() implemented?
Message-Id: <MPG.18a1bbf086a3da8a989695@news-central.giganews.com>
Is alarm() implemented for Win32 in the latest version of Perl?
------------------------------
Date: 29 Jan 2003 10:47:54 -0800
From: kcline17@hotmail.com (Kevin Cline)
Subject: Re: APL's relation to perl
Message-Id: <ba162549.0301291047.18d1789e@posting.google.com>
Michele Dondi <bik.mido@tiscalinet.it> wrote in message news:<eeso2v44e4f3o8ih3qik2b2vllk12am846@4ax.com>...
> On Fri, 17 Jan 2003 19:11:54 GMT, Uri Guttman <uri@stemsystems.com>
> wrote:
>
> >you should take a peek at the perl 6 world. many of the apl vector
> >flavored ops are getting into perl. you will be able to convert most
> >common ops to a vector form, e.g. a scalar can be added to all elements
>
> Another OT intervention from me, but at least in this case it's a Perl
> question...
>
> To your knowledge, will Perl 6 support cartesian products and the
> possibilty of iterating over them, e.g. with a syntax roughly of the
> kind of:
>
> for my ($x,$y) ((1..3)*(1..5)) {
> # do something...
> }
How is this different from the more usual:
foreach my $x (1..3) {
foreach my $y (1..5) {
# do something ...
}
}
------------------------------
Date: 29 Jan 2003 17:26:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: array slicing
Message-Id: <b192rp$539$1@mamenchi.zrz.TU-Berlin.DE>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in comp.lang.perl.misc:
> Bart Lateur <bart.lateur@pandora.be> wrote in comp.lang.perl.misc:
> > Anno Siegel wrote:
> >
> > >print "@{[grep { $_ eq 'THREE' .. !defined } @numbers]}\n";
> >
> > I don't think the range operator will flop back to false at the end of
> > the list.
> >
> > my @numbers = ( 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE' );
> > for(\@numbers, [qw(A B C)]) {
> > print "@{[grep { $_ eq 'THREE' .. !defined } @$_]}\n";
> > }
> > -->
> > THREE FOUR FIVE
> > A B C
> >
> > Like I said... :-)
>
> Right, another reason not to use this joke in earnest.
>
> "!defined" is not an attempt to reset the operator. I would have
> used "0" or "''" instead of "!defined" if the range operator didn't
> insist in comparing a constant against $. I wanted a non-constant
> expression that returns false, and nothing simpler came to mind. In
> fact, it returns false only most of the time :)
I guess "do { 0 }" is what I was looking for.
print "@{[grep { $_ eq 'THREE' .. do { 0 } } @$_]}\n";
It leaves the ".." operator hanging, as it were, but that's the least
problem of this obfuscated bit of code.
Anno
------------------------------
Date: 29 Jan 2003 09:45:53 -0800
From: dave_h4@yahoo.com (Hunter)
Subject: Assign New Values in Loop After Submit
Message-Id: <27ad91d2.0301290945.3acf18c2@posting.google.com>
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. This is
what I have, but it does not work:
input form:
<p>Question1</p>
<input type="radio" name="question1" value="Y">Yes
<input type="radio" name="question1" value="N" checked>No
processing:
if ($p{question1} = "N") {
$p{question1} = "No";
} else {
$p{question1} = "Yes";
}
if ($p{question2} = "N") {
$p{question2} = "No";
} else {
$p{question2} = "Yes";
}
if ($p{question3} = "N") {
$p{question3} = "No";
} else {
$p{question3} = "Yes";
}
output:
<td colspan="2" class="tdheadingsleftform">$p{question1}</td>
Thanks gurus -
------------------------------
Date: Wed, 29 Jan 2003 12:53:30 -0600
From: Jeff D Gleixner <glex_nospam@qwest.net>
Subject: Re: Assign New Values in Loop After Submit
Message-Id: <4pVZ9.60$TG3.77764@news.uswest.net>
Hunter 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. This is
> what I have, but it does not work:
>
> input form:
> <p>Question1</p>
> <input type="radio" name="question1" value="Y">Yes
> <input type="radio" name="question1" value="N" checked>No
>
> processing:
>
> if ($p{question1} = "N") {
> $p{question1} = "No";
[...]
'=' is to set something equal to something else, you want to compare a string's
equality to another string. Hint 'eq'.
------------------------------
Date: 29 Jan 2003 11:01:56 -0800
From: ibm_97@yahoo.com (JZ)
Subject: file limitation and if -e option?!!
Message-Id: <10bc841c.0301291101.552282a4@posting.google.com>
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") {
....
}
When the file is over 2GB, Perl cannot detect this file even though
file actually exists. But it's ok when file size is less than 2GB.
I got the same error by using '-f' option.
On Linux, if the file is over 2GB, the 'file <filename>' command
failed, but it worked fine on Solaris 2.8. Both OSs have unlimited
file size.
How to overcome this?
Thanks a lot!
------------------------------
Date: Wed, 29 Jan 2003 16:33:22 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: hash ordering.
Message-Id: <b18vq8$p88$1@newshost.mot.com>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:SuSZ9.68$cu4.38@nwrddc02.gnilink.net...
> Richard S Beckett wrote:
> > Is there any way to force a hash to be in the same order as you
> > defined it?
>
> Hashes are mappings. They do not have an order. Asking for the order of a
> hash is like asking for the weight of the color green.
But a litre of green weighs just over a kilo. ;-)
------------------------------
Date: Wed, 29 Jan 2003 17:40:07 +0000 (UTC)
From: mauzo@ux-ma160-13.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: How to search a file (newbie)
Message-Id: <b193ln$9e4$1@wisteria.csv.warwick.ac.uk>
helgi@decode.is wrote:
>On Wed, 29 Jan 2003 07:47:44 -0600, tadmc@augustmail.com
>(Tad McClellan) wrote:
>
>>Djm <dmuren@start.no> wrote:
>>> I also
>>> want to print the all text between f.eks. utv2:3 and utv2:4.
>> ^^^^^^^
>>What does "f.eks." mean?
>
>It means "for eksempel" in Nordic languages, which
>surprise, surprise means the the same as f.ex. or
>"for example" in English. The OP appears to be Norwegian.
The English abbreviation for 'for example' is 'e.g.'.
Ben
------------------------------
Date: Wed, 29 Jan 2003 18:02:06 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: How to search a file (newbie)
Message-Id: <Xns931284999E67Adkwwashere@216.168.3.30>
Ben Morrow <mauzo@ux-ma160-13.csv.warwick.ac.uk> wrote on 29 Jan 2003:
> The English abbreviation for 'for example' is 'e.g.'.
I thought it was Latin, "exempli gratia". :-)
------------------------------
Date: Wed, 29 Jan 2003 13:01:35 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: How to search a file (newbie)
Message-Id: <Xns93128F05597B4sdn.comcast@216.166.71.239>
"David K. Wall" <usenet@dwall.fastmail.fm> wrote in
news:Xns931284999E67Adkwwashere@216.168.3.30:
> Ben Morrow <mauzo@ux-ma160-13.csv.warwick.ac.uk> wrote on 29 Jan 2003:
>
>> The English abbreviation for 'for example' is 'e.g.'.
>
> I thought it was Latin, "exempli gratia". :-)
>
It is. But nobody uses "f.ex." in English.
--
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
------------------------------
Date: 29 Jan 2003 10:47:03 -0800
From: tararse@hotmail.com (Tara)
Subject: Re: Need help with sendmail routine <file attachments>
Message-Id: <27eb673f.0301291047.38e29923@posting.google.com>
Cool, thanks for these little enhancements! :))
The big question for me is still how do I get a file attachment to
pass through from a form page and send out using the existing Perl
code I have below? I'm not sure how to do this.
i.e. <input type="file" name="attachment" size="30" style="background:
#FFFFFF; border-color: black; border-width: 0px">
Tara
"Janek Schleicher" <bigj@kamelfreund.de> wrote in message news:<pan.2003.01.29.08.49.12.410198@kamelfreund.de>...
> On Wed, 29 Jan 2003 00:52:35 +0000, Tara wrote:
>
> > Hello, I have this simple script that is submitted from a form that I
> > want to add file attachments too. How can I work in this process
> > under the sub SendSubmission routine? I know it has something to do
> > with encode_base64, but I have no idea on how to implement this. Can
> > someone please help?
>
> I would recommend to use any of the Mail::
> modules.
>
> As there also some other thing odd,
> I'll try to give some hints.
>
> > #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> >
> > [snipped some declarations]
> >
> > sub SendSubmission {
> > open (MAIL,"|$MailProgram -t");
>
> _Always_ check the result of an open statement:
> open MAIL, "|$MailProgram -t" or die "Couldn't open $MailProgram";
>
> > print MAIL "To: $YourEmail\n";
> > print MAIL "From: $Email\n";
> > print MAIL "Subject: $Subject1\n";
> Here's a shorter way to express it:
>
> print MAIL <<HEADER;
> To: $YourEmail
> From: $Email
> Subject: $Subject1
> HEADER
>
>
> Or
>
> print MAIL join "\n", "To: $YourMail",
> "From: $Email",
> "Subject: $Subject1";
>
> > print MAIL "First Name: $first_name\n";
> > print MAIL "Last Name: $last_name\n";
>
> Are you sure that these fields are valid fields for an email header ?
>
> > [...]
> >
> > sub GetDate {
> > @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
> > @months = ('01','02','03','04','05','06','07','08','09','10','11','12');
> > ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> > localtime(time);
> > $year = $year+1900;
> > $Date = "$days[$wday] $months[$mon]/$mday/$year";
> > }
>
> A simpler way to get that date format is the POSIX way:
> use POSIX qw/strftime/;
>
> my $date = strftime "%A %B/%d/%Y", localtime;
>
> >
> > # _________________________________________________________
> >
> > sub ReadParse { local (*in) = @_ if @_;
> > local ($i, $key, $val); if ( $ENV{'REQUEST_METHOD'} eq "GET" )
> > {$in = $ENV{'QUERY_STRING'};}
> > elsif ($ENV{'REQUEST_METHOD'} eq "POST")
> > {read(STDIN,$in,$ENV{'CONTENT_LENGTH'});}
> > else {
> > $in = ( grep( !/^-/, @ARGV )) [0];
> > $in =~ s/\\&/&/g; } @in = split(/&/,$in);
> > foreach $i (0 .. $#in) {
> > $in[$i] =~ s/\+/ /g;
> > ($key, $val) = split(/=/,$in[$i],2);
> > $key =~ s/%(..)/pack("c",hex($1))/ge;
> > $val =~ s/%(..)/pack("c",hex($1))/ge;
> > $in{$key} .= "\0" if (defined($in{$key}));
> > $in{$key} .= $val; } return length($in); }
> >
>
> That's really something for that modules like CGI or URI are done for.
>
> > # _________________________________________________________
> >
> > sub CheckEmailAddressFormat {
> > if (index($Email, "@") < 1) {&DoEmailError;}
> > if (index($Email, ".") < 1) {&DoEmailError;}
> > if (index($Email, " ") > -1) {&DoEmailError;}
> > }
>
> A good module checking email addresses is e.g.
> Email::Valid
>
> However, I've never used the index method in Perl,
> as you'll nearly never need it.
> If you want to assert that a variable must have an @ and a . inside,
> use a regexp.
>
> unless ($Email =~ /[@.]/) { ... }
>
> Similiar check for a whitespace:
>
> if ($Email =~ /\s/) { ... }
>
> But note that a " " is a valid character in an email address,
> e.g.:
> "Janek Schleicher" <bigj@kamelfreund.de>
>
>
>
> Greetings,
> Janek
------------------------------
Date: 29 Jan 2003 16:20:42 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Next problem.
Message-Id: <b18v0q$10frj5$1@ID-24002.news.dfncis.de>
Tassilo v. Parseval <tassilo.parseval@localhost.localhost> wrote:
> Also sprach Richard S Beckett:
>>
>> next if ($_ eq ('Fred' || 'Wilma'));
> This shortcut of yours looks tempting but doesn't do what you expect.
> ('Fred' || 'Wilma')
> will evaluate to something true (possibly 1) so you end up comparing
> $_ eq 1
from perlop:
| The "||" and "&&" operators differ from C's in that,
| rather than returning 0 or 1, they return the last value
| evaluated.
so it evaluates to:
$_ eq 'Fred'
regards, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Wed, 29 Jan 2003 10:40:43 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Next problem.
Message-Id: <slrnb3g10b.b6m.tadmc@magna.augustmail.com>
Jürgen Exner <jurgenex@hotmail.com> wrote:
> Richard S Beckett wrote:
>> next if ($_ eq ('Fred' || 'Wilma'));
> BTW: I think if you would have used warnings then perl would have warned you
> about his blunder.
Nope, warnings won't catch that one.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 29 Jan 2003 16:34:38 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: Next problem.
Message-Id: <b18vsl$pbt$1@newshost.mot.com>
> You are mixing boolean values and text.
> In ('Fred' || 'Wilma') you are applying a boolean operator to two text
> strings. Those strings are not empty. That means their boolean value is
TRUE
> (simplifying here).
> So you are computing (TRUE || TRUE) which of course is TRUE.
> And then you are comparing $_ with TRUE
> ($_ eq TRUE)
> I doubt this is what you meant.
> BTW: I think if you would have used warnings then perl would have warned
you
> about his blunder.
I _always_ use strict and warnings.
R.
------------------------------
Date: Wed, 29 Jan 2003 16:50:34 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Next problem.
Message-Id: <uDTZ9.23587$uR.5746@nwrddc01.gnilink.net>
Tad McClellan wrote:
> Jürgen Exner <jurgenex@hotmail.com> wrote:
>> Richard S Beckett wrote:
>
>>> next if ($_ eq ('Fred' || 'Wilma'));
>
>> BTW: I think if you would have used warnings then perl would have
>> warned you about his blunder.
>
> Nope, warnings won't catch that one.
Hmm, I wonder if they should.
After all, if I try to e.g. add two strings, then they will warn me that
probably I'm doing something stupid. Why not warn the user if he tries to
apply a boolean operation (instead of numerical operation) to text strings,
too?
Considering that this mistake pops up about every month it may be worth
thinking about a change in warnings.
jue
------------------------------
Date: Wed, 29 Jan 2003 17:46:50 +0000 (UTC)
From: mauzo@ux-ma160-13.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Next problem.
Message-Id: <b1942a$9kk$1@wisteria.csv.warwick.ac.uk>
"Jürgen Exner" <jurgenex@hotmail.com> wrote:
>Tad McClellan wrote:
>> Jürgen Exner <jurgenex@hotmail.com> wrote:
>>> Richard S Beckett wrote:
>>
>>>> next if ($_ eq ('Fred' || 'Wilma'));
>>
>>> BTW: I think if you would have used warnings then perl would have
>>> warned you about his blunder.
>>
>> Nope, warnings won't catch that one.
>
>Hmm, I wonder if they should.
>After all, if I try to e.g. add two strings, then they will warn me that
>probably I'm doing something stupid. Why not warn the user if he tries to
>apply a boolean operation (instead of numerical operation) to text strings,
>too?
>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.
Ben
------------------------------
Date: 29 Jan 2003 10:56:29 -0800
From: bl8n8r@yahoo.com (bad_knee)
Subject: perl data structure question
Message-Id: <e817ca4d.0301291056.7cc005ef@posting.google.com>
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. The question was asked of me today just
what exactly this is, and I realized I didn't know. I
had a good chuckle at my ignorance. I've learned perl
by gleaning from examples, source code, FAQs, and just
plain "doing". Particulars relating to the questions
I'm posing, I simply haven't committed to memory.
So a couple questions:
A - What type of data structure is this?
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?)
Thanks for your time,
bl8n8r
###############################################################
# 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
};
print "name:$DirEnts[$i]->{n} type:$DirEnts[$i]->{t}\n";
------------------------------
Date: 29 Jan 2003 09:59:46 -0800
From: jake@omnimode.com (jake johnson)
Subject: purpose of threads?
Message-Id: <8897a0de.0301290959.33c92fed@posting.google.com>
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?
In yesterday's interivew on oreillynet.com, Lincoln Stein said that a
major wish of his was to have a reliable thread implementation in
Perl. What I've read says that threads aren't officially available
yet and this seems to comport with what Stein's comment. 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, but if you can point me to a URL perhaps, that would be
appreciated. What I find in perldoc is over my head and not
introductory. For one thing, are threads an alternative to fork?
thanks,
- Jake
------------------------------
Date: 29 Jan 2003 18:24:45 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: purpose of threads?
Message-Id: <u9of5zvmoi.fsf@wcl-l.bham.ac.uk>
jake@omnimode.com (jake johnson) writes:
> 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?
Servers and GUIs are the two main areas. (Note I'm not talking about
Perl threads here, just threads in general).
> In yesterday's interivew on oreillynet.com, Lincoln Stein said that a
> major wish of his was to have a reliable thread implementation in
> Perl. What I've read says that threads aren't officially available
> yet and this seems to comport with what Stein's comment. This has
> piqued my curiosity about what threads are and why people are aching
> to use them.
Perhaps, because they are one thing in which Java is streets ahead of
Perl?
> I haven't been able to find any 'threads for newbies'
> discussions,
Perhaps threads are not for newbies.
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.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 29 Jan 2003 18:57:13 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: purpose of threads?
Message-Id: <b19869$cfk$1@wisteria.csv.warwick.ac.uk>
jake@omnimode.com (jake johnson) wrote:
> I haven't been able to find any 'threads for newbies'
>discussions, but if you can point me to a URL perhaps, that would be
>appreciated. What I find in perldoc is over my head and not
>introductory.
perldoc perlthrtut (new in 5.8.0).
Perl5.8's new ithreads are much more newbie-friendly than the old
5.005threads, but threaded programming is still a tricky area.
> For one thing, are threads an alternative to fork?
Yes, that is basically what they are: a lightweight alternative to fork.
ithreads is also how fork is implemented in perl for Win32: that is what
they were originally invented for.
I would _strongly_ recommend against trying to use threads in perl pre-5.8.
Ben
------------------------------
Date: Wed, 29 Jan 2003 16:42:01 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Tie::IxHash
Message-Id: <b190ae$pg8$1@newshost.mot.com>
Chaps and chapesses, ;-)
I read perldoc -q remember the order
It told me that:
tie(%myhash, Tie::IxHash);
should work.
I defined my hash of hashes, then put:
tie (%vars, Tie::IxHash);
and got the following error:
Bareword "Tie::IxHash" not allowed while "strict subs" in use at v06b.pl
line 101.
As usual I bet it's me that did something wrong, but I have no idea what.
Please hit me with that cluestick again!
R.
------------------------------
Date: 29 Jan 2003 17:35:20 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Tie::IxHash
Message-Id: <u9wuknvoyv.fsf@wcl-l.bham.ac.uk>
"Richard S Beckett" <spikey-wan@bigfoot.com> writes:
> I read perldoc -q remember the order
>
> It told me that:
>
> tie(%myhash, Tie::IxHash);
> Bareword "Tie::IxHash" not allowed while "strict subs" in use at v06b.pl
> line 101.
>
> As usual I bet it's me that did something wrong, but I have no idea what.
Actually you have found an error in the FAQ. The FAQ should not
include example code that only compiles without strict subs.
And your prize for finding the error is that you get to report it to
the FAQ maintainer. This means that you'll be able to say from now on
that you are a contributor to Perl (albeit a contributor of only two
characters).
> Please hit me with that cluestick again!
You need to put quotes around the string Tie::IxHash.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 29 Jan 2003 17:38:28 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Tie::IxHash
Message-Id: <pan.2003.01.29.16.14.02.488429@kamelfreund.de>
On Wed, 29 Jan 2003 16:42:01 +0000, Richard S Beckett wrote:
> I read perldoc -q remember the order
>
> It told me that:
>
> tie(%myhash, Tie::IxHash);
>
> should work.
>
> I defined my hash of hashes, then put:
>
> tie (%vars, Tie::IxHash);
>
> and got the following error:
>
> Bareword "Tie::IxHash" not allowed while "strict subs" in use at v06b.pl
> line 101.
This FAQ seems to be a bit older -- We'll have to change it!
In earlier versions of Perl, an unknown[from Perl's view] word had been
regarded simply as a string, so you could leave out the quoting chars ' or
". As an unknown word also can be a simple typo (and in fact often it is),
this can lead to hard finding errors. So it's nowadays strongly
recommended to use use strict; that forbids such barewords (and many other
dangerous constructs).
To solve your problem, you'll have to write instead
tie %vars, 'Tie::IxHash';
# or
tie my %vars, 'Tie::IxHash';
# if %vars had not been already declared
Best Wishes,
Janek
------------------------------
Date: Wed, 29 Jan 2003 17:27:10 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Timestamps to thousandths of a second.
Message-Id: <x7vg07dfyq.fsf@mail.sysarch.com>
>>>>> "JG" == Jeremy Gooch <jeremy.gooch@axa-im.com> writes:
JG> The solution I've gone for combines calls from Time::HiRes and
JG> Date::Calc:-
JG> # Get the timestamp (down to microseconds)
JG> ($secs_since_epoch, $microseconds) = gettimeofday();
JG> ($year, $month, $day, $hour, $min, $sec) =
JG> Time_to_Date($secs_since_epoch);
JG> $stamp = sprintf("%04d%02d%02d%02d%02d%02d",$year,$month,$day,$hour,$min,$sec);
strftime is your friend.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Wed, 29 Jan 2003 10:37:00 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: XML parser
Message-Id: <slrnb3g0pc.b6m.tadmc@magna.augustmail.com>
Flash Fan <flash0fan@hotmail.com> wrote:
> I am using XML::Parser version 2.30 to parse the following XML.
That is not XML. Perhaps you meant "XML fragment"?
In case you didn't know about it, there is also a mailing list
specifically for discussing the processing of XML using Perl:
http://listserv.ActiveState.com/mailman/listinfo/perl-xml
> I can
> get the name attributes,
That would be a trick, seeing as the name element does not _have_
any attributes...
> but the sessions are empty.
Yes they are. Is that a problem?
> Could any expert
> give me any advice?
Advice about what, exactly?
You never said what it is that you want to do.
If you had showed us your code, we could have helped you fix it...
I'll assume you meant to ask an actual question:
How can I access attribute values using XML::Parser?
-----------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use XML::Parser;
my $xml = <<ENDXML;
<root>
<name>SP 500 March,2003</name>
<sessions>
<session1 open="15:45:00" close=" 8:15:00" days="SMTWR"/>
<session2 open=" 8:30:00" close="15:15:00" days="MTWRF"/>
</sessions>
</root>
ENDXML
my $p = new XML::Parser(Handlers => {Start => \&handle_start});
$p->parse($xml);
sub handle_start {
my($expat, $gi, %attr) = @_;
print "<$gi> has these attributes:\n";
print qq/ $_ = "$attr{$_}"\n/ foreach sort keys %attr;
}
-----------------------------------
On an unrelated note, element names with "numbers" like you
have above (session1, session2) is a red flag that indicates
you could probably make a better document model.
<sessions>
<session open="15:45:00" close=" 8:15:00" days="SMTWR"/>
<session open=" 8:30:00" close="15:15:00" days="MTWRF"/>
</sessions>
Will work fine, and be scalable to any number of sessions.
Your application processing can simply count the <session>s
to determine which is "1" and which is "2".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 29 Jan 2003 17:50:57 +0000 (UTC)
From: mauzo@ux-ma160-13.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: XML parser
Message-Id: <b194a1$9pc$1@wisteria.csv.warwick.ac.uk>
flash0fan@hotmail.com (Flash Fan) wrote:
>I am using XML::Parser version 2.30 to parse the following XML.
I would recommend using XML::SAX instead, if you can. It is more flexible.
Ben
------------------------------
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 4483
***************************************