[10130] in Perl-Users-Digest
Perl-Users Digest, Issue: 3723 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 15 20:07:14 1998
Date: Tue, 15 Sep 98 17:00:18 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 15 Sep 1998 Volume: 8 Number: 3723
Today's topics:
A real dumb PERL question... <dejah@DejahsPrivateIce.com>
Re: A real dumb PERL question... (Martien Verbruggen)
Re: Can I foreach multiple arrays? <uri@camel.fastserv.com>
Re: Can I foreach multiple arrays? (Abigail)
Re: Can I foreach multiple arrays? <tchrist@mox.perl.com>
Re: Can I foreach multiple arrays? <ajohnson@gpu.srv.ualberta.ca>
Concatenation of variable names <sherlock@genome.stanford.edu>
Re: Concatenation of variable names <tchrist@mox.perl.com>
Getting the "key" for a hash <gbc1@axe.humboldt.edu>
Re: Getting the "key" for a hash <eashton@bbnplanet.com>
Re: Getting the "key" for a hash (Larry Rosler)
Re: Gratuitous warning: Deep Recursion (Alastair)
Re: NT Login Script via PERL? <metcher@spider.herston.uq.edu.au>
Re: output from a file to be used in code <murrayb@vansel.alcatel.com>
Re: Perl & Java - differences and uses <fsg@newsguy.com>
Re: Perl & Java - differences and uses <uri@camel.fastserv.com>
Re: Perl & Java - differences and uses <pats@acm.org>
Re: Perl (Joe McMahon)
Re: print statement in perl nguyen.van@imvi.bls.com
Re: print statement in perl (Mike Stok)
Q: Is there any Win32-compilabe perl? (Hermann Flacke)
Re: STD I/O for WIN32 Perl (Tye McQueen)
Timeout <leeky@ucalgary.ca>
Re: Timeout (Larry Rosler)
Re: Transposing an array <uri@camel.fastserv.com>
Re: Win32::NetAdmin and WIN95 <cwashing@ix.netcom.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 15 Sep 1998 16:48:11 -0500
From: Mary E Tyler <dejah@DejahsPrivateIce.com>
Subject: A real dumb PERL question...
Message-Id: <35FEE085.200D@DejahsPrivateIce.com>
first:
what are the keys for the Environmental valiable hash %ENV?
and second:
$ENV{REMOTE_HOST} what the hell exactly does it return and what doe it
look like... or more to the point... how can i find the domain that a
particuliar call is coming from... ak.
thanks in advance for not paughing at me.
dejah
--
i trust i make myself obscure, i have need of obscurity now- robert bolt
a heated exchange of unread mail would be welcomed by all- christensen
Skating Fiction. Featuring the highly acclaimed serial On The Edge!
http://www.DejahsPrivateIce.com
------------------------------
Date: Tue, 15 Sep 1998 22:19:39 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: A real dumb PERL question...
Message-Id: <%JBL1.9$gX4.73103@nsw.nnrp.telstra.net>
Please read the following information on how to choose a good subject
line: http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
In article <35FEE085.200D@dejahsprivateice.com>,
Mary E Tyler <dejah@DejahsPrivateIce.com> writes:
> first:
> what are the keys for the Environmental valiable hash %ENV?
The keys are whatever the names of your environment variables are.
> and second:
> $ENV{REMOTE_HOST} what the hell exactly does it return and what doe it
> look like... or more to the point... how can i find the domain that a
> particuliar call is coming from... ak.
Ah, it's a CGI question, right? Check out www.cgi-resources.com. They
have a bunch of documentation there explaining how CGI works.
$ENV{REMOTE_HOST} will contain the symbolic name of the connected
client, or the proxy the client is connecting to. If your server
doesn't do reverse name lookups for you, it will contain the IP
address. You will have to resolve IP addresses yourself (look at the
gethostby* functions). To find the domain name you really have to
request the DNS record for the domain, and get it from that. As a
shortcut, you can try throwing away everything but the last two parts
of the host name, although this will fail in many cases where a domain
name has three parts (as in Australia and the UK).
In other words: it's not a trivial exercise. Maybe there is something
out there already that can do it for you. Check CPAN:
http://www.perl.com/CPAN/
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | 75% of the people make up 3/4 of the
Commercial Dynamics Pty. Ltd. | population.
NSW, Australia |
------------------------------
Date: 15 Sep 1998 18:35:52 -0400
From: Uri Guttman <uri@camel.fastserv.com>
To: jzobel@my-dejanews.com (Joachim Zobel)
Subject: Re: Can I foreach multiple arrays?
Message-Id: <sard88x80mv.fsf@camel.fastserv.com>
>>>>> "JZ" == Joachim Zobel <jzobel@my-dejanews.com> writes:
JZ> Hi.
JZ> I would like to
JZ> foreach ($foo, $bar) (@foos, Qbars) {} # doesn`t work
JZ> just like I
JZ> foreach $foo (@foos) {}
JZ> Is there a simple and elegant way?
NO.
if all you have is two arrays and you don't mind destroying one you can
do something like this:
(adds elements of two same length arrays)
@sums = map { $_ + shift @a } @b ;
with a temp var you can save @a:
@sums = map { push @a, ($a = shift @a) ; $_ + $a } @b ;
obviously this can be used for a variety of similar tasks with 2 arrays.
uri
--
Uri Guttman Speed up your web server with Fast CGI!
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: 15 Sep 1998 22:44:23 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Can I foreach multiple arrays?
Message-Id: <6tmqk7$gph$1@client3.news.psi.net>
Tom Christiansen (tchrist@mox.perl.com) wrote on MDCCCXLI September
MCMXCIII in <URL: news:6tmlgd$hbp$2@csnews.cs.colorado.edu>:
++
++ Destructively:
++
++ while (($foo, $bar) = (shift @foos, shift @bars)) { }
That will never terminate. (undef, undef) is *TRUE*.
++ Non-destructively, given @foos == @bars:
++
++ @pairs = map { [ $foos[$_], $bars[$_] } 0 .. $#foos;
^ Needs extra ]
++ while (($foo, $bar) = @{shift @pairs}) { }
++
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET", "http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content)) =~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: 15 Sep 1998 22:52:36 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Can I foreach multiple arrays?
Message-Id: <6tmr3k$lt4$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, abigail@fnx.com writes:
:++ while (($foo, $bar) = (shift @foos, shift @bars)) { }
:That will never terminate. (undef, undef) is *TRUE*.
But ()[0,1] is false, and I misextrapolated. Perl isn't
very good for inferring, unless you're Larry.
Check emptiness elesewhere:
for ( ;
@foos || @bars;
($foo, $bar) = (shift @foos, shift @bars)
)
{
}
--tom
--
"The young think they are immortal, and are determined to prove otherwise."
--Larry Wall
------------------------------
Date: Tue, 15 Sep 1998 18:32:35 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Can I foreach multiple arrays?
Message-Id: <35FEF913.465EA34E@gpu.srv.ualberta.ca>
Joachim Zobel wrote:
>
> Hi.
>
> I would like to
>
> foreach ($foo, $bar) (@foos, Qbars) {} # doesn`t work
>
> just like I
>
> foreach $foo (@foos) {}
>
> Is there a simple and elegant way?
well, there's been several suggestions, so why
not one more (a little left of center) --- here's
a merged_list_iterating_closure_constructor :-)
#!/usr/bin/perl -w
use strict;
my $merge_it = sub {
my @arr_refs =map{[@$_]} @_;
my $cnt = @arr_refs;
my @merged;
push @merged,map{@$_?shift @$_:''}@arr_refs while(grep{@$_>0}@arr_refs);
return sub {
return splice(@merged,0,$cnt) if @merged;
return;
};
};
my @one=qw(0 a b c d);
my @two=qw(0 mon tue wed thu fri);
my @three=(0,1,2,3);
my $triple_it = $merge_it->(\(@one,@two,@three));
while(my($a,$b,$c)=$triple_it->()){
print "$a:$b:$c\n";
}
__END__
of course, that's just a general idea ... further tampering
may be in order...
regards
andrew
------------------------------
Date: Tue, 15 Sep 1998 15:58:53 -0700
From: Gavin Sherlock <sherlock@genome.stanford.edu>
Subject: Concatenation of variable names
Message-Id: <35FEF12D.9A6A0B2C@genome.stanford.edu>
Hi,
This may be a dumb question, as I'm a Perl newbie, but I want to write
something like:
for ($i=1; $i<=10; $i++){
$fred$i=$somearray[$i];
}
so that I have variables $fred1, $fred2, $fred3 etc. whose values come
from the array @somearray. (I do have a convoluted reason to want to do
this). I would even like to be able later on in the program to put:
print "\$fred1 is $fred1!\n";
so that the value of $fred1 was simply printed out.
Obviously, as I've tested, the above code doesn't compile. Is there
some way that will easily accomplish this aim?
Cheers,
Gavin Sherlock
Dept. of Genetics
Stanford University
300 Pasteur Drive
Tel: 650 498 6602
------------------------------
Date: 15 Sep 1998 23:15:45 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Concatenation of variable names
Message-Id: <6tmsf1$mtn$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Gavin Sherlock <sherlock@genome.stanford.edu> writes:
:This may be a dumb question, as I'm a Perl newbie, but I want to write
:something like:
:for ($i=1; $i<=10; $i++){
: $fred$i=$somearray[$i];
:}
:so that I have variables $fred1, $fred2, $fred3 etc. whose values come
:from the array @somearray.
Forgive me, but I think you want to write this:
for ($i=1; $i<=10; $i++){
$fred[$i] = $somearray[$i];
}
So that you have variables $fred[1], $fred[2], etc.
--tom
--
Just don't compare it with a real language, or you'll be unhappy... :-)
--Larry Wall in <1992May12.190238.5667@netlabs.com>
------------------------------
Date: Tue, 15 Sep 1998 15:28:02 -0700
From: Greg Coit <gbc1@axe.humboldt.edu>
Subject: Getting the "key" for a hash
Message-Id: <35FEE9F2.AFE7A478@axe.humboldt.edu>
OK, I'm running through a hash using this slice of code:
foreach $some_hash (sort { $a <=> $b } %SOME_HASH)
{ (some stuff that I want to happen to each value in the hash)
}
What I want to do is grab the value of the key of the particular
key-value pair being evaluated within the foreach loop. I've checked
all the books I have (camel, lama, and the ram) with no luck.
Thanks,
--
Greg Coit
gbc1@axe.humboldt.edu
------------------------------
Date: Tue, 15 Sep 1998 22:42:34 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Getting the "key" for a hash
Message-Id: <35FEEAF7.F5CC628D@bbnplanet.com>
Greg Coit wrote:
> What I want to do is grab the value of the key of the particular
> key-value pair being evaluated within the foreach loop. I've checked
> all the books I have (camel, lama, and the ram) with no luck.
Try using 'reverse' to create an inverted hash and get the key that way.
perldoc -f reverse
This operator is also handy for inverting a hash, although there are
some
caveats. If a value is duplicated in the original hash, only one of
those
can be represented as a key in the inverted hash. Also, this has to
unwind one hash and build a whole new one, which may take some time
on a large hash.
%by_name = reverse %by_address; # Invert the hash
e.
"All of us, all of us, all of us trying to save our immortal souls, some
ways seemingly more round-about and mysterious than others. We're having
a good time here. But hope all will be revealed soon." R. Carver
------------------------------
Date: Tue, 15 Sep 1998 15:51:38 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Getting the "key" for a hash
Message-Id: <MPG.10688f50f8222ef89897a4@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <35FEE9F2.AFE7A478@axe.humboldt.edu> on Tue, 15 Sep 1998
15:28:02 -0700, Greg Coit <gbc1@axe.humboldt.edu> says...
> OK, I'm running through a hash using this slice of code:
>
> foreach $some_hash (sort { $a <=> $b } %SOME_HASH)
> { (some stuff that I want to happen to each value in the hash)
> }
>
> What I want to do is grab the value of the key of the particular
> key-value pair being evaluated within the foreach loop. I've checked
> all the books I have (camel, lama, and the ram) with no luck.
Your sort is meaningless, because you are sorting both the keys and the
values of the hash indiscriminately. (Unless they all happen to be
numbers, the '-w' flag would have told you something was amiss.)
What you want is something like this (assuming all the keys are numbers,
and that you want to sort by them):
foreach $some_hash (sort { $a <=> $b } keys %SOME_HASH)
{ (some stuff that I want to happen to each value in the hash)
# $SOME_HASH{$some_hash} is set to each value in turn.
}
One might well leave '$some_hash' out of the 'foreach' statement, and
simply use $_ as the hash key.
You might look again in the Camel, where all this is spelled out under
the 'keys' function. Or do `perldoc -f keys`.
By the way, Perl style suggests that you avoid all-caps identifiers,
which imply by convention either a constant or a system variable
(such as %ENV and %SIG).
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 15 Sep 1998 00:04:20 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Gratuitous warning: Deep Recursion
Message-Id: <slrn6vrff1.5v.alastair@calliope.demon.co.uk>
Martin Gregory <mgregory@asc.sps.mot.com> wrote:
>
>Isn't it my business how deeply I recurse? Does this message ever
>really help anyone, or does it only hinder people like me who happen
>to have a job that calls for deep recursion and now have to grapple
>with whether to take out -w or placate users about these warning
>messages?
It might be useful under some circumstances to see this warning. Would it be
possible to turn off warnings around the recursion only?
--
Alastair
work : alastair@psoft.co.uk
home : alastair@calliope.demon.co.uk
------------------------------
Date: Wed, 16 Sep 1998 09:07:53 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: NT Login Script via PERL?
Message-Id: <35FEF349.8E4FDF0@spider.herston.uq.edu.au>
Bill 'Sneex' Jones wrote:
>
<snip>
> PS - What I do know about security tells I wouldn't mess with
> re-writing the NT Log-in functions with Perl, it isn't safe.
No messing with log-in functions was implied. NT either logs you in or
not as it desires. As the price for getting NT to log you in, your
workstation has to promise to run any program the server tells it to,
just this once (per logon). This is the logon script - a priceless
opportunity for the sysadm to take control! And what better language to
do it in than Perl?
--
Jaime Metcher
------------------------------
Date: 15 Sep 1998 16:00:19 -0700
From: Brad Murray <murrayb@vansel.alcatel.com>
Subject: Re: output from a file to be used in code
Message-Id: <usohtrngc.fsf@vansel.alcatel.com>
trex16@my-dejanews.com writes:
> Hey everyone, I was wondering if someone can help me. I have a .exe file
> that produces a date and a numeric code and displays it onto the screen. I
> would like to generate a short perl program that captures this output and
> writes it to a .txt file. Can someone give me some pointers on how to use
> the output of another file for my own file?
program.exe | perl perlcode
...or from inside perl:
open PROGRAM, "program.exe |" or die "Cannot run program.exe";
...and then treat it like any other file.
I think you need to know more about how your operating system behaves
in order to be able to program in its context usefully, though.
--
BMurray "What they [young Americans] do have now is an unordered
SW Analyst tangle of rather ordinary passions, running through their
Alcatel consciousness like a monochrome kaleidoscope."
(Alan Bloom)
------------------------------
Date: Tue, 15 Sep 1998 14:34:08 -0700
From: "Felix S. Gallo" <fsg@newsguy.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <6tmmad$j52@enews2.newsguy.com>
George writes:
>In comp.lang.java.programmer Felix S. Gallo <fsg@newsguy.com> wrote:
>: The indefatigable George Reese writes:
>:>Freedom has no place in programming. Period.
>
>: Here we discover the crux of the problem: George Reese
>: believes that hilariously nonsensical dogma, stated in an
>: authoritative way, is a feasible substitute for a forebrain.
>
>[ad hominem diatribe deleted]
>
>It seems my claim that freedom has no place in programming has really
>struck a nerve with several perl programmers. This one went on to
>talk about all the places where freedom does belong and then attribute
>to me the belief that because I want freedom gone from programming,
>that I want it gone from all aspects of life.
Your reading comprehension is as heroically incompetent as
your arguments and assertions are comically vacuous.
"this" perl programmer didn't mention anything about "all the
places where freedom does belong" (sic). Rather, I detailed
how difficult it would be for you to live in a world without Perl,
C, or C++ -- the languages you claim are being swept from
the earth by the majestic might of python because it's just
not possible to use them properly. Tell it to the factories,
the distribution networks, the highways, your car, your
microwave, your utilities, and your computer.
>ROFL
No doubt, 'borg@imaginary.com'. No doubt.
Felix
can't wait to see that operating system written in python!
------------------------------
Date: 15 Sep 1998 18:30:55 -0400
From: Uri Guttman <uri@camel.fastserv.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <saremtd80v4.fsf@camel.fastserv.com>
>>>>> "Z" == Zenin <zenin@bawdycaste.org> writes:
Z> Uri Guttman <uri@camel.fastserv.com> wrote:
Z> So, you'd end up with stuff like:
Z> package Foo::Bar::Dog; sub some_method { my $self = shift;
Z> $self->{'Foo::Bar::Dog'}->{my_field} = 'my value'; }
but internally if the (modified) bless set it up that way. when you are
executing in a package, that name would be used automagically as the
first level hash key.
you would write code like this:
$self->{my_field} = 'my value';
but it would translate into this:
$self->{'Foo::Bar::Dog'}->{my_field} = 'my value'; }
Z> This makes it much harder to swap package names and a few
Z> other problems. You could do:
Z> $self->{ __PACKAGE__ }->{my_field} = 'my value';
Z> But I don't think that tag works as a hash key (it's seen
Z> as the string '__PACKAGE__').
Z> Either way, it's still ugly. :-)
not if it not seen in the source.
Z> : and if they behave nicely they can peek into : others in the same
Z> object by climbing up the class tree and looking at : those hashes.
Z> Tree? So are you thinking of something like:
Z> package Foo::Bar::Dog; $self->{Foo}{Bar}{Dog}{my_field} =
Z> 'my_value';
Z> What happends when Foo::Bar wants the field name "Dog"
Z> later?
this is not valid, see my idea above. there is no overlap of name spaces.
Z> How is a sub-class to know what is considered public and
Z> what is private?
if you reference somthing that doesn't exist, an ISA like search up the
tree can be initiated to find the level that has that key. how to
separate public from private i haven't thought out. this is separating
class data from each other with inherited sharing of names in the data space.
Z> Luckily for us, this issue has already been covered pretty
Z> well in the newest version of perl, 5.005*.
Z> See perldoc fields for more info. -- -Zenin
i will look at it. 5.005 still seems to me to be bleeding edge. you keep
mentioning new features, regex stuff, etc. no wonder i don't see it
being used much. i am sticking with 5.004_4 until i hear more stories of
005 being used in the real world.
uri
--
Uri Guttman Speed up your web server with Fast CGI!
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: 15 Sep 1998 15:48:15 PDT
From: Patricia Shanahan <pats@acm.org>
Subject: Re: Perl & Java - differences and uses
Message-Id: <35FEEE18.F4226516@acm.org>
I don't think the popularity of C can be used as evidence of its
technical goodness, because there were overwelming non-technical
reasons for C compilers being widely available and well supported,
which in turn gave a portability advantage to C programs.
Patricia
Abigail wrote:
>
> Cees de Groot (cg@dhcpcl-129.cdg.acriter.nl) wrote on MDCCCXLI September
> MCMXCIII in <URL: news:6tl0sc$epm@dhcpcl-129.cdg.acriter.nl>:
> ++
> ++ You're completely overreacting. I tend to agree with George: history learns
> ++ that software built in tightly defined programming languages turns out
> ++ to be better. Freedom does have a place in programming - on the style
> ++ level (how do you solve a certain problem, which algorithm do you use,
> ++ etcetera). On lower levels, such freedom works against you in the long term.
>
> And which fact from history learns us that? The overwelming amount of
> applications written in Pascal, with C not standing a chance?
>
> ++ I'm not an academic, by the way (what a strange notion that only academics
> ++ would have good ideas on programming ;-}).
>
> Indeed, as an academic wouldn't use "better" without stating which
> definition of "better" (s)he was using.
>
> Abigail
> --
> perl -we '$_ = q ?4a75737420616e6f74686572205065726c204861636b65720as?;??;
> for (??;(??)x??;??)
> {??;s;(..)s?;qq ?print chr 0x$1 and \161 ss?;excess;??}'
------------------------------
Date: Tue, 15 Sep 1998 19:29:25 -0400
From: joe.mcmahon@gsfc.nasa.gov (Joe McMahon)
Subject: Re: Perl
Message-Id: <joe.mcmahon-1509981929250001@prtims.stx.com>
In article <6tmlmr$t11$1@nnrp1.dejanews.com>, kazman@my-dejanews.com wrote:
>I am trying to make script which can edit web pages through web browsers.
>But I want the script can edit only a specific part of pages. For example,
>If I want people to edit words between specific images, what can I do?
>
>Below is what I tried to do.
>
> if ($_ = /^<.*>/ .. /(<P><IMG SRC=\"/imagesT/area_of_expertise.gif\"
>HEIGHT=25 WIDTH=427 ALT=\"Area Of Expertise Key
>Words\">)/([^\"]*)/<P><CENTER><A HREF=\"#top\"><IMG
>SRC=\"/imagesT/top.gif\")/i {
>s/([^\"]*)=\"\"/([^\"]*)=\"$param{keywords}\"/gi; print NEWPAGE; } }
>
You are assigning to $_, not matching against it (=~ operator). That's problem
1. You are not using the "/s" (multi-line match) modifier. That's problem 2.
>I am trying to have a script which edit words between
>
><P><IMG SRC=\"/imagesT/area_of_expertise.gif\" HEIGHT=25 WIDTH=427 ALT=\"Area
>Of Expertise Key Words\">
>
>AND
>
><P><CENTER><A HREF=\"#top\"><IMG SRC=\"/imagesT/top.gif\">
You are making your life *much* too complicated. That's problem 3.
Use HTML comments bracketed around the area you want to isolate.
<!-- BEGIN-EDITABLE -->
yadda yadda yadda
<!-- END-EDITABLE -->
Writing the match becomes trivial at this point:
# assuming your multi-line text is in $_:
if (($editable) =~ /<!-- BEGIN-EDITABLE -->(.*)<!-- END-EDITABLE -->/s) {
# Do your deed here. Remember to not to trust ANYTHING that you
# get back from the user. You will particularly want to filter
# any <!-- END-EDITABLE --> if some wiseguy enters it to prevent
# now-uneditable stuff from being stuffed into your page.
}
This has not been tested in brutal detail, and frankly I don't remember if
I got the HTML comment syntax just right, but what the heck, this is a Perl
newsgroup. The CGI groups can tell you if I blew the comments. :)
"Have the appropriate amount of fun."
--- Joe M.
------------------------------
Date: Tue, 15 Sep 1998 21:54:55 GMT
From: nguyen.van@imvi.bls.com
Subject: Re: print statement in perl
Message-Id: <6tmnnf$vd8$1@nnrp1.dejanews.com>
In article <35FEA2CD.C006DC97@ee.gatech.edu>,
Tien Pham <tpham@ee.gatech.edu> wrote:
> Hello there,
>
> I have a question regarding to Perl.
>
> On page 117 of "Programming Perl" by O'Reilly & Associates,
> there is an example (near the bottom of the page) showing
> how to pass arrays using typeglob approach.
> I include the example here for convenience:
>
> (*a, *b) = func(\@c, \@d);
> print "@a has more than @b\n";
> sub func {
> local (*c, *d) = @_;
> if (@c > @d) {
> return (\@c, \@d);
> }
> else {
> return (\@d, \@c);
> }
> }
>
> Notice how @a and @b are printed in the print statement in
> the codes above.
>
> I follow pretty much the method shown on that page, but I
> always got error message when I executed my Perl program:
>
> % In string, @cout now must be written as \@cout at
> add.prl line 17, near "@sum \t @cout"
> Execution of add.prl aborted due to compilation errors.
>
> This is my Perl program:
> -----------------------
>
> @x = ([1,0,1], [0,1,1]);
> @y = ([1,1,1], [1,1,0]);
>
> $row = $#x;
> $col = $#{$x[0]};
>
> for $time (0..$row) {
>
I guess that you have a problem right here:
(*sum,*cout) = add_arr (\@x,\@y);
if you used the "\" in front of "@", Perl will not understand @x as an array
instead of as scalar variable (@x and @y). So don't use this "\" if you want
perl kowning @x and @y as the arrays.
> print "@sum \t @cout \t aaa\n";
> }
>
> sub add_arr {
> local (*x,*y) = @_;
> print STDOUT "@x\t@y\tbbb\n";
>
> return (\@x,\@y);
> }
>
> ------------------------
>
> Basically, it complains that I cannot have @sum or @cout like that
> in the quotation. According to the book, I can.
>
> If I add another print statement to the program:
>
> ...
> for $time (0..$row) {
> (*sum,*cout) = add_arr (\@x,\@y);
>
> print @sum, "\t", @cout, "\t aaa\n"; <---- Added
> print "@sum \t @cout \t aaa\n";
> }
> ...
>
> Both statements are executed properly! Without the added
> line, the 2nd print statement will give error message.
>
> Does anybody know what's going on, and how to fix this?
>
> thanks,
>
> tien pham
> tpham@ee.gatech.edu
>
> --
> Plan:
>
> To live
> To enjoy
> To appreciate
> every opportunity and every minute here, in America!
> --------------------------------------
>
>
Van Nguyen ( Tuan Dung)
Former GT student, but don't much about you. Graduated from GT for more than a
year.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: 15 Sep 1998 23:16:02 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: print statement in perl
Message-Id: <6tmsfi$jgo@news-central.tiac.net>
In article <35FEA2CD.C006DC97@ee.gatech.edu>,
Tien Pham <tpham@ee.gatech.edu> wrote:
>This is my Perl program:
>-----------------------
>
>@x = ([1,0,1], [0,1,1]);
>@y = ([1,1,1], [1,1,0]);
>
>$row = $#x;
>$col = $#{$x[0]};
>
>for $time (0..$row) {
> (*sum,*cout) = add_arr (\@x,\@y);
> print "@sum \t @cout \t aaa\n";
>}
>
>sub add_arr {
> local (*x,*y) = @_;
> print STDOUT "@x\t@y\tbbb\n";
>
> return (\@x,\@y);
>}
>
>------------------------
>
>Basically, it complains that I cannot have @sum or @cout like that
>in the quotation. According to the book, I can.
>
>If I add another print statement to the program:
>
>...
>for $time (0..$row) {
> (*sum,*cout) = add_arr (\@x,\@y);
>
> print @sum, "\t", @cout, "\t aaa\n"; <---- Added
> print "@sum \t @cout \t aaa\n";
>}
>...
>
>Both statements are executed properly! Without the added
>line, the 2nd print statement will give error message.
>
>Does anybody know what's going on, and how to fix this?
Perl 5.xxx cleaned up the interpolation of arrays in double quoted things.
Unless perl "knows" that you're using the array it now assumes that @
signs in double quoted strings are meant to be literals. Consider:
#!/usr/local/bin/perl -w
# @bar = (1, 2, 3);
print "foo@bar.baz\n";
__END__
If you were writing a big program and someone introduced @bar, would the
change in behaviour be desirable?
One way to get around it is to always
use strict;
in your program, and that way you're likely to either have a
my @bar;
or
use vars qw/@bar/;
in the code to indicate to the compiler/interpreter that you're really
using the array.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: 15 Sep 1998 07:12:47 GMT
From: hermann.flacke@t-online.de (Hermann Flacke)
Subject: Q: Is there any Win32-compilabe perl?
Message-Id: <6tl41f$rb2$2@news01.btx.dtag.de>
I would like to use the the perl functionality within the C/C++ and
the Java language. I know that there is the "embedded" perl way. Is
there any resource and documentation out there to get perl run within
_one_ programm, _not_ from a running interpreter outside my *.exe
file?
Thanks!
Hermann Flacke
------------------------------
Date: 15 Sep 1998 16:53:59 -0500
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: STD I/O for WIN32 Perl
Message-Id: <6tmnln$1do@fohnix.metronet.com>
) steven_elias@ml.com (Stephen Elias) writes:
)
) > myperl.pl < foo-in.txt > foo-out.txt
You can do:
perl myperl.pl < foo-in.txt > foo-out.txt
or:
pl2bat myperl.pl
REM creates myperl.bat
myperl < foo-in.txt > foo-out.txt
REM runs myperl.bat
I prefer the second one since I don't think you should need to
know what I used to write some utility in order to be able to
use it.
This is a bug in Win32.
Brad Murray <murrayb@vansel.alcatel.com> writes:
) This sort of thing works for me---what trouble are you having?
I find that hard to believe. Perhaps you aren't using Win32?
--
Tye McQueen Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)
------------------------------
Date: Tue, 15 Sep 1998 17:04:41 -0600
From: Kin Yee Lee <leeky@ucalgary.ca>
Subject: Timeout
Message-Id: <6tmrqh$gt4@ds2.acs.ucalgary.ca>
Hi everyone,
If the execution of my program not finish in a certain amount of
time, I want to abort the execution of my program. Is the following
way going to work?
#!/usr/local/bin/perl
use Env;
$Env{TMOUT}=30;
:
:
:
Thank You for any help in advance.
Kin
------------------------------
Date: Tue, 15 Sep 1998 16:48:23 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Timeout
Message-Id: <MPG.10689ca4b8f842049897a5@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <6tmrqh$gt4@ds2.acs.ucalgary.ca> on Tue, 15 Sep 1998 17:04:41
-0600, Kin Yee Lee <leeky@ucalgary.ca> says...
> If the execution of my program not finish in a certain amount of
> time, I want to abort the execution of my program. Is the following
> way going to work?
>
> #!/usr/local/bin/perl
> use Env;
> $Env{TMOUT}=30;
No, it won't do anything like that. To be honest, after looking at the
description of the Env module (<URL:http://www.perl.com/CPAN-
local/doc/manual/html/lib/Env.html>) I'm not sure why one would want to
use it. Is $ENV{PATH} that much harder to write than $PATH?
What you want is the 'alarm' function (`perldoc -f alarm` gives a simple
example) provided it is implemented on your system (i.e., not Windows or
DOS). If 'alarm' is not available, I don't know how to do it. I have
asked several times here, but not gotten a clear answer about a Win32 API
to similar functionality. Help, anyone???
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 15 Sep 1998 18:14:57 -0400
From: Uri Guttman <uri@camel.fastserv.com>
Subject: Re: Transposing an array
Message-Id: <sarg1dt81lq.fsf@camel.fastserv.com>
>>>>> "A" == Abigail <abigail@fnx.com> writes:
A> @c = @{$a [1]}; @b = map {[$_, shift @c]} @{$a [0]};
A> But this makes unnessary copies of data.
A> This doesn't:
A> $i = -1;
A> $b [$i] = [map {$a [$_] -> [$i]} 0, 1] while ++ $i < @{$a[0]};
shouldn't the 0,1 input to map be 0 .. $#a ?
your code assumes 2 in that dimension but loops over the other
dimension.
also you could use push instead of indexing into @b. so the rewrite
would be (tested):
$i = -1;
push( @b, [map {$a [$_][$i]} 0 .. $#a] ) while ++$i < @{$a[0]};
another version is (tested):
foreach $i ( 0 .. $#{$a[0]} ) {
push @c, [ map { $_->[$i]} @a ] ;
}
that could be made into a one liner in 5.005 with the foreach modifier:
push @c, [ map { $_->[$i]} @a ] foreach $i ( 0 .. $#{$a[0]} ) ;
surprisingly my push version of abby's is slower by quite a bit. the
foreach version is closer (but it uses system time, for malloc?). i
have not tested it with the foreach modifier since i don't have 5.005
built at work yet.
Benchmark: timing 5000 iterations of abby, uri1, uri2...
abby: 8 secs ( 7.84 usr 0.00 sys = 7.84 cpu)
uri1: 11 secs (10.67 usr 0.00 sys = 10.67 cpu)
uri2: 9 secs ( 8.66 usr 0.40 sys = 9.06 cpu)
timethese( 5000, {
abby => sub { my $i = -1; my @b ;
$b [$i] = [map {$a [$_] -> [$i]} 0, 1]
while ++ $i < @{$a [0]}; },
uri1 => sub { my $i = -1 ; my @b ;
push( @b, [map {$a [$_][$i]} 0 .. $#a] )
while ++$i < @{$a[0]}; },
uri2 => sub { my @b ;
foreach $i ( 0 .. $#{$a[0]} ) {
push @c, [ map { $_->[$i]} @a ] ;
}
}
}
) ;
--
Uri Guttman Speed up your web server with Fast CGI!
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: Tue, 15 Sep 1998 17:38:14 -0500
From: "Clarence Washington Jr." <cwashing@ix.netcom.com>
Subject: Re: Win32::NetAdmin and WIN95
Message-Id: <6tmq77$dj4$1@farragut.paranet.com>
Use Perl with WSH and ADSI. Works fine under Windows 95
--
Check it out
http://cwashington.netreach.net
Win32 bit scripting, lots of sample scripts, downloads,
reference files, and technical support via an online discussion forum.
RonBo wrote in message <35fecff6.26306078@newshost.unx.sas.com>...
>Does anyone know an alternate way of gettting at User information,
>specifically $comment, for a WIN95 client running under NT? The
>Win32::NetAdmin is only compatible with NT clients, and I've not been
>able to pull out the comment field for Win95\98 clients.
>
>Thanks. for any help.
>
------------------------------
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 3723
**************************************