[10747] in Perl-Users-Digest
Perl-Users Digest, Issue: 4346 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 2 19:07:24 1998
Date: Wed, 2 Dec 98 16:00:22 -0800
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, 2 Dec 1998 Volume: 8 Number: 4346
Today's topics:
Re: $! type variables <r28629@email.sps.mot.com>
Re: $! type variables (Sam Holden)
alarm <stmintz@yahoo.com>
Re: Behavior of C<for $var (..)> (Martien Verbruggen)
Re: Behavior of C<for $var (..)> <jeffp@crusoe.net>
Re: Debugger and pager option (Ilya Zakharevich)
Re: Debugger and pager option <ketung.Hsiao@losangeles.af.mil>
Re: Help with - Dynamic HTML loading an applet???? (Martien Verbruggen)
Re: Help with multiple database queries using Perl and (Martien Verbruggen)
Re: New idiom? (Mark-Jason Dominus)
no instance of a classy kludge (method) (Verily Blue)
Re: no instance of a classy kludge (method) (Martien Verbruggen)
Re: no instance of a classy kludge (method) <jeffp@crusoe.net>
Re: Okay, I took the advice -- now what? (Tad McClellan)
Re: Perl and FTP 'rcmd' command or 'quote rcmd' (Charles Wilt)
Re: PERL is TOO flexible <r28629@email.sps.mot.com>
Re: PERL is TOO flexible (Erik)
Re: Prgmr detection of redirection of STDOUT <rra@stanford.edu>
string to array <nir_l@netvision.net.il>
Re: string to array <jeffp@crusoe.net>
Re: string to array <ludlow@us.ibm.com>
Re: string to array (Martien Verbruggen)
Re: string to array (Erik)
Re: string to array (Tad McClellan)
Re: Substitute (Mark Mark Dominus Dominus Weatherby George Dupree)
Re: system call with parameters that have spaces <bryan@eai.com>
system commands in WinNT <darmawan@scic.org>
Tool to reverse engineer perl code <swalsh@americasm01.nt.com>
Re: variable inside variable (Tad McClellan)
Re: When does CLOSE not FLUSH? <rra@stanford.edu>
Re: When does CLOSE not FLUSH? (Larry Rosler)
Re: When does CLOSE not FLUSH? (Bart Lateur)
Re: Why is "... @foo ..." occasionally a syntax error? <rra@stanford.edu>
Re: win32API module available for Unix? (Rich)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 02 Dec 1998 16:02:04 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: sholden@cs.usyd.edu.au
Subject: Re: $! type variables
Message-Id: <3665B8DC.B69715A5@email.sps.mot.com>
[posted to c.l.p.m and copy emailed]
Sam Holden wrote:
>
> On 2 Dec 1998 20:36:05 GMT, Gregory Snow <snow@biostat.washington.edu> wrote:
> >
> >I remember reading somewhere how to make variables like $!, that
> >return different values in string context and numeric context. I've
> >spent the last hour pouring through the docs and faq but have not
> >found it (and DejaNews won't search for $! and other searches have
> >been useless). Can anyone point me to the correct doc or post?
>
> I've never needed to do that so I could be wrong but I suspect :
>
> perldoc overload
>
> might have the answers you want (of course it's quite possible that
> that is the extremely long and comlicated way to do it in which case I
> guess it won't jog your memory anyway)...
overload? I think this is overkill ;-)
perldoc perlvar
-TK
------------------------------
Date: 2 Dec 1998 22:49:07 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: $! type variables
Message-Id: <slrn76bgv3.cso.sholden@pgrad.cs.usyd.edu.au>
On Wed, 02 Dec 1998 16:02:04 -0600, Tk Soh <r28629@email.sps.mot.com> wrote:
>[posted to c.l.p.m and copy emailed]
>
>Sam Holden wrote:
>>
>> On 2 Dec 1998 20:36:05 GMT, Gregory Snow <snow@biostat.washington.edu> wrote:
>> >
>> >I remember reading somewhere how to make variables like $!, that
>> >return different values in string context and numeric context. I've
>> >spent the last hour pouring through the docs and faq but have not
>> >found it (and DejaNews won't search for $! and other searches have
>> >been useless). Can anyone point me to the correct doc or post?
>>
>> I've never needed to do that so I could be wrong but I suspect :
>>
>> perldoc overload
>>
>> might have the answers you want (of course it's quite possible that
>> that is the extremely long and comlicated way to do it in which case I
>> guess it won't jog your memory anyway)...
>
>overload? I think this is overkill ;-)
>
> perldoc perlvar
Where does perlvar tell me how to make variables which have 'magical'
properties like many of the built in variables that perlvar lists?
All I see is a list of variables that are special in various ways already,
nothing about making my own though...
--
Sam
There's no such thing as a simple cache bug.
--Rob Pike
------------------------------
Date: Wed, 2 Dec 1998 17:38:11 -0600
From: "Sean Mintz" <stmintz@yahoo.com>
Subject: alarm
Message-Id: <744in7$q0$1@Masala.CC.UH.EDU>
Hi. I am using Perl for Win32 by ActiveState and it does not support the
alarm function. Is there any version of Perl for Win32 that DOES support
alarm?
Thank you.
Sean Mintz <stmintz@yahoo.com>
------------------------------
Date: Wed, 02 Dec 1998 22:03:54 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Behavior of C<for $var (..)>
Message-Id: <ePi92.25$Fw3.133@nsw.nnrp.telstra.net>
In article <Pine.GSO.3.96.981202142548.19230C-100000@crusoe.crusoe.net>,
Jeff Pinyan <jeffp@crusoe.net> writes:
> So. I use Perl 5.004_04 (I'll be installing 5.005 soon, I hope). I
> wasn't able to find this behavior documented in the camel or perldoc... is
> it?
Yes. First you need to know that in Perl for and foreach are basically
the same beast.
# perldoc perlsyn
[snip]
Foreach Loops
The foreach loop iterates over a normal list value and sets
the variable VAR to be each element of the list in turn. If
the variable is preceded with the keyword my, then it is
lexically scoped, and is therefore visible only within the
loop. Otherwise, the variable is implicitly local to the
loop and regains its former value upon exiting the loop.
[snip]
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd. | selective about its friends.
NSW, Australia |
------------------------------
Date: Wed, 2 Dec 1998 17:11:18 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Behavior of C<for $var (..)>
Message-Id: <Pine.GSO.3.96.981202170901.23364A-100000@crusoe.crusoe.net>
> Yes. First you need to know that in Perl for and foreach are basically
> the same beast.
Yes, I'm absolutely aware of that. I had just missed that one section of
the docs. Thanks for the pointers, all of you.
I always use for anyway... call it bad style, it's 4 less chars, and I
like it. :)
--
Jeff Pinyan (jeffp@crusoe.net)
www.crusoe.net/~jeffp
Crusoe Communications, Inc.
973-882-1022
www.crusoe.net
------------------------------
Date: 2 Dec 1998 22:00:41 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Debugger and pager option
Message-Id: <744da9$2c5$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Ketung Hsiao
<ketung.Hsiao@losangeles.af.mil>],
who wrote in article <3665A659.9D5D3CC2@losangeles.af.mil>:
> I set O pager=more, but it O pager still said '1'.
> How to resolve this ?
How to resolve *what*?
O whatever
by definition sets whatever to 1. Did you mean
O whatever?
Ilya
------------------------------
Date: Wed, 02 Dec 1998 14:40:15 -0800
From: Ketung Hsiao <ketung.Hsiao@losangeles.af.mil>
Subject: Re: Debugger and pager option
Message-Id: <3665C1CF.36F99E6B@losangeles.af.mil>
Sorry about the typo, I meant to say:
in using Win32 Perl debugger mode:
I entered O pager
debugger's respond pger = '|1'
I entered O pager=more
debugger's respond pager = '|more'
My question: how do I make this pager='|more' stay ?
( Because after this any piping command still scroll).
Thanks.
llya Zakharevich wrote:
> [A complimentary Cc of this posting was sent to Ketung Hsiao
> <ketung.Hsiao@losangeles.af.mil>],
> who wrote in article <3665A659.9D5D3CC2@losangeles.af.mil>:
> > I set O pager=more, but it O pager still said '1'.
> > How to resolve this ?
>
> How to resolve *what*?
>
> O whatever
>
> by definition sets whatever to 1. Did you mean
>
> O whatever?
>
> Ilya
------------------------------
Date: Wed, 02 Dec 1998 22:06:05 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Help with - Dynamic HTML loading an applet????
Message-Id: <hRi92.26$Fw3.133@nsw.nnrp.telstra.net>
In article <3664FA54.7CBEF852@plexstar.com>,
Rama Murthy <rmurthy@plexstar.com> writes:
> Everytime I run this perl script from CGI script the applet seems to be
> loading the cached class file instead of a newly created one. How do I
> make it so that it
> loads the newly created class file.
If there is a way to do that, it certainly has absolutely nothing to
do with perl at all.
Try asking on one of the comp.infosystems.www.* groups. They talk
about HTTP, HTML, applets, CGI and stuff like that.
We talk about perl, Perl and the best way to prepare bananas for
consumption.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Inside every anarchy lurks an old boy
Commercial Dynamics Pty. Ltd. | network - Mitchell Kapor
NSW, Australia |
------------------------------
Date: Wed, 02 Dec 1998 22:00:19 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Help with multiple database queries using Perl and Mysql.pm
Message-Id: <TLi92.24$Fw3.133@nsw.nnrp.telstra.net>
In article <7443jk$58u$1@nnrp1.dejanews.com>,
xaqtnr@my-dejanews.com writes:
> I am trying to do multiple (only 2) database queries using Mysql.pm
> and I keep getting the following error:
>
>>> Can't call method "Query" without a package or object reference at
>>> script.cgi line 60.
Most likely it means that $cc_dbh or $sn_dbh is undefined (whichever
one is used on line 60). And this most likley is because the Connect
failed for some reason. I am not too familiar with the Mysql package,
but I suggest that you do whatever you need to do to ensure that the
Connect call succeeded.
Another thing: It seems that you are using globals for a lot of the
stuff, and you re-use them in other subroutines. This may be a
potential source of error. You may be mixing up things. localising
variables is always a good thing.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Very funny Scotty, now beam down my
Commercial Dynamics Pty. Ltd. | clothes.
NSW, Australia |
------------------------------
Date: 2 Dec 1998 17:49:10 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: New idiom?
Message-Id: <744g56$nja$1@monet.op.net>
In article <da692.2239$CY1.9080887@news.itd.umich.edu>,
Sean McAfee <mcafee@waits.facilities.med.umich.edu> wrote:
>while (($host, *param) = each %paramhash) {
I think you might want something like
while (($host, local *param) = each %paramhash) {
instead. Although I don't know if thatll work the way I expect.
Hey, it's your idiom.
Oddly, just yesterday I found myself doing
foreach $h (@a) {
local *h = $h;
...
}
to serve a similar sort of purpose. (@a was an array of hashrefs.)
This yielded a surprise benefit later on; it turned out that I would
have had to do something similar even if I hadn't been trying to be
cute and clever, because I needed to use the %h items in a format.
------------------------------
Date: Wed, 02 Dec 1998 22:52:39 GMT
From: trueblue2@bellsouth.net (Verily Blue)
Subject: no instance of a classy kludge (method)
Message-Id: <912638825.233@209.214.173.130>
I am using a kludge that I do not like: At first glance
what appears to be a class method invocation is effectively
an instance method call.
As an example to illustrate, I have two classes of objects:
Animal and Bird. Animal is the base class. I want both
classes to define an instance method 'has' and the Bird
'has' method also needs to call the Animal 'has' method
sometimes.
This would be no problem if the methods were class methods
I think but what is the best way to do this for instance
methods?
...
package Bird;
sub has
{ # Bird method
my $self = shift;
my $attribute = shift;
...
return $value if $value = $self->has( $attribute );
^^^^^
...
}
...
I want to be able to call Animal 'has' above but using '$self'
obviously won't work. The following works but it seems to me
to be a bit kludge-y passing '$self' as an argument in a 'class'
call!
...
package Bird;
sub has
{ # Bird method
my $self = shift;
my $attribute = shift;
...
return $value if $value = Animal->has( $self, $attribute );
...
}
package Animal;
sub has
{ # Animal method
my $self = shift;
$self = shift unless ref $self;
my $attribute = shift;
...
}
...
Is there a better way to do this other than perhaps using a
different method name (like 'has_a') for one of the methods
or modifying my object design?
------------------------------
Date: Wed, 02 Dec 1998 23:10:45 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: no instance of a classy kludge (method)
Message-Id: <VNj92.38$Fw3.239@nsw.nnrp.telstra.net>
In article <912638825.233@209.214.173.130>,
trueblue2@bellsouth.net (Verily Blue) writes:
> This would be no problem if the methods were class methods
> I think but what is the best way to do this for instance
> methods?
I think you are looking for SUPER.
# perldoc perltoot
[snip]
Overridden Methods
[snip]
There is still something a bit off here. We've hard-coded
our superclass's name. This in particular is bad if you
change which classes you inherit from, or add others.
Fortunately, the pseudoclass SUPER comes to the rescue here.
$self->SUPER::debug($Debugging);
This way it starts looking in my class's @ISA. This only
makes sense from within a method call, though. Don't try to
access anything in SUPER:: from anywhere else, because it
doesn't exist outside an overridden method call.
[snip]
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | I'm just very selective about what I
Commercial Dynamics Pty. Ltd. | accept as reality - Calvin
NSW, Australia |
------------------------------
Date: Wed, 2 Dec 1998 18:27:48 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: no instance of a classy kludge (method)
Message-Id: <Pine.GSO.3.96.981202182631.25139B-100000@crusoe.crusoe.net>
> I am using a kludge that I do not like: At first glance
> what appears to be a class method invocation is effectively
> an instance method call.
>
> As an example to illustrate, I have two classes of objects:
> Animal and Bird. Animal is the base class. I want both
> classes to define an instance method 'has' and the Bird
> 'has' method also needs to call the Animal 'has' method
> sometimes.
>
> This would be no problem if the methods were class methods
> I think but what is the best way to do this for instance
> methods?
Are you possibly referring to can()? Or is that for class methods only?
--
Jeff Pinyan (jeffp@crusoe.net)
www.crusoe.net/~jeffp
Crusoe Communications, Inc.
973-882-1022
www.crusoe.net
------------------------------
Date: Wed, 2 Dec 1998 17:50:44 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Okay, I took the advice -- now what?
Message-Id: <koj447.5oe.ln@metronet.com>
Jim Mooney (gemhound@gemhound.com) wrote:
[ snip first question ]
: Second question. I also tried <use strict;> and got a message like the
: one below for Every data item:
: Global symbol "$dataitem" requires explicit package name at hello.pl
: line ##.
The messages that might be issued by perl are *all* documented
in the 'perldiag' man page that is shipped with the perl
distribution:
-----------------
=item Global symbol "%s" requires explicit package name
(F) You've said "use strict vars", which indicates that all variables
must either be lexically scoped (using "my"), or explicitly qualified to
say which package the global variable is in (using "::").
-----------------
: What's an explicit package
$main::dataitem # if in the main package
: and again, how do I get this working so I
: can use full diagnostics and warnings?
my $dataitem; # somewhere before you use it
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 2 Dec 1998 22:15:52 GMT
From: charles.0272@worldnet.no.spam.att.net (Charles Wilt)
Subject: Re: Perl and FTP 'rcmd' command or 'quote rcmd'
Message-Id: <MPG.10cf89a758e6473a98968c@netnews.worldnet.att.net>
In article <3665553b.1351393@news.mmc.org>, drummj@mail.mmc.org says...
>
> The Net::FTP module provides a quot() method, and is included in the libnet
> distribution. If you downloaded the GSAR port of 5.004_02, you probably already
> have it. I did encounter some anomalies with that version of libnet, though,
> and have since switched to the ActiveState Perl 5.005_02 build 507 (you must
> install libnet separately via ppm). No problems to report so far.
>
>
>
Thanks,
I was looking at the libwin32 module, and did not see anything in its FTP
documentation about quot. I'll see what I can find in libnet.
Thanks again, sorry about posting to the moderated group with a munged e-
mail.
--
Charles Wilt
Miami Luken, Inc.
e-mail: charles.0272@worldnet.no.spam.att.net
--->remove the no.spam.
------------------------------
Date: Wed, 02 Dec 1998 15:49:03 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: PERL is TOO flexible
Message-Id: <3665B5CF.D3710D9B@email.sps.mot.com>
Sam Curren wrote:
> I've found programming to be very similar to foreign languages in that
> respect. The first you learn you usually revert back to, unless you
> discontinue use entirely, and each language is easier to learn after
^^^^^^^^^^^^^^^^^^^^^^^^
I think (can't recall for sure) this is what Randal Schwartz suggest :)
The last ten lines of C code that I wrote was a wrapper for my CGI
script.
> that. One that understands C,perl,and VB would have an easier time
> learning another then one that only understands C.
>
> Although people are different, and some take to different languages then
> others.
Talking about learning a new language, there is one thing uniquely nice
(as far as I'm concerned :) about Perl: while learning C++ is like
attending a formal classroom lesson, learning Perl is like singing in
the shower - some sing more badly than others, but they all have fun.
[I guess I should stop here]
-TK
------------------------------
Date: 2 Dec 1998 22:36:01 GMT
From: eln@cyberhighway.net (Erik)
Subject: Re: PERL is TOO flexible
Message-Id: <744fch$bg5$1@news.cyberhighway.net>
In article <3665B5CF.D3710D9B@email.sps.mot.com>,
Tk Soh <r28629@email.sps.mot.com> writes:
> Talking about learning a new language, there is one thing uniquely nice
> (as far as I'm concerned :) about Perl: while learning C++ is like
> attending a formal classroom lesson, learning Perl is like singing in
> the shower - some sing more badly than others, but they all have fun.
> [I guess I should stop here]
Good thing...I was getting a little frightened as to how far you might
try to take that analogy ;)
--
Erik Nielsen, Cyberhighway Internet Services NOC
Well, I think Perl should run faster than C. :-)
-- Larry Wall in <199801200306.TAA11638@wall.org>
------------------------------
Date: 02 Dec 1998 13:57:51 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Prgmr detection of redirection of STDOUT
Message-Id: <ylr9ui436o.fsf@windlord.stanford.edu>
James McHutchion <jim.mchutchion@compaq.com> writes:
> I would like to be able to programmatically determine if the STDIN/
> STDOUT files have been redirected in a command like
> perl file.txt <infile >outfile.
if (!-t STDOUT) { print "They redirected us! How lame!\n" }
I'm not positive this will work under NT, though. You'd have to try it.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Wed, 2 Dec 1998 23:58:19 +0200
From: "nir l." <nir_l@netvision.net.il>
Subject: string to array
Message-Id: <744d83$5kb$1@news.netvision.net.il>
hey...
maybe its trivial, but still,:
how do i force a string into an array??
(well..in C a string is defined as an array but how do i do it in Perl???)
i.e $a="hello" , how do i create an array like that--> @a1=qw( h e l l o)
thanks
nir
------------------------------
Date: Wed, 2 Dec 1998 17:18:27 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: string to array
Message-Id: <Pine.GSO.3.96.981202171723.23775A-100000@crusoe.crusoe.net>
> maybe its trivial, but still,:
> how do i force a string into an array??
> (well..in C a string is defined as an array but how do i do it in Perl???)
> i.e $a="hello" , how do i create an array like that--> @a1=qw( h e l l o)
Easiest way would be:
@letters = split "", $word;
Note: better to use quotes here instead of //, I think... // implies a
regex, which isn't needed. Rootbeer, tchrist, merlyn? Comments? :)
--
Jeff Pinyan (jeffp@crusoe.net)
www.crusoe.net/~jeffp
Crusoe Communications, Inc.
973-882-1022
www.crusoe.net
------------------------------
Date: Wed, 02 Dec 1998 16:17:03 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: string to array
Message-Id: <3665BC5F.74D8B30B@us.ibm.com>
nir l. wrote:
> i.e $a="hello" , how do i create an array like that--> @a1=qw( h e l l o)
Check the docs for the following keywords:
split
substr
--
James Ludlow (ludlow@us.ibm.com)
(Any opinions expressed are my own, not necessarily those of IBM)
------------------------------
Date: Wed, 02 Dec 1998 22:39:03 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: string to array
Message-Id: <bkj92.34$Fw3.110@nsw.nnrp.telstra.net>
In article <Pine.GSO.3.96.981202171723.23775A-100000@crusoe.crusoe.net>,
Jeff Pinyan <jeffp@crusoe.net> writes:
> @letters = split "", $word;
>
> Note: better to use quotes here instead of //, I think... // implies a
> regex, which isn't needed. Rootbeer, tchrist, merlyn? Comments? :)
I'm not one of those, but I do have a comment :)
The first argument of split is always interpreted as a regexp, with
some extra oddities for some special cases. This is even the case when
you use double or sinlge quotes. That is one of the reasons I always
specify the first argument with // or m//. Just as a gentle reminder
of this fact.
> perl
$_ = "aa : bb : cc";
split /\s+:\s+/;
print STDOUT (join '|', @_), "\n";
split '\s+:\s+';
print STDOUT (join '|', @_), "\n";
__END__
aa|bb|cc
aa|bb|cc
Martien
PS. Yes I know that implicit split into @_ is deprecated.
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Little girls, like butterflies, need no
Commercial Dynamics Pty. Ltd. | excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: 2 Dec 1998 22:56:52 GMT
From: eln@cyberhighway.net (Erik)
Subject: Re: string to array
Message-Id: <744gjk$cfr$1@news.cyberhighway.net>
In article <Pine.GSO.3.96.981202171723.23775A-100000@crusoe.crusoe.net>,
Jeff Pinyan <jeffp@crusoe.net> writes:
> Easiest way would be:
> @letters = split "", $word;
>
> Note: better to use quotes here instead of //, I think... // implies a
> regex, which isn't needed. Rootbeer, tchrist, merlyn? Comments? :)
On a pentium 66:
use Benchmark;
$string = "hsgkjldfhsgdsfkjhgkdfsgdfshgjdskldshlkdsghlsdurleshgludrhglsdjkfbvjlk
dsfbgvsdjlkhdajklghjlksfhgluerhulghdlufhdajguidhfjuldahjgadhjlduahaduhguldhgluad
fhuhdaluaudhjuladhjuialdhuilhdauaduliadhuldiahlidagda";
timethese(500000,{
"doubles" => sub { split "",$word },
"pattern" => sub { split //,$word },
"single" => sub { split '',$word },
});
Benchmark: timing 500000 iterations of doubles, pattern, single...
doubles: 36 wallclock secs (27.22 usr + 1.89 sys = 29.11 CPU)
pattern: 29 wallclock secs (25.60 usr + 1.75 sys = 27.35 CPU)
single: 31 wallclock secs (25.40 usr + 1.62 sys = 27.02 CPU)
So, no real difference. If anything, // is actually faster.
// suggests a pattern, not necessarily a regex. And, according to the
Camel, other than the case of splitting on " " (all whitespace), "if you
supply a string instead of a regular expression, it'll be interpreted as
a regular expression anyway". For a literal string match, double, single, or
slash quotes are pretty much a matter of personal preference more than
anything else.
--
Erik Nielsen, Cyberhighway Internet Services NOC
One operator is no big deal. That can be fixed in a jiffy.
-- Larry Wall in <199809151814.LAA22396@wall.org>
------------------------------
Date: Wed, 2 Dec 1998 17:52:39 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: string to array
Message-Id: <7sj447.5oe.ln@metronet.com>
nir l. (nir_l@netvision.net.il) wrote:
: how do i force a string into an array??
: i.e $a="hello" , how do i create an array like that--> @a1=qw( h e l l o)
@a1 = split //, $a;
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 2 Dec 1998 23:07:19 GMT
From: mjd@plover.com (Mark Mark Dominus Dominus Weatherby George Dupree)
Subject: Re: Substitute
Message-Id: <744h77$e29$1@netnews.upenn.edu>
Keywords: Keywords
In article <366572F7.7BACB2E0@eddie.mit.edu>,
John Chambers <jc@eddie.mit.edu> wrote:
>#!/usr/bin/perl
>open(F,$0);while(<F>){print}
>
>I don't think I've seen one smaller.
The empty program is smaller, and doesn't have the caveats you mentioned.
Among nontrivial programs,
open+0;print<0>
works on the same principle as yours, and is the smallest I know of.
It also has the benefit of depending on an obscure and little-used
feature. I wish I could remember who invented it.
Also, see http://www.plover.com/~mjd/perl/quine.html.
It is probably quite different from others you have seen before.
>But it's a nice example, and not even obscure.
Sometimes obscure is a virtue.
------------------------------
Date: Wed, 02 Dec 1998 17:49:07 -0600
From: Bryan Hart <bryan@eai.com>
Subject: Re: system call with parameters that have spaces
Message-Id: <3665D1F3.446B@eai.com>
I'm not sure it the original of this made it to this group, so for
background...
I'm having problems when using the system() command in Win32 perl when
passing arguments that contain spaces. Tye McQueen was good enough to
send some sample code to work around some of the problems, but things
still don't quite work. I initially thought it was a problem with
system() understanding the argument for the executable if it was quoted,
but that's not exactly the case. My response follows...
=
OK - while packaging up my test script I found one more variable that I
didn't consider - you'll love this :)
It appears that this is more complex than a quoted executeable argument,
it's actually an interaction of some kind between having a quoted
executeable argument and at least one quoted "other" argument
Here's a example script that shows the various cases:
----------------------------------begin----------------------------------=
------------------
# here's the multiarg form - this works
@args1 =3D ("c:\\temp\\zip.exe", "-jq9", "c:\\temp\\foo.zip",
"c:\\temp\\foo.txt");
system(@args1) =3D=3D 0 ? print "arg1 succeeded\n" :=A0 print "$! from
args1\n";
#here's the same multiarg with a space in the executeable path - this
#fails as expected from your previous description, but works under UNIX
#when the /'s are correct
#this is what I was seeing at the very beginning
@args2 =3D ("c:\\program files\\zip.exe", "-jq9", "c:\\temp\\foo.zip",
"c:\\temp\\foo.txt");
system(@args2) =3D=3D 0 ? print "arg2 succeeded\n" :=A0 print "$! from
args2\n";
#here's the single arg version of 1 - this works since it has no quoted
#arguments
@args3 =3D ("c:\\temp\\zip.exe -jq9 c:\\temp\\foo.zip c:\\temp\\foo.txt")=
;
system(@args3) =3D=3D 0 ? print "arg3 succeeded\n" :=A0 print "$! from
args3\n";
#here's the single arg version of 2 - this works because only the
#executeable is quoted
@args4 =3D ("\"c:\\program files\\zip.exe\" -jq9 c:\\temp\\foo.zip
c:\\temp\\test.pl");
system(@args4) =3D=3D 0 ? print "arg4 succeeded\n" :=A0 print "$! from
args4\n";
#here's another single arg version of 2 with a quoted destination file
#this fails because both the executeable and an argument are quoted
#this is the case I was seeing after I added your example fix
@args5 =3D ("\"c:\\program files\\zip.exe\" -jq9 \"c:\\temp\\foo.zip\"
c:\\temp\\foo.txt");
system(@args5) =3D=3D 0 ? print "arg5 succeeded\n" :=A0 print "$! from
args5\n";
#here's another single arg version of 1 with a quoted destination file
#this works because only the argument is quoted
@args6 =3D ("c:\\temp\\zip.exe -jq9 \"c:\\temp\\foo.zip\"
c:\\temp\\foo.txt");
system(@args6) =3D=3D 0 ? print "arg6 succeeded\n" :=A0 print "$! from
args6\n";
#here's another single arg version of 1 with 2 quoted destination files
#this works and is just here to make sure the error is not more than 1
#quoted argument per system()
@args7 =3D ("c:\\temp\\zip.exe -jq9 \"c:\\temp\\foo.zip\"
\"c:\\temp\\foo.txt\"");
system(@args7) =3D=3D 0 ? print "arg7 succeeded\n" :=A0 print "$! from
args7\n";
----------------------------end-----------------------------------
At 03:55 PM 12/2/98 , you wrote:
>Excerpts from the mail message of Bryan Hart:
>) =
>) "C:\Program Files\visnetwork\tools\zip.exe" -jq9 \temp\92\92.zip
>) "c:\program files\visnetwork\documentroot\projects\images\11.gif"
>) \temp\92\92.pvl
>) =
>) doesn't from a perl system() (both work from a command shell) - NT giv=
es
>) the error that it cannot find an executeable with that name
>
>When debugging, precision is important. Reduce the problem script
>to the smallest possible script that still exhibits the problems
>and post that script, exactly, to comp.lang.perl.misc or .moderated.
>-- =
-- =
------------------------------------------------------------
| Bryan Hart | Phone: (515) 296-5979 |
| Network Products Engineer | Fax: (515) 296-7025 |
| Engineering Animation Inc. | Email: bryan@eai.com | =
| | WWW: http://www.eai.com/ =
| =
------------------------------------------------------------
------------------------------
Date: Wed, 02 Dec 1998 17:44:46 -0600
From: darmawan <darmawan@scic.org>
Subject: system commands in WinNT
Message-Id: <3665D0EE.9034E477@email.com>
I am trying to get a script to work on NT but when run through a Web
page it doeesn't seem to return anything for system calls.
Let's say I have the lines
$version = `ver`;
print "Version: $version";
somewhere in my script. When run from the command line I get
Version: Window NT Version 4.0
But when run from a browser I get
Version:
What is the deal? Is there something, somewhere that needs to be set so
that the default Web user can reference system commands through scripts?
Thanks
Cliff Corder
corder@email.com
------------------------------
Date: Wed, 2 Dec 1998 17:51:03 -0500
From: "Steve Walsh" <swalsh@americasm01.nt.com>
Subject: Tool to reverse engineer perl code
Message-Id: <744g8p$7e7$1@bcarh8ab.ca.nortel.com>
Has anyone on this list come across a reverse engineering tool that will
take perl code as input and generate data diagrams, process diagrams
(flowcharts), etc. I know that there are lots of software tools available
that do this for Java, C++, etc but I would like to find one that I can use
with perl or is customizable to allow me to add perl in as a supported
language. If you know of such a tool please email with details. Thank you.
Steve Walsh
swalsh@americasm01.nt.com
------------------------------
Date: Wed, 2 Dec 1998 17:20:00 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: variable inside variable
Message-Id: <0vh447.pfe.ln@metronet.com>
quinn coldiron (qcoldiro@unlinfo.unl.edu) wrote:
: I'm working on a database with a table of names and a table of form
: letters.
: What I want to do is place variables in the form letter like this:
: Dear $fname,
: but I dont get the data, just the variable names. Can I do this?
Perl FAQ, part 4:
"How can I expand variables in text strings?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 02 Dec 1998 14:29:22 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: When does CLOSE not FLUSH?
Message-Id: <ylg1ay41q5.fsf@windlord.stanford.edu>
Jonathan Stowe <gellyfish@btinternet.com> writes:
> On 30 Nov 1998 20:29:54 -0800 Russ Allbery <rra@stanford.edu> wrote:
>> I thought open with a mode of ">>" uses O_APPEND. If it doesn't, that
>> strikes me as really odd. If it does, the seek should not be
>> necessary:
>> O_APPEND If set, the file offset is set to the end of
>> the file prior to each write.
> Except that it is appending to the file as it stands at the open - it
> might be that another process has added to the file between the open and
> the lock.
No. That's the whole point of O_APPEND. O_APPEND does an implicit seek
to end of file *before every write to the file*. So it doesn't matter if
the file changes after you opened it; if you opened it with O_APPEND,
you'll still be writing to the current end of the file.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Wed, 2 Dec 1998 14:42:37 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: When does CLOSE not FLUSH?
Message-Id: <MPG.10cf623640716aa59898a8@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <7449bs$er$1@gellyfish.btinternet.com> on 2 Dec 1998 20:53:16
-0000, Jonathan Stowe <gellyfish@btinternet.com> says...
> On 30 Nov 1998 20:29:54 -0800 Russ Allbery <rra@stanford.edu> wrote:
> > Abigail <abigail@fnx.com> writes:
> >
> >> As the example on 'perldoc -f flock' tells you, you need to do a seek
> >> after you got the lock.
...
> > I thought open with a mode of ">>" uses O_APPEND. If it doesn't, that
> > strikes me as really odd. If it does, the seek should not be necessary:
> >
> > O_APPEND If set, the file offset is set to the end of
> > the file prior to each write.
>
> Except that it is appending to the file as it stands at the open - it might
> be that another process has added to the file between the open and the lock.
No. Can't happen.
This is an old thread: "Re: File IO Question: opening for appending
without flock?" April 16, 1998.
http://x9.dejanews.com/getdoc.xp?AN=344789136
DejaNews is a great resource! I don't have to type all that stuff all
over again.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 02 Dec 1998 23:36:19 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: When does CLOSE not FLUSH?
Message-Id: <3665c98a.1143428@news.skynet.be>
Russ Allbery wrote:
>> Except that it is appending to the file as it stands at the open - it
>> might be that another process has added to the file between the open and
>> the lock.
>
>No. That's the whole point of O_APPEND. O_APPEND does an implicit seek
>to end of file *before every write to the file*. So it doesn't matter if
>the file changes after you opened it; if you opened it with O_APPEND,
>you'll still be writing to the current end of the file.
I'd like to believe that.
Could anybody provide a code snippet that would irrefutably prove that?
Bart.
------------------------------
Date: 02 Dec 1998 13:56:33 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Why is "... @foo ..." occasionally a syntax error?
Message-Id: <ylu2ze438u.fsf@windlord.stanford.edu>
Martien Verbruggen <mgjv@comdyn.com.au> writes:
> I am confused. I don't think we were actually discussing this behaviour
> under 'use strict'. I advised earlier in the thread to always use
> strict, but the original post stated that the message from perl was
[...]
It was in there, but the chain of discussion may have been lost. Someone
suggested that the original poster use strict and declare all their
variables, they followed up asking how to declare variables, and we went
from there. So it seemed at least to me that the context was within "use
strict" for this particular branch of things.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 2 Dec 1998 23:50:33 GMT
From: richm@ucesucks.mulveyr.roc.servtech.com (Rich)
Subject: Re: win32API module available for Unix?
Message-Id: <slrn76bke1.prh.richm@ll.aa2ys.ampr.org>
On Wed, 02 Dec 1998 12:08:02 GMT, elcaro@my-dejanews.com <elcaro@my-dejanews.com> wrote:
>Does anyone know if the win32API is available for Unix? I've seen the module
>but it seems to be precompiled for i386 and I need to do this work under Sun
>Solaris.
>
Is is *still* September?
- Rich
--
Rich Mulvey
My return address is my last name,
followed by my first initial, @mulveyr.roc.servtech.com
http://mulveyr.roc.servtech.com
Amateur Radio: aa2ys@wb2wxq.#wny.ny.usa
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 4346
**************************************