Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-10 Thread Wiggins d'Anconia
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]
 



Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-10 Thread Harald Ashburner
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 unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-10 Thread Manav Mathur

;)

$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

an easier method(if you think so) might be

perl -e '$a=[1,2,3,4,76]; print $a->[EMAIL PROTECTED]'

-Original Message-
From: Marcos Rebelo [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 10, 2005 8:23 PM
To: Perl Beginners
Subject: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[EMAIL PROTECTED]'


This is correctly printing '7' but '$a->[EMAIL PROTECTED]' seems to be encripted
code.

Can I write this in a cleaner way?


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



*
Disclaimer:

The contents of this E-mail (including the contents of the enclosure(s) or 
attachment(s) if any) are privileged and confidential material of MBT and 
should not be disclosed to, used by or copied in any manner by anyone other 
than the intended addressee(s).   In case you are not the desired addressee, 
you should delete this message and/or re-direct it to the sender.  The views 
expressed in this E-mail message (including the enclosure(s) or attachment(s) 
if any) are those of the individual sender, except where the sender expressly, 
and with authority, states them to be the views of MBT.

This e-mail message including attachment/(s), if any, is believed to be free of 
any virus.  However, it is the responsibility of the recipient to ensure that 
it is virus free and MBT is not responsible for any loss or damage arising in 
any way from its use

*

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-10 Thread Marcos Rebelo
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]'


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]
 




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-10 Thread Larsen, Errin M HMMA/IT
> -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' but '$a->[EMAIL PROTECTED]' seems to be 
> > encripted code.
> > 
> > Can I write this in a cleaner way?
> > 
> > 
> 
> $a->[-1]; ???
> 
 Hi Wiggins,

  for those of us tryin' to keep up at home, can you walk us through
that bit a little?

  Here's what I spot:

  $a = [1,2,3,4,7] # this is initializing a scalar, $a, with a reference
to an array, [1,2,3,4,7]

 # $a-> this is dereferencing the array
 # as I understand it, and I really don't, the $#ARRAYNAME will give you
the number of elements, minus one, of an array?
 #  if that is the case, and then [EMAIL PROTECTED] ALSO derefernces the array, 
so
then
 #  [EMAIL PROTECTED] will be the number of elements in the array referenced by
$a, minus one (or, '4', in this example)

 # so
 print $a->[EMAIL PROTECTED]

 # is equivelant to
 print $a->[4]

 # 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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-10 Thread Wiggins d'Anconia
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:
This is correctly printing '7' but '$a->[EMAIL PROTECTED]' seems to be 
encripted code.

Can I write this in a cleaner way?

$a->[-1]; ???
 Hi Wiggins,
  for those of us tryin' to keep up at home, can you walk us through
that bit a little?
  Here's what I spot:
  $a = [1,2,3,4,7] # this is initializing a scalar, $a, with a reference
to an array, [1,2,3,4,7]
 # $a-> this is dereferencing the array
 # as I understand it, and I really don't, the $#ARRAYNAME will give you
the number of elements, minus one, of an array?
 #  if that is the case, and then [EMAIL PROTECTED] ALSO derefernces the array, 
so
then
 #  [EMAIL PROTECTED] will be the number of elements in the array referenced by
$a, minus one (or, '4', in this example)
Actually I wasn't quite convinced about the [EMAIL PROTECTED] construct. Because 
theoretically @$a has already dereferenced the array, but it appears 
Perl will just do the right thing (amazing how it does that).  It could 
be written as $#{$a} or even!! $#$a, but I am not entirely sure where to 
hunt in the docs to find that one, probably under the $# construct, but 
not sure what that is called. possibly in perlvar but I don't have the 
time to check, and I suspect John Krahn or somebody will chime in with 
something brilliant :-).

 # so
 print $a->[EMAIL PROTECTED]
 # is equivelant to
 print $a->[4]
 # 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 last item in a list, I can think of 
lots of reasons to want that...

