[28791] in Perl-Users-Digest
Perl-Users Digest, Issue: 35 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 16 09:05:58 2007
Date: Tue, 16 Jan 2007 06:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 16 Jan 2007 Volume: 11 Number: 35
Today's topics:
Array operation <kunanu@gmail.com>
Re: Array operation <nobull67@gmail.com>
Re: Asynchronous alert (NOSPAM)
Re: backtick and system command <josef.moellers@fujitsu-siemens.com>
Re: CGI & LWP::UserAgent - forwarding cookies - how? (NOSPAM)
Re: How do you Call a Perl subroutine with a variable n <louisREMOVE@REMOVEh4h.com>
Re: launch simple perl script from browser usenet@DavidFilmer.com
LWP::UserAgent and proxy <xx@wp.pl>
Re: Map Windows from Unix <scobloke2@infotop.co.uk>
Re: Map Windows from Unix anno4000@radom.zrz.tu-berlin.de
Re: My program dies. <wblock@wonkity.com>
Re: My program dies. anno4000@radom.zrz.tu-berlin.de
Re: My program dies. <bik.mido@tiscalinet.it>
Position in an array <bew_ba@gmx.net>
Re: Position in an array <rs@474.at>
Re: Position in an array <rs@474.at>
Re: Position in an array anno4000@radom.zrz.tu-berlin.de
Re: Position in an array <wahab-mail@gmx.de>
Re: Position in an array <tfeserver@gmail.com>
Re: Position in an array anno4000@radom.zrz.tu-berlin.de
Re: Position in an array <bew_ba@gmx.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 16 Jan 2007 04:08:51 -0800
From: "Kuna" <kunanu@gmail.com>
Subject: Array operation
Message-Id: <1168949330.388962.225990@11g2000cwr.googlegroups.com>
Hi All,
I am having problem in implementing array operation in my task these
are:
In my form I have some multiple entry fields which are showing in a row
and below that I have an Add button which will add the rows again in
the form which I have done by incrementing the value but for deleting
the rows I have a check box and when selecting the check box and
hitting delete button it suppose to delete the rows which I had
selected and I am just taking an array and keeping the values in the
array to not shoe the selected row after delete button. But the problem
is that delete is working as it need to work when I am going to save
the form data then it was having the deleted values in the array and
showing the fields again. So what will I do for solve this problem
please suggest me. Here is the code I have used for the array storing
purpose:
<code>
our @rows = qw(); # this is the array I have declared globally for the
entire form.
====
if ( $var eq 'delete' || $var eq 'add' ) {
push (@rows,"$checkid");
}
$number_of_rows = @rows; # it is checking for the check box click and
push those rows to the array.
====
$is_download=0;
for (my $u=0; $u < $number_of_rows; $u++)
{
if ($rows[$u] eq $i)
{
$is_download=1;
last;
}
}
if ( $i eq $checkid || $is_download eq 1 ) {
}
else {
#The form goes here
}
</code>
------------------------------
Date: 16 Jan 2007 05:11:38 -0800
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Array operation
Message-Id: <1168953098.296541.75500@s34g2000cwa.googlegroups.com>
On Jan 16, 12:08 pm, "Kuna" <kun...@gmail.com> wrote:
> I am having problem
[ snip: suspected stealth-CGI question with confusing description and
very little, (and quite possibly, not relevant) code ]
Please produce a _minimal_ but _complete_ (strict, warning-free) script
that you have actually run and found to illustrtate your question. This
and much other helpful advice can be found in the posting guidelines.
Random-shot-in-the-dark: You are forgetting CGI.pm is sticky be
default.
------------------------------
Date: Tue, 16 Jan 2007 01:18:07 -0600
From: "Mumia W. (NOSPAM)" <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: Asynchronous alert
Message-Id: <eoi3lk$n57$1@aioe.org>
On 01/15/2007 03:42 PM, * Tong * wrote:
> On Mon, 15 Jan 2007 01:39:30 -0600, Mumia W. (NOSPAM) wrote:
>
>>>>> I'm trying to write an alert detection script.
>>>>>
>>>>> Generally, the script loops to detect if the alert criteria is met,
>>>>> and if so, alert the user. Somewhat like this:
>>> my $alerted;
>>> for(;;){
>>> my $flag=detect_flag
>>> if($flag){
>>> alert_user unless $alerted;
>>> $alerted=1
>>> }
>>> }
>>>
>>>>> The 'alert_user' can be as simple as a pop up window via Xdialog. Once the
>>>>> alert goes off, it might take some time to resolve, but I don't want to
>>>>> alert user again and again, hence the '$alerted' var. The problem is that
>>>>> I need a way to clear the '$alerted' var. I think, to make it simple, the
>>>>> best time is when the user confirm the alert pop up window.
>>>>>
>>>>> Now, what's the easiest way to do it? The reason I wanted to use Xdialog is
>>>>> because it's extreme easy to code, but I can't think of a way to clear the
>>>>> '$alerted' var.
>>> IMHO, as a *general purpose* *high-level* code snip, it is complete. What
>>> only lacks is the way/mechanism to reset $alerted asynchronous, which I
>>> don't know and is asking -- how to reset it determines how the alert_user()
>>> is coded, and there is no need to dive into the detect_flag() at all.
>> Under what conditions do you want to clear the $alerted flag?
>
> I think, to make it simple, the best time is when the user confirm the
> alert pop up window -- i.e., user click, pop up gone, $alerted cleared.
>
> how is that?
>
You need to post an actual (short) program. The solution is not simply
conceptual.
Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
--
Windows Vista and your freedom in conflict:
http://www.badvista.org/
------------------------------
Date: Tue, 16 Jan 2007 10:37:48 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: backtick and system command
Message-Id: <eoi6ei$91v$1@nntp.fujitsu-siemens.com>
mail4ashok@gmail.com wrote:
>>It's not the Perl script's fault that the Tcl interpreter buffers its
>>output.
>>There is little you can do in your Perl script to correct that.
>=20
>=20
> that is not true.
>=20
> #!/usr/bin/perl -w
> select STDOUT;
> $|=3D1;
> print `echo test;sleep 5;echo test`;
> __END__
>=20
> o/p:
> time goes by 5 seconds
> test
> test
> #!/usr/bin/perl -w
> select STDOUT;
> $|=3D1;
> print system "echo test;sleep 5;echo test";
> __END__
>=20
> o/p:
> test
> time goes by 5 seconds
> test
>=20
Note that a "0" is also printed, but you don't show it:
josef@bounty:~> perl
print system "echo test;sleep 5;echo test";
test
test
0josef@bounty:~>
^
The difference between the two examples is that the return value of the=20
back-quoted command sequence is the output of the command sequence while =
the return value of the "system" command is the exit status of the=20
executed command (a shell, in this case as the string contains shell=20
meta characters).
I.e. in the first case, "print" prints the two "test"s while in the=20
second case, the two "echo"s print the "test"s.
Try
my $x =3D `echo Test1`;
my $y =3D system("echo Test2");
See?
If not, add
print "x=3D$x\ny=3D$y\n";
>>I almost wrote "nothing you can do" as there is a solution:
>>do not run your Tcl script through a pipe but rather set up a pseudo-tt=
y
>>between the Perl and the Tcl script. That way the Tcl script will assum=
e
>>a terminal on its stdout (which, in effect, it has) and will send
>>line-buffered output.
>>
>>Expect (a Tcl based software) does that.
>=20
>=20
> Actually I wasn't doing fully disclosing all the details, the script
> called by Perl is a Expect script
> most of it Tcl. I think I am correct in saying that the "puts" Tcl
> function is unbuffered.
It appears I'm wrong in assuming that Tcl's output is buffered: it's not:=
test.tcl:
puts "line1"
exec /bin/sleep 10
puts "line2"
test.pl:
open(my $tcl, 'tclsh test.tcl|');
select STDOUT; $|=3D1;
while (<$tcl>) {
print;
}
prints the two lines with a 10s delay in between.
> So what I experienced is a difference between backtick and system
> command.
The work differently. Therefore there is a difference.
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Tue, 16 Jan 2007 02:33:18 -0600
From: "Mumia W. (NOSPAM)" <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: CGI & LWP::UserAgent - forwarding cookies - how?
Message-Id: <eoi3lp$n57$2@aioe.org>
On 01/15/2007 02:25 PM, S P Arif Sahari Wibowo wrote:
> Hi!
>
> I am developing a CGI application (using CGI module), which upon
> processing (when user submit) will contact a second httpd server using
> LWP::UserAgent.
>
> The issue is, I need to forward some cookies (authentication cookies) -
> that the application receievd - to the second server. I know
> LWP::UserAgent use HTTP::Cookies to represent it cookie jar, but I
> cannot find out how I can inject a new cookie into the jar, especially
> when the cookie came from a CGI application.
>
> Any ideas how I can do this? Can I somehow inject "raw_cookie" from CGI
> directly into LWP::UserAgent?
>
> Thanks!
>
> http://www.arifsaha.com/
>
(Followups set to comp.lang.perl.misc)
perldoc lwpcook
perldoc LWP::UserAgent
perldoc HTTP::Cookies
Without seeing any code, all I can suggest is that you create a cookie
jar, add the desired cookie to it using the set_cookie method and attach
the cookie jar to an LWP::UserAgent object using LWP::UserAgent's
cookie_jar method.
Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
--
Windows Vista and your freedom in conflict:
http://www.securityfocus.com/columnists/420/2
------------------------------
Date: Tue, 16 Jan 2007 02:12:28 -0800
From: "Wayne M. Poe" <louisREMOVE@REMOVEh4h.com>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <513mogF1igns0U1@mid.individual.net>
Tad McClellan wrote:
> Wayne M. Poe <louisREMOVE@REMOVEh4h.com> wrote:
> > Brian McCauley wrote:
> > > fred.illig@lmco.com (Fred) spits TOFU in Tad's face:
> > >
> > > > Thanks
> > >
> > > Please express your thanks by learning how to quote properly.
> > >
> > > Failure to do not only makes you appear rude and arrogant but may
> > > even cause you get "killfiled" (your posts are automatically
> > > ignored) by many of the most knowledgable people here.
> > >
> > > --
> > > \\ ( )
> > > . _\\__[oo
> > > .__/ \\ /\@
> > > . l___\\
> > > # ll l\\
> > > ###LL LL\\
> >
> >
> > I fully understand that replying below the relevant text is the most
> > appreciate way. That is not what I wish to dispute.
>
>
> That's a relief!
>
>
> > What I really dislike here is the approach you (and others
> > sometimes) take in conveying this information.
>
>
> Then simply post a few more forgeries to "even it out".
I didn't forge anything. I simply copied the original post, headers et
al, from an archive and replied to that via my reader. The actual way
the reply was generated is the same way it would of been had the
original still been in my spool, but as this thread is over 2 years old,
that was the only way I knew of that I could add to the thread itself
(so it would become part of the thread in archives, instead of a new
"root" thread. In all my years of UseNet, I've never see anyone say
anything against adding to forlorn discussions, nor that it will
suddenly cause the planet to cease rotating.)
> > May I shouldn't of watched the God Father yesterday on television,
> > but later when I was doing a search on Google Groups, and read this
> > thread, this Mr. McCauley, who otherwise is a helpful person, made
> > it look like Fred was being threatened by the mob, so to speak.
>
>
> There was a "contract" out on the OP that he was unaware of.
Interesting way of putting it. I think you made part of my point for me
in this one sentence :)
> > Telling someone "makes you appear rude and arrogant", seems just way
> > more than needed to be said.
>
>
> Knowing that you risk becoming ignored is a _good_ thing.
>
> It allows you to make an informed decision.
>
> You seem to be in favor of leaving the OP in ignorance, to suffer
> consequences that he was unaware of?
>
> That's not very nice.
Lets not twist what I'm saying. I have nothing against informing one of
guidelines and what not, it's the *way* this is commonly done in this
news group that can really make on urk in dismay.
"no bull"'s post of which I replied to came across to me as almost a
bully tactic. He could of been polite about it rather than cast
mellow-negative tone as if he's the nun-teacher tapping a ruler in hand.
I guess my point is some of you act too much as if you are moderators
rather than just participants, which we all are.
> > Yes, posting below what you are replying to
> > is the accepted UseNet (and other medium) manner, but I never saw it
> > written that it's the *only* way that can be utilized.
>
>
> It is not the only way that can be utilized.
I didn't mean simply below the entire block, but rather below the
paragraph or so that you are replying to, as we are doing :)
Trimming/snipping is part of it too, of course.
> It is the only way that is socially acceptable.
Well, that is a *subjective* view, as it's definitely *not* the *only*
way, just the *preferred* way, I think that's an important distention.
> > All I ask is,
>
>
> We will all get right on doing things the way you want.
>
> Thanks for showing us your light.
Again, you are trying to change what I am saying. I NEVER said I wanted
everyone to suddenly change how they do things to suit *me*. Not do I
want that. What I would like to see is a little compassion when dealing
with those who, to quote Tom Christiansen, "are clueless", rather than
the semi-putting-on-airs that constantly goes on. Please don't try to
say it does not happen. I come across this all the time when searching
this group, which is what finally sparked my rather tardy reply.
> > don't try to imply the *REASON* someone is try to appear a
> > certain way, just because you see it as that. It doesn't mean
> > *everyone* does. Especially when it amounts to a general lack of
> > understanding in the posting department. Many people just aren't
> > used to posting in the *same way* you are.
>
>
> Then they need to be educated before it is Too Late.
I wasn't disputing that. Once again, it's the *way* some practice this
educating that comes off as unnecessarily aggressive.
------------------------------
Date: 16 Jan 2007 00:22:16 -0800
From: usenet@DavidFilmer.com
Subject: Re: launch simple perl script from browser
Message-Id: <1168935736.365476.118790@11g2000cwr.googlegroups.com>
Bob Walton wrote:
> Well, one way would be to install a web server on your system. Modify
> the Perl script to function as a CGI program.
A webserver is not necessary if you want to run the script on the same
machine that it resides on. You may "run" anything on the localhost
with the file://whatever syntax in the browser address bar.
Of course, it won't display output to the browser... but the program
WILL run.
--
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Tue, 16 Jan 2007 11:11:54 +0100
From: avlee <xx@wp.pl>
Subject: LWP::UserAgent and proxy
Message-Id: <op.tl8rx4vl1sq83a@saturn>
Hello
I use WWW::Mechanize but it's based on LWP::UserAgent, so everything =
should be the same.
my $proxy =3D "http://127.0.0.1:8118";
my $mech =3D WWW::Mechanize->new();
$mech->proxy(['http'],$proxy);
my $urlsearch =3D "http://myserver.com";
$mech->get($urlsearch);
print $mech->content;
Without proxy - everything works fine.
With proxy i receive:
500 Chunked must be last Transfer-Encoding 'identity'
Proxy is working correctly (webbrowsers works fine with them)
What's wrong ?
Thanx
Michal
------------------------------
Date: Tue, 16 Jan 2007 14:02:19 +0000
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: Map Windows from Unix
Message-Id: <qdKdnZiI_sBiRzHYnZ2dnUVZ8sGvnZ2d@bt.com>
Tuhin wrote:
> Hi Mark,
>
> Here is what I am doing now:
>
> Step 1. Every month, I receive data on CD from another department.
> Step 2. Using Windows Explorer, I copy those data in the appropriate
> directory on a remote Unix server.
> Step 3. Then I connect to the Unix server using Exceed On Demand.
> Step 4. Then I run a Perl script (which I wrote on the Unix server) to
> generate some reports from those data.
>
> Now, here is what I am trying to do:
>
> I like to do Step 1 while sitting on the Unix server so that when I
> will run my Perl script, first it will prompt to copy the data from the
> CD. CD ROM is connected with the PC.
>
> Since I am new in the Perl world, my idea is, sitting on the Unix
> server if I can open the Windows Explorer (or any file selection dialog
> box that will display the directory structure of the PC), then I will
> be able to copy the data from the CD using my Perl script.
>
I'd write a HTML web page containing a form that prompts for the file to
be uploaded and which runs a CGI script to process the uploaded file and
return a web page summarising the results (even if it is just "file OK").
The first part of this is an HTML question not a Perl question so is a
bit off-topic here ...
<form enctype="multipart/form-data"
method=post
action="http://web.example.com/cgi/foo.pl">
File:
<input type=file name=textfile>
</form>
The second part is handling the submitted form in Perl. For which I
suggest CPAN.
Then the user just inserts the CD, opens the web page, clicks the button
and uses the file-chooser to select the file. Job done.
------------------------------
Date: 16 Jan 2007 14:03:16 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Map Windows from Unix
Message-Id: <514494F1hs55eU1@mid.dfncis.de>
Andrew DeFaria <Andrew@DeFaria.com> wrote in comp.lang.perl.misc:
> -=-=-=-=-=-
>
> Sherm Pendley wrote:
> > Andrew DeFaria <Andrew@DeFaria.com> writes:
> >
> >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> >>
> >> Tuhin wrote:
> >> <blockquote
> >> cite="mid1168914587.000083.127320@a75g2000cwd.googlegroups.com"
> > Please stop posting HTML gibberish. This is not the web, and your
> > posting style is very annoying to those of us who actually know what
> > we're doing.
> Last time I checked this was a free country (well at least where I'm
> posting from). Please stop telling me how to post. You might wish to get
> out of your holier then fucking thou chair while your at it...
Continue posting HTML and be ignored by those with a clue who don't
flame you. It's a free country, you know.
Anno
------------------------------
Date: Tue, 16 Jan 2007 13:01:26 -0000
From: Warren Block <wblock@wonkity.com>
Subject: Re: My program dies.
Message-Id: <slrneqpj56.1vtc.wblock@speedy.wonkity.com>
John Bokma <john@castleamber.com> wrote:
> Paul Pluzhnikov <ppluzhnikov-nsp@charter.net> wrote:
>
>> Hint: zombies exhaust your per-user process limit, and kernel
>> process table.
>
> And they eat the flesh of the living...
print unpack("u*","*0E)\!24Y3+BXN(```")x3
--
Warren Block * Rapid City, South Dakota * USA
------------------------------
Date: 16 Jan 2007 13:27:22 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: My program dies.
Message-Id: <51425qF1ilt74U1@mid.dfncis.de>
Krivenok Dmitry <krivenok.dmitry@gmail.com> wrote in comp.lang.perl.misc:
>
> John Bokma wrote:
> > Paul Pluzhnikov <ppluzhnikov-nsp@charter.net> wrote:
> >
> > > Hint: zombies exhaust your per-user process limit, and kernel
> > > process table.
>
> It's impossible.
> There is SIGCHLD handler in my code.
> ps output doesn't show any zombies.
The show your code (reduced to a minimum that still exhibits the
problem). Pseudo-code will only give you pseudo-answers.
Anno
------------------------------
Date: Tue, 16 Jan 2007 14:58:21 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: My program dies.
Message-Id: <qdmpq2l4ncvr2qpi8n1jdnqgochpersn42@4ax.com>
On 15 Jan 2007 22:40:44 -0800, "Krivenok Dmitry"
<krivenok.dmitry@gmail.com> wrote:
>> > Hint: zombies exhaust your per-user process limit, and kernel
>> > process table.
>
>It's impossible.
>There is SIGCHLD handler in my code.
Which you didn't show. So try to do as usual, that is prepare a
minimal but complete (as opposed to pseudocode) example still
exhibiting the problem.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 16 Jan 2007 02:49:42 -0800
From: "bernd" <bew_ba@gmx.net>
Subject: Position in an array
Message-Id: <1168944581.128435.300670@a75g2000cwd.googlegroups.com>
Hello folks,
just for confirmation: Is my assumption correct that there is no
"implicit" method to know the current index of an array (means: the
index of the item which is stored in $_ in a foreach-loop for example)
without using an "external" counter variable?
In the following I want to traverse the array @testarr and want to
treat the very first item (but it could be any other arbitrary item as
well) specially. Is there a way of "knowing" the index without using
the explicitly defined variable $count?
$count = 0 ;
foreach ( @testarr ) {
if ( $count == 0 ) { print $_ }
# same code for all items ....
$count++ ;
}
So, can I get rid of $count in some way (by using an implicit
mechanism) or do I have to live with this, IMO, long winded way.
Cheers
Bernd
------------------------------
Date: Tue, 16 Jan 2007 12:10:41 +0100
From: Robert 'phaylon' Sedlacek <rs@474.at>
Subject: Re: Position in an array
Message-Id: <45acb2b2$0$27621$9b4e6d93@newsspool2.arcor-online.net>
bernd wrote:
> $count = 0 ;
> foreach ( @testarr ) {
>
> if ( $count == 0 ) { print $_ }
>
> # same code for all items ....
>
> $count++ ;
> }
>
> So, can I get rid of $count in some way (by using an implicit
> mechanism) or do I have to live with this, IMO, long winded way.
How about
for my $x (0 .. $#testarr) {
print if $x == 0;
}
--
# Robert 'phaylon' Sedlacek
# Perl 5/Catalyst Developer in Hamburg, Germany
{ EMail => ' rs@474.at ', Web => ' http://474.at ' }
------------------------------
Date: Tue, 16 Jan 2007 12:22:21 +0100
From: Robert 'phaylon' Sedlacek <rs@474.at>
Subject: Re: Position in an array
Message-Id: <45acb56d$0$5714$9b4e6d93@newsspool3.arcor-online.net>
Robert 'phaylon' Sedlacek wrote:
> for my $x (0 .. $#testarr) {
> print if $x == 0;
> }
Of course that should be...
for my $x (0 .. $#testarr) {
print $testarr[ $x ] if $x == 0;
}
--
# Robert 'phaylon' Sedlacek
# Perl 5/Catalyst Developer in Hamburg, Germany
{ EMail => ' rs@474.at ', Web => ' http://474.at ' }
------------------------------
Date: 16 Jan 2007 11:23:29 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Position in an array
Message-Id: <513qthF1hsakeU1@mid.dfncis.de>
bernd <bew_ba@gmx.net> wrote in comp.lang.perl.misc:
> Hello folks,
>
> just for confirmation: Is my assumption correct that there is no
> "implicit" method to know the current index of an array (means: the
> index of the item which is stored in $_ in a foreach-loop for example)
> without using an "external" counter variable?
Right.
>
> In the following I want to traverse the array @testarr and want to
> treat the very first item (but it could be any other arbitrary item as
> well) specially. Is there a way of "knowing" the index without using
> the explicitly defined variable $count?
>
> $count = 0 ;
> foreach ( @testarr ) {
>
> if ( $count == 0 ) { print $_ }
>
> # same code for all items ....
>
> $count++ ;
> }
>
> So, can I get rid of $count in some way (by using an implicit
> mechanism) or do I have to live with this, IMO, long winded way.
Alternatively you can loop over the index set in the first place:
for my $count ( 0 .. $#testarr ) {
my $el = $testarr[ $count];
print $el unless $count;
# etc.
}
or variants thereof.
Anno
------------------------------
Date: Tue, 16 Jan 2007 12:22:18 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Position in an array
Message-Id: <eoicqu$ifm$1@mlucom4.urz.uni-halle.de>
Robert 'phaylon' Sedlacek wrote:
> bernd wrote:
>> $count = 0 ;
>> foreach ( @testarr ) {
>> if ( $count == 0 ) { print $_ }
>
> for my $x (0 .. $#testarr) {
> print if $x == 0;
> }
foreach ( @testarr ) {
print if $# == 0;
}
perl6?
Regards
Mirco
------------------------------
Date: 16 Jan 2007 03:27:56 -0800
From: "tfe" <tfeserver@gmail.com>
Subject: Re: Position in an array
Message-Id: <1168946876.362416.271040@l53g2000cwa.googlegroups.com>
Robert 'phaylon' Sedlacek a =E9crit :
> bernd wrote:
>
> > $count =3D 0 ;
> > foreach ( @testarr ) {
> >
> > if ( $count =3D=3D 0 ) { print $_ }
> >
> > # same code for all items ....
> >
> > $count++ ;
> > }
> >
> > So, can I get rid of $count in some way (by using an implicit
> > mechanism) or do I have to live with this, IMO, long winded way.
>
> How about
>
> for my $x (0 .. $#testarr) {
> print if $x =3D=3D 0;
> }
>
Might be
for my $x (0 .. $#testarr) {
print $testarr[$x] if $x =3D=3D 0;
}
or you should do $_ =3D $test[$x] at the start of the loop...
--=20
tfe
------------------------------
Date: 16 Jan 2007 11:40:04 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Position in an array
Message-Id: <513rskF1hsakeU2@mid.dfncis.de>
tfe <tfeserver@gmail.com> wrote in comp.lang.perl.misc:
>
> Robert 'phaylon' Sedlacek a écrit :
> > bernd wrote:
> >
> > > $count = 0 ;
> > > foreach ( @testarr ) {
> > >
> > > if ( $count == 0 ) { print $_ }
> > >
> > > # same code for all items ....
> > >
> > > $count++ ;
> > > }
> > >
> > > So, can I get rid of $count in some way (by using an implicit
> > > mechanism) or do I have to live with this, IMO, long winded way.
> >
> > How about
> >
> > for my $x (0 .. $#testarr) {
> > print if $x == 0;
> > }
> >
>
> Might be
> for my $x (0 .. $#testarr) {
> print $testarr[$x] if $x == 0;
> }
> or you should do $_ = $test[$x] at the start of the loop...
Doing it like that is a very bad idea. $_ is often aliased to
another variable. If it is when this code is called, "$_ = $test[$x]"
will assign the value to an unrelated variable somewhere in the
program, which can be a hard-to-find bug.
Before assigning to $_ you should at least localize the variable:
local $_ = $test[$x];
though a bug in Perl makes even that unsafe in some (rare) situations.
An alternative is another level of aliasing, through a one-shot do
(untested):
for my $x (0 .. $#testarr) {
for ( $testarr[ $x] = {
print unless $x;
# etc.
}
}
Anno
------------------------------
Date: 16 Jan 2007 04:53:20 -0800
From: "bernd" <bew_ba@gmx.net>
Subject: Re: Position in an array
Message-Id: <1168952000.243756.167960@v45g2000cwv.googlegroups.com>
@Robert: What You suggested is, basically, what I wanted to avoid (Your
$x is my $count). I think Anno is right: There is no more elegant way
(o.k., this thread made me sure at least ;-).
Thanks to all!
Bernd
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 35
*************************************