Hi Dr. Ruud! (and all).
See below for my response.
On Monday 21 Dec 2009 22:03:07 Dr.Ruud wrote:
> Bryan R Harris wrote:
> >> perl -wle '
> >>
> >> sub inc{ ++$_ for @_ }
> >>
> >> my @x = 1 .. 5;
> >>
> >> inc @x;
> >>
> >> print "@x";
> >> '
> >> 2 3 4 5 6
> >
> > FYI, the reason we wanted a reference was because the data set might end
> > up being huge.
>
> FYI, there is no issue.
>
> > Uh, come to think of it, I'm surprised your script does what it does.
> > I'd have thought that the changes made internal to inc would've stayed
> > there since they're not being "returned". This bothers me a little...
>
> It shouldn't bother you, it should make you aware that parameters in
> Perl are aliases, so there is no content copying happening until you
> code it.
>
>
> perl -wle'
>
> my @x = 0 .. 3;
> print "@x";
>
> ++$_ for grep $_, @x;
> print "@x";
>
> ++$_ for map $_, @x;
> print "@x";
> '
I appreciate all your help on the channel. However, I noticed that you keep
giving examples as one big perl -wle '....' block (with single-quotes). This
is:
-->
1. Error prone. What if someone changes the program to include a single-quote?
2. Won't work properly on Win32's CMD.EXE , which we may unfortunately still
need to accommodate for.
3. Very hard to experiment with on the shell, due to scrolling between such
large numbers.
4. Doesn't follow best practices of using "use strict;", "use warnings;", etc.
<--
As a result, I believe it would set a bad example, and that people may mis-
interpret it.
I suggest that instead you (or whoever) delimit a block using <<<< and >>>> or
{{{{ and }}}} or whatever you want and include a Perl program that you've
tested inside a file. E.g:
<<<<<<<<<<<<<
#!/usr/bin/perl -l
use strict;
use warnings;
my @x = 0 .. 3;
print "@x";
++$_ for grep $_, @x;
print "@x";
++$_ for map $_, @x;
print "@x";
>>>>>>>>>>>>>
Which ives me:
<<<<<<<<<<
shlomi:~$ perl test2.pl
0 1 2 3
0 2 3 4
0 2 3 4
>>>>>>>>>>
Which seems right.
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/
Bzr is slower than Subversion in combination with Sourceforge.
( By: http://dazjorz.com/ )
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/