http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-10 Thread Larsen, Errin M HMMA/IT

  <>

> >  # 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 last item in a list, I can think of 
> lots of reasons to want that...
> 
> http://danconia.org
> 

Yeah.  I agree.  However, I always use the $ARRAY[-1] (or,
$ARRAYREF->[-1]) syntax to get at the last element.

Why would I ever type: [EMAIL PROTECTED] ?!?

Btw ... What perldoc can I read to read about '$#'?

--Errin

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-10 Thread Wiggins d'Anconia
Larsen, Errin M HMMA/IT wrote:
  <>
# 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 last item in a list, I can think of 
lots of reasons to want that...

http://danconia.org

Yeah.  I agree.  However, I always use the $ARRAY[-1] (or,
$ARRAYREF->[-1]) syntax to get at the last element.
Why would I ever type: [EMAIL PROTECTED] ?!?
Uh, I wouldn't either, apparently if you didn't know about the -1 
capability like the OP :-). TMTOWTDI.

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 :-).

--Errin
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-10 Thread Jenda Krynicky
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 definition 
doesn't say anything about the number of elements. And while it's 
true that under normal circumstances Perl array indexes are zero 
based and thus the maximum index is the number of elements minus one 
it's not quaranteed.

#perl
$[ = 8;
@a = (1,2,3);

print "And the max index is: $#a\n";

You should not fiddle with $[ though. Unless you are creating an 
entry into the obfuscated code contest or a YAPH. 

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-11 Thread Gerhard Meier
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 '$#' 
6

/GM

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-12 Thread Jonathan Paton
> 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 constant
value.

Jonathan Paton

-- 
#!perl
$J=' 'x25 ;for (qq< 1+10 9+14 5-10 50-9 7+13 2-18 6+13
17+6 02+1 2-10 00+4 00+8 3-13 3+12 01-5 2-10 01+1 03+4
00+4 00+8 1-21 01+1 00+5 01-7 >=~/ \S\S \S\S /gx) {m/(
\d+) (.+) /x,, vec$ J,$p +=$2 ,8,= $c+= +$1} warn $J,,

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-12 Thread Hendrik Maryns
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 only set $_ to a constant
value.
Nice one!  I even think I understand it :-p
Shouldn't there be a ; after [3]?  But no, let me guess: you don't need 
to type the last ; of your program?

H.
--
Hendrik Maryns
Interesting websites:
www.lieverleven.be  (I cooperate)
www.eu04.comEuropean Referendum Campaign
aouw.orgThe Art Of Urban Warfare
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'

2005-03-14 Thread marcos rebelo
This was not a home work. In a real script I need to change the last
element of the array. Not changing the array it self.

I work with Perl for more than 4 years now. And after 4 years, I need this.

Thanks
MArcos


On Thu, 10 Mar 2005 09:06:52 -0600, Larsen, Errin M HMMA/IT
<[EMAIL PROTECTED]> 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 printing '7' but '$a->[EMAIL PROTECTED]' seems to be
> > > encripted code.
> > >
> > > Can I write this in a cleaner way?
> > >
> > >
> >
> > $a->[-1]; ???
> >
> Hi Wiggins,
> 
>  for those of us tryin' to keep up at home, can you walk us through
> that bit a little?
> 
>  Here's what I spot:
> 
>  $a = [1,2,3,4,7] # this is initializing a scalar, $a, with a reference
> to an array, [1,2,3,4,7]
> 
> # $a-> this is dereferencing the array
> # as I understand it, and I really don't, the $#ARRAYNAME will give you
> the number of elements, minus one, of an array?
> #  if that is the case, and then [EMAIL PROTECTED] ALSO derefernces the 
> array, so
> then
> #  [EMAIL PROTECTED] will be the number of elements in the array referenced by
> $a, minus one (or, '4', in this example)
> 
> # so
> print $a->[EMAIL PROTECTED]
> 
> # is equivelant to
> print $a->[4]
> 
> # 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
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]