] wrote:
-Original Message-
From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 10, 2005 8:55 AM
To: Marcos Rebelo
Cc: Perl Beginners
Subject: Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a-[EMAIL
PROTECTED]'
Marcos Rebelo wrote:
This is correctly
You should not fiddle with $[ though. Unless you are creating an
entry into the obfuscated code contest or a YAPH.
Thanks for the idea :)
@words = (another , hacker\n, Just , Perl );
eval '$[=' . $_ . ';print $words[3]' for 1, 3, 0, 2;
The eval is required because you can only set $_ to a
Jonathan Paton schreef:
You should not fiddle with $[ though. Unless you are creating an
entry into the obfuscated code contest or a YAPH.
Thanks for the idea :)
@words = (another , hacker\n, Just , Perl );
eval '$[=' . $_ . ';print $words[3]' for 1, 3, 0, 2;
The eval is required because you can
On Thu, Mar 10, 2005 at 11:10:06AM -0500, Wiggins d'Anconia wrote:
Btw ... What perldoc can I read to read about '$#'?
Not sure, a quick glance at perldata discusses the -1 index usage, but
didn't turn up $# that I could see. Its in the books :-).
wiggim$ perldoc perldata | fgrep -c '$#'
Marcos Rebelo wrote:
This is correctly printing '7' but '$a-[EMAIL PROTECTED]' seems to be encripted
code.
Can I write this in a cleaner way?
$a-[-1]; ???
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
On Thu, 10 Mar 2005 14:52:36 -, Marcos Rebelo
[EMAIL PROTECTED] wrote:
This is correctly printing '7' but '$a-[EMAIL PROTECTED]' seems to be
encripted
code.
Can I write this in a cleaner way?
perl -e '$a = [1,2,3,4,7]; print $a-[-1];'
--
Kind regards,
Hal Ashburner
--
To
;)
$a is an anonymous reference to the array defined
@$a resolves that reference
[EMAIL PROTECTED] prints out the index of the last element of array
$a-[elemmentnumber] is used to access an element thru an array reference.
so
$a-[EMAIL PROTECTED] simply gives you the last element of the array
This really works, I didn't now that.
Thanks
Marcos Rebelo
-Original Message-
From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
Sent: quinta-feira, 10 de Março de 2005 14:55
To: Marcos Rebelo
Cc: Perl Beginners
Subject: Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a-[EMAIL PROTECTED
-Original Message-
From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 10, 2005 8:55 AM
To: Marcos Rebelo
Cc: Perl Beginners
Subject: Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a-[EMAIL PROTECTED]'
Marcos Rebelo wrote:
This is correctly printing '7
Larsen, Errin M HMMA/IT wrote:
-Original Message-
From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 10, 2005 8:55 AM
To: Marcos Rebelo
Cc: Perl Beginners
Subject: Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a-[EMAIL PROTECTED]'
Marcos Rebelo wrote
SNIP
# or, since [EMAIL PROTECTED] will always be the index of the last
element of
the
array:
print $a-[-1]
Did I get it right? That looks like homework to me ... Why
would you
ever do that in a practical script?
--Errin
I think you got it. Ever want the
Larsen, Errin M HMMA/IT wrote:
SNIP
# or, since [EMAIL PROTECTED] will always be the index of the last
element of
the
array:
print $a-[-1]
Did I get it right? That looks like homework to me ... Why
would you
ever do that in a practical script?
--Errin
I think you got it. Ever want the
From: Larsen, Errin M HMMA/IT [EMAIL PROTECTED]
# [EMAIL PROTECTED] will be the number of elements in the array referenced
by
$a, minus one (or, '4', in this example)
Well, yes most likely it will be, but it doesn't have to ;-)
$#array is defined as the highest index in the array. The
13 matches
Mail list logo