[23213] in Perl-Users-Digest
Perl-Users Digest, Issue: 5434 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 3 18:05:49 2003
Date: Wed, 3 Sep 2003 15:05:09 -0700 (PDT)
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, 3 Sep 2003 Volume: 10 Number: 5434
Today's topics:
Re: [newbie] how to get just the first value of a hash? (Anno Siegel)
Re: [newbie] how to get just the first value of a hash? <uri@stemsystems.com>
Re: [newbie] how to get just the first value of a hash? (Anno Siegel)
Re: [newbie] how to get just the first value of a hash? <kkeller-usenet@wombat.san-francisco.ca.us>
Re: [newbie] how to get just the first value of a hash? (Anno Siegel)
Re: [newbie] how to get just the first value of a hash? <uri@stemsystems.com>
Re: A suggestion for perldoc <yanoff@STOP-SPAMMINGyahoo.com>
Re: A suggestion for perldoc <bik.mido@tiscalinet.it>
Re: A suggestion for perldoc (Anno Siegel)
can perl write to a usb port com3 device?? <B.S.@hsc.vcu.edu>
Getting directory sizes on win32 (Jeffrey Ellin)
grep'd list as loop parameter <coo_t2-NO-LIKE-SPAM@yahoo.com>
Re: grep'd list as loop parameter <postmaster@castleamber.com>
Re: grep'd list as loop parameter <coo_t2-NO-LIKE-SPAM@yahoo.com>
Re: grep'd list as loop parameter (Anno Siegel)
Re: grep'd list as loop parameter (Anno Siegel)
Re: grep'd list as loop parameter <coo_t2-NO-LIKE-SPAM@yahoo.com>
Re: grep'd list as loop parameter <postmaster@castleamber.com>
Re: grep'd list as loop parameter <postmaster@castleamber.com>
Re: Help:Why does eval add a 1 behind evaluations? (Joe Smith)
Re: Help:Why does eval add a 1 behind evaluations? (Tad McClellan)
Re: IN SEARCH OF ELEGANT CODE: Setting a hash value to (Greg)
Re: Modify during a while statement (Tad McClellan)
Re: Modify during a while statement (Tad McClellan)
Re: perl CGI related: form post failure (Tad McClellan)
Perl6 internals Archives? (John M. Gamble)
Re: Perl6 internals Archives? (Anno Siegel)
Replacing a line of text in an HTML file ??? <rodney1@bellsouth.net>
Re: Replacing a line of text in an HTML file ??? <postmaster@castleamber.com>
Re: Silly push tricks <cwilbur@mithril.chromatico.net>
Re: The life of $! (Joe Smith)
Re: What ever happened to comp.lang.perl ? <tcurrey@no.no.no.i.said.no>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 3 Sep 2003 19:35:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <bj5fqq$f43$4@mamenchi.zrz.TU-Berlin.DE>
Tina Mueller <usenet@expires12.2003.tinita.de> wrote in comp.lang.perl.misc:
> Gunnar Hjalmarsson wrote:
> > Guest1 wrote:
> >> I have a hash of arrays, and I would like to get the length of any
> >> of these arrays. I said first instead to say any of them (because
> >> all the arrays have the same length), More clear my question now?
>
> > Suppose so. Assuming that you by "length" mean the number of elements,
> > this is one way:
>
> > print scalar @{$myhash{(keys %myhash)[0]}};
>
> or maybe one of these:
> print scalar @{ (values %myhash)[0] };
> print $#{ (values %myhash)[0] }+1;
> print $#{ (each %myhash)[1] }+1;
> print @{ (%myhash)[1] }+0;
The "each"-solution is different from the others -- it doesn't expand
all of the hash, which is good. It also leaves the hash with a not-
quite-fresh iterator, which is bad. In a one-off program it probably
doesn't matter, but in a general-purpose routine it would. Where is
uneach?
Anno
------------------------------
Date: Wed, 03 Sep 2003 19:39:45 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <x7u17tr79a.fsf@mail.sysarch.com>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
AS> The "each"-solution is different from the others -- it doesn't expand
AS> all of the hash, which is good. It also leaves the hash with a not-
AS> quite-fresh iterator, which is bad. In a one-off program it probably
AS> doesn't matter, but in a general-purpose routine it would. Where is
AS> uneach?
it is called keys.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class
------------------------------
Date: 3 Sep 2003 19:47:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <bj5ggf$f43$5@mamenchi.zrz.TU-Berlin.DE>
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
>
> AS> The "each"-solution is different from the others -- it doesn't expand
> AS> all of the hash, which is good. It also leaves the hash with a not-
> AS> quite-fresh iterator, which is bad. In a one-off program it probably
> AS> doesn't matter, but in a general-purpose routine it would. Where is
> AS> uneach?
>
> it is called keys.
Yes and no. "keys" resets the iterator. The mythical uneach restores it,
so the next call to each returns what it would have before. A tied hash
could implement it.
Anno
------------------------------
Date: Wed, 3 Sep 2003 13:52:39 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <nak5jb.5rs.ln@goaway.wombat.san-francisco.ca.us>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On 2003-09-03, Uri Guttman <uri@stemsystems.com> wrote:
>
> it is called keys.
In scalar context, will keys run through the whole hash? If so,
then it doesn't sound the same as Anno's suggested ''uneach''.
- --keith
- --
kkeller-mmmspam@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iEYEARECAAYFAj9WVJYACgkQhVcNCxZ5ID9AQQCfUlN7rTA5utK0D2RJ/02BYHoi
ZOQAn3WLbI9/fx8/cexin2qQu2tcrSJ9
=ZXbe
-----END PGP SIGNATURE-----
------------------------------
Date: 3 Sep 2003 21:07:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <bj5l66$jbg$2@mamenchi.zrz.TU-Berlin.DE>
Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> wrote in comp.lang.perl.misc:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> On 2003-09-03, Uri Guttman <uri@stemsystems.com> wrote:
> >
> > it is called keys.
>
> In scalar context, will keys run through the whole hash? If so,
> then it doesn't sound the same as Anno's suggested ''uneach''.
No, it won't. It does hash magic and retrieves the number of keys
directly. It also resets each-iteration.
Anno
------------------------------
Date: Wed, 03 Sep 2003 21:09:14 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <x7llt5r346.fsf@mail.sysarch.com>
>>>>> "KK" == Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> writes:
KK> On 2003-09-03, Uri Guttman <uri@stemsystems.com> wrote:
>>
>> it is called keys.
KK> In scalar context, will keys run through the whole hash? If so,
KK> then it doesn't sound the same as Anno's suggested ''uneach''.
from doop.c:
if (! SvTIED_mg((SV*)keys, 'P'))
i = HvKEYS(keys);
else {
i = 0;
/*SUPPRESS 560*/
while (hv_iternext(keys)) i++;
}
and HvKEYS is a macro that gets the key count from the hv. so it looks
like it is O(1)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Wed, 03 Sep 2003 14:44:05 -0500
From: Scott Yanoff <yanoff@STOP-SPAMMINGyahoo.com>
Subject: Re: A suggestion for perldoc
Message-Id: <3f564486$0$40213$39cecf19@news.twtelecom.net>
Charlton Wilbur wrote:
> http://perl.faq-by-day.org/
I was able to find a Perl Tip of the Day list at:
http://www.perlcoders.com/main/tipoftheday.html
Cheers,
--
-Scott
yanoff@STOP-SPAMMINGyahoo.com | http://www.yanoff.org | AOL IM: SAY KJY
------------------------------
Date: 3 Sep 2003 19:51:14 GMT
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: A suggestion for perldoc
Message-Id: <t05flv8mcnd8mm3pqkp08g6ejiomb2j57g@4ax.com>
On Sun, 31 Aug 2003 18:00:03 GMT, Charlton Wilbur
<cwilbur@mithril.chromatico.net> wrote:
>>>>>> "MD" == Michele Dondi <bik.mido@tiscalinet.it> writes:
>
> MD> So I wonder if it may be worth to add a "tip of the day"
> MD> feature to perldoc, say by means of 'perldoc -T': of course
> MD> there would be some overlap with other pieces of
> MD> documentation, but indeed I for one would consider it useful!
>
>There is a service that picks one of the Perl FAQ questions each day
>and e-mails it to a mailing list. Perhaps you should subscribe.
I know! FAQ entries used to be posted regularly here too, as someone
else mentioned. However, as I said, my (vague) idea was of something
somehow different from a (the) FAQ.
I think that the tip-of-the-day feature, would one exist, should focus
on advanced, hardly known, cool (not or not necessarily misunderstood,
as is more common in a FAQ) features possibly introduced in recent
versions of the language.
>Alternately, build the infrastructure yourself and ask people to
>donate tips. I'm not sure how useful this would be for perldoc --
>since the people who find this sort of thing useful are unlikely to
>stumble upon it -- but there are hundreds of joke-, picture-, word-,
>and tip-of-the-day mailing lists out there.
I mostly agree. However I was thinking that while you generally have
to perform a well determined task and you learn while working on it,
OTOH sometimes you happen to wonder what other cool trick is hidden in
Perl that you still don't know and maybe you have some spare time, so
this might be an occasion for a perldoc based tip of the day.
Of course it wouldn't be of MUCH use. Yet, IMHO, it would be of SOME
use...
Thanks,
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: 3 Sep 2003 21:00:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: A suggestion for perldoc
Message-Id: <bj5kpg$jbg$1@mamenchi.zrz.TU-Berlin.DE>
Michele Dondi <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
> On Sun, 31 Aug 2003 18:00:03 GMT, Charlton Wilbur
> <cwilbur@mithril.chromatico.net> wrote:
>
> >>>>>> "MD" == Michele Dondi <bik.mido@tiscalinet.it> writes:
> >
> > MD> So I wonder if it may be worth to add a "tip of the day"
> > MD> feature to perldoc, say by means of 'perldoc -T': of course
> > MD> there would be some overlap with other pieces of
> > MD> documentation, but indeed I for one would consider it useful!
> >
> >There is a service that picks one of the Perl FAQ questions each day
> >and e-mails it to a mailing list. Perhaps you should subscribe.
>
> I know! FAQ entries used to be posted regularly here too, as someone
> else mentioned. However, as I said, my (vague) idea was of something
> somehow different from a (the) FAQ.
>
> I think that the tip-of-the-day feature, would one exist, should focus
> on advanced, hardly known, cool (not or not necessarily misunderstood,
> as is more common in a FAQ) features possibly introduced in recent
> versions of the language.
The hard part, it seems to me, is generating an initial mass of such
tips. If it's going to be run in a fortune-cookie manner, you need a
hundred, better more. They would have to be short, too. I can't think
of too many of those, but then I'm just one. I think the 03 thing to
do is set up a wiki.
Anno
------------------------------
Date: Wed, 03 Sep 2003 16:11:00 -0400
From: Brainwave Surfer <B.S.@hsc.vcu.edu>
Subject: can perl write to a usb port com3 device??
Message-Id: <bj5hsk$f6o$1@mira.vcu.edu>
I've looked at the #13: "Controlling Modems with Win32::SerialPort".
article in the Perl Journal...
will it handle USB port com devices?
it will be active perl win32 on windoze XP..
--
"3,000 years ago I made a mistake." Elrond Half-Elven, in "Fellowship
of the Ring"
"I try not to be right any more than necessary". -- Larry Wall, author
of the Perl Language
------------------------------
Date: 3 Sep 2003 14:04:18 -0700
From: deaduser@hotmail.com (Jeffrey Ellin)
Subject: Getting directory sizes on win32
Message-Id: <e8a45386.0309031304.7c5ea111@posting.google.com>
Hi, I am using the following code to get the directory sizes of users
outboxes on our appservers. This code snippet works but it is
dreadfully slow. I have also used File:Find, but it doesn't seem any
faster. Any ideas on how to speed it up? Everything is running on
Win2K.
#sql to get all active users and their last sync date, exclude users
who
#are enddated in the system
$sql = " select n.name,n.APP_SERVER_NAME, max(s.LAST_UPD) as
sync_date " .
" from siebel.s_node n, " .
" siebel.s_extdata_node e, " .
" siebel.s_dock_status s " .
" where n.ROW_ID = s.node_id and " .
" e.NODE_ID = n.ROW_ID and " .
" n.node_type_cd = 'REMOTE' and " .
" s.type = 'SESSION' and " .
" local_flg = 'N' and " .
" e.ACTIVE_FLG = 'Y' and " .
" (n.EFF_END_DT > sysdate or n.EFF_END_DT is null)" .
" group by n.name, n.APP_SERVER_NAME " .
" order by sync_date " ;
#execute sql
$sth = $dbh->prepare($sql);
$sth->execute;
#delete old report file
unlink 'outboxreport.csv';
#loop through each user in resultset.
while (($node,$server,$sync)=$sth->fetchrow_array()){
#get name of docking directory
my $dockloc = substr($server,6);
#assemble path statement
my $path = "//$server/docking$dockloc/$node/outbox";
#my $path = "//$server/docking/$node/outbox";
#get directory size
my $dirsize = -s $path;
opendir(my ($dh),$path);
#loop through each file in the directory skip over dat and uaf since
they are part of new database
while( defined( my $filename = readdir $dh ) ) {
next if $filename eq "." or $filename eq ".." or $filename
=~ /uaf/ or $filename =~ /dat/;
$dirsize += -s "$path/$filename";
}
#re-open file so it writes as we process
open REP, ">>outboxreport.csv";
#convert file size to megabytes
$dirsize = $dirsize/1000000;
#round file size
$dirsize = sprintf "%.2f", $dirsize;
#print out report in csv format
print REP "$node,$server,$sync,$dirsize\n";
}
------------------------------
Date: Wed, 03 Sep 2003 18:26:21 GMT
From: ed <coo_t2-NO-LIKE-SPAM@yahoo.com>
Subject: grep'd list as loop parameter
Message-Id: <n9cclvkau1bvlnmtgflc826ulsr3of2f4f@4ax.com>
Hi all. Up until recently I've been avoiding things like grep and
map.
But now I'm starting to use them, and really see their appeal.
I've read the faq: "What's wrong with using grep or map in a void
context?"
But was wondering if anyone could point me to examples of these
functions
being used in void and non-void context.
For example, is the code below ok?
The list grep creates _is_ used, but it isn't assigned to a variable.
foreach my $currentFilePath ( grep{!/^\.{1,2}$/} readdir(DIR) )
{ # .. do stuff with $currentFilePath
}
tia,
--ed
------------------------------
Date: Wed, 03 Sep 2003 20:28:53 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: grep'd list as loop parameter
Message-Id: <3f563348$0$202$58c7af7e@news.kabelfoon.nl>
ed wrote:
> Hi all. Up until recently I've been avoiding things like grep and
> map.
> But now I'm starting to use them, and really see their appeal.
>
> I've read the faq: "What's wrong with using grep or map in a void
> context?"
> But was wondering if anyone could point me to examples of these
> functions
> being used in void and non-void context.
>
> For example, is the code below ok?
> The list grep creates _is_ used, but it isn't assigned to a variable.
which is ok since you are *using* the result.
> foreach my $currentFilePath ( grep{!/^\.{1,2}$/} readdir(DIR) )
> { # .. do stuff with $currentFilePath
> }
If you throw away the value(s) generated by map/grep why bother
generating them? It costs memory and probably has other overhead too.
--
Kind regards, feel free to mail: mail(at)johnbokma.com (or reply)
virtual home: http://johnbokma.com/ ICQ: 218175426
John web site hints: http://johnbokma.com/websitedesign/
------------------------------
Date: Wed, 03 Sep 2003 19:08:14 GMT
From: ed <coo_t2-NO-LIKE-SPAM@yahoo.com>
Subject: Re: grep'd list as loop parameter
Message-Id: <eheclv8vt2glbi116ff1q0bdgho4e4jpsp@4ax.com>
On Wed, 03 Sep 2003 20:28:53 +0200, John Bokma
<postmaster@castleamber.com> wrote:
>ed wrote:
>
>> Hi all. Up until recently I've been avoiding things like grep and
>> map.
>> But now I'm starting to use them, and really see their appeal.
>>
>> I've read the faq: "What's wrong with using grep or map in a void
>> context?"
>> But was wondering if anyone could point me to examples of these
>> functions
>> being used in void and non-void context.
>>
>> For example, is the code below ok?
>> The list grep creates _is_ used, but it isn't assigned to a variable.
>
>which is ok since you are *using* the result.
>
>> foreach my $currentFilePath ( grep{!/^\.{1,2}$/} readdir(DIR) )
>> { # .. do stuff with $currentFilePath
>> }
>
>If you throw away the value(s) generated by map/grep why bother
>generating them? It costs memory and probably has other overhead too.
I figured it was ok since I'm looping over the values. Guess not?
So I'd be better off with this? :
foreach my $currentFilePath ( readdir(DIR) )
{ next if ($currentFilePath eq '.' || $currentFilePath eq '..');
# .. do stuff..
}
tia,
--ed
------------------------------
Date: 3 Sep 2003 19:09:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: grep'd list as loop parameter
Message-Id: <bj5e8g$f43$2@mamenchi.zrz.TU-Berlin.DE>
John Bokma <thx113@castleamber.com> wrote in comp.lang.perl.misc:
> ed wrote:
>
> > Hi all. Up until recently I've been avoiding things like grep and
> > map.
> > But now I'm starting to use them, and really see their appeal.
> >
> > I've read the faq: "What's wrong with using grep or map in a void
> > context?"
> > But was wondering if anyone could point me to examples of these
> > functions
> > being used in void and non-void context.
> >
> > For example, is the code below ok?
> > The list grep creates _is_ used, but it isn't assigned to a variable.
>
> which is ok since you are *using* the result.
>
> > foreach my $currentFilePath ( grep{!/^\.{1,2}$/} readdir(DIR) )
> > { # .. do stuff with $currentFilePath
> > }
>
> If you throw away the value(s) generated by map/grep why bother
> generating them? It costs memory and probably has other overhead too.
Just wait for Abigail to see this!
She would be right, of course, in saying that it is Perl's job not
to generate the list in void context, not the programmer's to avoid
calling it that way. However, these days it is so easily avoided in
most cases that it is hardly an issue.
Anno
------------------------------
Date: 3 Sep 2003 19:15:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: grep'd list as loop parameter
Message-Id: <bj5ekf$f43$3@mamenchi.zrz.TU-Berlin.DE>
ed <coo_t2-NO-LIKE-SPAM@yahoo.com> wrote in comp.lang.perl.misc:
> On Wed, 03 Sep 2003 20:28:53 +0200, John Bokma
> <postmaster@castleamber.com> wrote:
>
> >ed wrote:
> >
> >> Hi all. Up until recently I've been avoiding things like grep and
> >> map.
> >> But now I'm starting to use them, and really see their appeal.
> >>
> >> I've read the faq: "What's wrong with using grep or map in a void
> >> context?"
> >> But was wondering if anyone could point me to examples of these
> >> functions
> >> being used in void and non-void context.
> >>
> >> For example, is the code below ok?
> >> The list grep creates _is_ used, but it isn't assigned to a variable.
> >
> >which is ok since you are *using* the result.
> >
> >> foreach my $currentFilePath ( grep{!/^\.{1,2}$/} readdir(DIR) )
> >> { # .. do stuff with $currentFilePath
> >> }
> >
> >If you throw away the value(s) generated by map/grep why bother
> >generating them? It costs memory and probably has other overhead too.
>
> I figured it was ok since I'm looping over the values. Guess not?
No, no, your use is perfectly okay, and quite idiomatic. You are
using the result of grep(), even if you don't assign it to anything
(directly).
Put another way, you're using grep in list context. The arguable
use is in void context.
[unnecessarily corrected code snipped]
Anno
------------------------------
Date: Wed, 03 Sep 2003 19:30:22 GMT
From: ed <coo_t2-NO-LIKE-SPAM@yahoo.com>
Subject: Re: grep'd list as loop parameter
Message-Id: <c8gclvsmk6059hc05t8fh677epq8l9n292@4ax.com>
On 3 Sep 2003 19:15:27 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:
>
>No, no, your use is perfectly okay, and quite idiomatic. You are
>using the result of grep(), even if you don't assign it to anything
>(directly).
>
>Put another way, you're using grep in list context. The arguable
>use is in void context.
>
>[unnecessarily corrected code snipped]
>
>Anno
I guess I misunderstood.
Thanks.
--ed
------------------------------
Date: Wed, 03 Sep 2003 21:39:21 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: grep'd list as loop parameter
Message-Id: <3f5643cc$0$195$58c7af7e@news.kabelfoon.nl>
ed wrote:
> On Wed, 03 Sep 2003 20:28:53 +0200, John Bokma
> <postmaster@castleamber.com> wrote:
>
>
>>ed wrote:
>>
>>
>>>Hi all. Up until recently I've been avoiding things like grep and
>>>map.
>>>But now I'm starting to use them, and really see their appeal.
>>>
>>>I've read the faq: "What's wrong with using grep or map in a void
>>>context?"
>>>But was wondering if anyone could point me to examples of these
>>>functions
>>>being used in void and non-void context.
>>>
>>>For example, is the code below ok?
>>>The list grep creates _is_ used, but it isn't assigned to a variable.
>>
>>which is ok since you are *using* the result.
>>
>>
>>>foreach my $currentFilePath ( grep{!/^\.{1,2}$/} readdir(DIR) )
>>>{ # .. do stuff with $currentFilePath
>>>}
>>
>>If you throw away the value(s) generated by map/grep why bother
>>generating them? It costs memory and probably has other overhead too.
>
>
> I figured it was ok since I'm looping over the values. Guess not?
Yes, it is ok, you are using the values generated by grep. You use grep
to obtain every item in the dir that is neither . nor .. (the regexp
could be written as /^\.\.?$/ btw)
> So I'd be better off with this? :
>
> foreach my $currentFilePath ( readdir(DIR) )
> { next if ($currentFilePath eq '.' || $currentFilePath eq '..');
It *could* be faster to use eq instead of the regexp, but you can do
this in the grep as well. You are not using grep in a void context.
--
Kind regards, feel free to mail: mail(at)johnbokma.com (or reply)
virtual home: http://johnbokma.com/ ICQ: 218175426
John web site hints: http://johnbokma.com/websitedesign/
------------------------------
Date: Wed, 03 Sep 2003 21:40:56 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: grep'd list as loop parameter
Message-Id: <3f56442a$0$195$58c7af7e@news.kabelfoon.nl>
Anno Siegel wrote:
> John Bokma <thx113@castleamber.com> wrote in comp.lang.perl.misc:
>
[snip]
>>If you throw away the value(s) generated by map/grep why bother
>>generating them? It costs memory and probably has other overhead too.
>
> Just wait for Abigail to see this!
>
> She would be right, of course, in saying that it is Perl's job not
> to generate the list in void context
I agree.
--
Kind regards, feel free to mail: mail(at)johnbokma.com (or reply)
virtual home: http://johnbokma.com/ ICQ: 218175426
John web site hints: http://johnbokma.com/websitedesign/
------------------------------
Date: Wed, 03 Sep 2003 18:09:38 GMT
From: inwap@inwap.com (Joe Smith)
Subject: Re: Help:Why does eval add a 1 behind evaluations?
Message-Id: <C7q5b.512$Zr2.18954@iad-read.news.verio.net>
In article <326cdb5b.0308280343.604385c0@posting.google.com>,
Tay Ray Chuan <rctay1989@hotmail.com> wrote:
>Hi, I tried using eval like this:
>
>print "Enter something to evaluate:\n";
>while (defined($s = <>)) {
> $result = eval $s;
> if ($@) {
> print "Invalid string:\n $s";
> } else {
> print "$result\n";
> }
>}
>
>this can evaluate anything. but when I type this:
>
>"$a=5;$b=5;$c=$a+$b;print $c;", it prints "101".
>
>Why is there an extra "1"?
Change
print "$result\n";
to
print "The result from eval() is $result\n";
and it will show what is really happening.
-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Wed, 3 Sep 2003 13:33:23 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help:Why does eval add a 1 behind evaluations?
Message-Id: <slrnblccvj.4dr.tadmc@magna.augustmail.com>
Tay Ray Chuan <rctay1989@hotmail.com> wrote:
> Hi, I tried using eval like this:
>
> print "Enter something to evaluate:\n";
> while (defined($s = <>)) {
> $result = eval $s;
> if ($@) {
> print "Invalid string:\n $s";
> } else {
> print "$result\n";
> }
> }
>
> this can evaluate anything. but when I type this:
>
> "$a=5;$b=5;$c=$a+$b;print $c;", it prints "101".
>
> Why is there an extra "1"?
The last expression eval()uated is the value of the eval(), so
$result gets print()'s return value (1).
So, the
print $c
outputs the 10
then
print "$result\n";
outputs the 1 and a newline.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 3 Sep 2003 14:07:56 -0700
From: gdsafford@hotmail.com (Greg)
Subject: Re: IN SEARCH OF ELEGANT CODE: Setting a hash value to a chomp'ed thing
Message-Id: <a8f367ed.0309031307.72e2edc7@posting.google.com>
IneverReadAnythingSentToMe@hotmail.com (David Filmer) wrote in message news:<e4c916dd.0309022357.56493908@posting.google.com>...
> Bart Lateur <bart.lateur@pandora.be> wrote in message news:<d9takvo352aosmhu5glc4n0itcr56kotsf@4ax.com>...
>
> > chomp($hash{key} = `which ps`);
>
> Yes, thanks, Bart, but I already knew that worked (see the PS in my
> original post). I have a reason for wanting to use the
> %hash=(key=>value) syntax (rather than %hash{key}=value syntax).
>
> Thanks especially to Tassilo and Randall for (again) showing me new
> and wonderful ways to use (if not to abuse) Perl. And, thanks Dave
> Saville, for asking Tassilo to further elaborate on his ingenious
> answer; his further explanation proved most enlightening.
Another way would be to use the comma operator, as
use strict;
use warnings;
use Data::Dumper;
my %h;
my $i = 0;
while(<DATA>){
$h{$i++} = (chomp($_), $_);
}
print Dumper(\%h);
__DATA__
one
two
three
four
------------------------------
Date: Wed, 3 Sep 2003 11:52:12 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Modify during a while statement
Message-Id: <slrnblc71s.47r.tadmc@magna.augustmail.com>
mechanicscart@hotmail.com <mechanicscart@hotmail.com> wrote:
> $changes;
> s/\%%$option_d_name%%/ ${$option_v_name}/g;
> #why does s/\%%$option_d_name%%/ ${$option_v_name}/g; work,
> # but $changes does not?
Because
s/\%%$option_d_name%%/ ${$option_v_name}/g;
is "code" and the contents of $changes is "data".
Code gets eval()uated. Data does not get evaluated.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 3 Sep 2003 13:36:22 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Modify during a while statement
Message-Id: <slrnblcd56.4dr.tadmc@magna.augustmail.com>
Mazdack <mazdack@list.ru> wrote:
>
><mechanicscart@hotmail.com> ???????/???????? ? ???????? ?????????:
> news:68f77a66.0309030733.1c7620d5@posting.google.com...
>> $change .= s/\%%$option_d_name%%/ ${$option_v_name}/g,;
>> $changes;
>> s/\%%$option_d_name%%/ ${$option_v_name}/g;
>> #why does s/\%%$option_d_name%%/ ${$option_v_name}/g; work,
>> # but $changes does not?
> $changes=~s/\%%$option_d_name%%/${$option_v_name}/g;
That is an absurd "answer".
Ignore it unless you want even more confusion.
I have no idea how Mazdack thought that that might do what you
are asking for.
The OP wants to match against the string in $_, not the string
in $changes.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 3 Sep 2003 13:37:33 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl CGI related: form post failure
Message-Id: <slrnblcd7d.4dr.tadmc@magna.augustmail.com>
Wenjie <gokkog@yahoo.com> wrote:
> I am not sure it is a good question for the group(s):
> I encountered a problem for my website form (method="post"):
> people have a different ISP encountered text posting
> problems when their text size is more than handreds of
> characters. The phenomena is that the post keeps 'connecting
> or whatever', then the browser reports page unavailable
> errors.
>
> I think it could be that name server of my ISP is slow?
> Or my web server is slow? What could be tuned here to
> resolve the problem?
What is your Perl question?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 3 Sep 2003 18:42:05 +0000 (UTC)
From: jgamble@ripco.com (John M. Gamble)
Subject: Perl6 internals Archives?
Message-Id: <bj5clt$gob$1@e250.ripco.com>
I used to drop in occasionally at the perl6-internals archive at
http://archive.develooper.com/ to see how development was going.
The entries seem to have vanished past 2002, and nothing new
is posted. Has the archive moved? If so, where to?
--
-john
February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.
------------------------------
Date: 3 Sep 2003 18:53:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl6 internals Archives?
Message-Id: <bj5dbp$f43$1@mamenchi.zrz.TU-Berlin.DE>
John M. Gamble <jgamble@ripco.com> wrote in comp.lang.perl.misc:
> I used to drop in occasionally at the perl6-internals archive at
> http://archive.develooper.com/ to see how development was going.
>
> The entries seem to have vanished past 2002, and nothing new
> is posted. Has the archive moved? If so, where to?
Google knows.
Anno
------------------------------
Date: Wed, 3 Sep 2003 15:02:43 -0400
From: "NoSpamPlease" <rodney1@bellsouth.net>
Subject: Replacing a line of text in an HTML file ???
Message-Id: <ZSq5b.17$2E.3@bignews2.bellsouth.net>
I have a situation where I need to "Replace" a line of text in an HTML file.
The code I'm using does not "replace"... but instead, it adds another
line... effectively duplicating the number of lines each time the script
runs.
Below is a sample of my code:
###########################
sub main_page
{
open(MAIN,"$basedir/$mesgfile") || die $!;
@main = <MAIN>;
close(MAIN);
open(MAIN,">$basedir/$mesgfile") || die $!;
if ($followup == 0) {
foreach $main_line (@main) {
##---Title
if ($main_line =~ m/<!--Title-->/) {
print MAIN "<!--Title--> <title>$title</title>\n";
}
##---Page Formatting
if ($main_line =~ m/<!--Pformat-->/) {
print MAIN "<!--Pformat--> <body bgcolor=$BKcolor
text=\"#000000\" alink=\"#FF0000\" vlink=\"#FF00FF\" link=\"#0000FF\">\n";
}
##---Page Heading
if ($main_line =~ /<!--PHeading-->/) {
print MAIN "<!--PHeading--> <FONT FACE=$HeadingFont
SIZE=$HeadingSize COLOR=$HeadingColor> $HeadingText </FONT>\n";
}
#######################################
Any help would be greatly appreciated.
--
...
`·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney
------------------------------
Date: Wed, 03 Sep 2003 21:11:50 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Replacing a line of text in an HTML file ???
Message-Id: <3f563d59$0$189$58c7af7e@news.kabelfoon.nl>
NoSpamPlease wrote:
> I have a situation where I need to "Replace" a line of text in an HTML file.
>
> The code I'm using does not "replace"... but instead, it adds another
> line... effectively duplicating the number of lines each time the script
> runs.
>
> Below is a sample of my code:
>
> ###########################
> sub main_page
> {
> open(MAIN,"$basedir/$mesgfile") || die $!;
> @main = <MAIN>;
> close(MAIN);
>
> open(MAIN,">$basedir/$mesgfile") || die $!;
> if ($followup == 0) {
I don't know what this test does, but it nothing needs to be done if it
is not 0 then better put it before the open and:
return unless $followup == 0;
or even:
return if $followup;
> foreach $main_line (@main) {
>
> ##---Title
> if ($main_line =~ m/<!--Title-->/) {
> print MAIN "<!--Title--> <title>$title</title>\n";
next; # since we have processed this line I assume
> }
>
> ##---Page Formatting
> if ($main_line =~ m/<!--Pformat-->/) {
> print MAIN "<!--Pformat--> <body bgcolor=$BKcolor
> text=\"#000000\" alink=\"#FF0000\" vlink=\"#FF00FF\" link=\"#0000FF\">\n";
next; # since we have processed this line I assume
> }
>
> ##---Page Heading
> if ($main_line =~ /<!--PHeading-->/) {
> print MAIN "<!--PHeading--> <FONT FACE=$HeadingFont
> SIZE=$HeadingSize COLOR=$HeadingColor> $HeadingText </FONT>\n";
next; # since we have processed this line I assume
> }
My guess is that you print $main_line here?
Tips:
use -w in the she bang line and put a use strict; in your code.
Also put some more info in your die, ie.
"Can't open file '$basedir/$mesgfile': $!"
--
Kind regards, feel free to mail: mail(at)johnbokma.com (or reply)
virtual home: http://johnbokma.com/ ICQ: 218175426
John web site hints: http://johnbokma.com/websitedesign/
------------------------------
Date: Wed, 03 Sep 2003 21:15:04 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Silly push tricks
Message-Id: <878yp57f6r.fsf@mithril.chromatico.net>
>>>>> "A" == Abigail <abigail@abigail.nl> writes:
[using map in void context]
A> Poor style? Why?
Because
map { fn($_) } @list;
and
fn ($_) foreach @list;
(where fn is a function with side-effects) do the same thing, but the
latter is better style.
The issue that map can be inefficient when called in void context is
orthogonal to the style issue.
Charlton
--
cwilbur at chromatico dot net
cwilbur at mac dot com
------------------------------
Date: Wed, 03 Sep 2003 18:16:53 GMT
From: inwap@inwap.com (Joe Smith)
Subject: Re: The life of $!
Message-Id: <peq5b.513$Zr2.18954@iad-read.news.verio.net>
In article <bii3i0$8mg$1@newshost.mot.com>,
Richard S Beckett <spikey-wan@bigfoot.com> wrote:
>Guys,
>
>How long does $! live for after the event, as it were?
It is best to put $! into a formatted string immediately,
before doing the operations needed to display it.
> copy ("$source", "$dest") or do {
>
> my $error_text = $!; # -----> Do I really need to do this?
my $error_text = "\nERROR: Cannot backup file $source\n$!\n\n";
> my $error_window = $main_window -> DialogBox (
> -title => "$title - Error!",
> -buttons=>["OK"]);
> my $text = $error_window -> Label (-text=>
> "\nERROR: Cannot backup file!\n\n".
> "$error_text\n", # ------> Could I use $! here?
> )
my $text = $error_window -> Label (-text=>$error_text);
> ->pack;
> $error_window -> bell;
> $error_window->Show();
> }
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Wed, 3 Sep 2003 13:32:11 -0700
From: "Trent Curry" <tcurrey@no.no.no.i.said.no>
Subject: Re: What ever happened to comp.lang.perl ?
Message-Id: <bj5jcd$2qg$1@news.astound.net>
"Helgi Briem" <f_baggins80@hotmail.com> wrote in message
news:3f55d605.171777583@News.CIS.DFN.DE...
> On Wed, 3 Sep 2003 00:47:04 -0500, tadmc@augustmail.com (Tad
> McClellan) wrote:
>
> >
> >Trent Curry, Islaw, krakle, MJ Owens, Cpt Fredo,
> >Manny Wilco, Robin Givens and a cast of thousands wrote:
> >
> >> been around, yet they were expected to
> > know all the rules. I know some jsut
> > ^^^^
So let me get this stright, you are assosiating me with another person or
persons becuase of a typographical error?
> This joker must be a glutton for punishment.
>
> Why does he keep coming back?
>
> What does he want?
>
> Strangely, if we just killfiled everybody who mistypes
> just j-s-u-t, we'd probably get rid of this moron forever
> at only a tiny cost. It might be worth it.
I don't know what you want of me, but I sense you have miss labeled me due
to an error that occurred when typing. I have in fact seen many people, in
this group and in others make such errors. Do you also think all people with
dark skin are African Americans? In other words, I don't appreciate being
miss categorized as something I'm not.
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5434
***************************************