On Tue, Dec 22, 2009 at 02:29:53PM +0200, Shlomi Fish wrote:
> Hi Dr. Ruud! (and all).
>
> See below for my response.
>
> On Monday 21 Dec 2009 22:03:07 Dr.Ruud wrote:
> >
> > perl -wle'
> > my @x = 0 .. 3;
> > print "@x";
> > ++$_ for grep $_, @x;
> > print "@x";
> > +
> 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 i
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 r
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 scr
On Monday 21 Dec 2009 18:09:32 Bryan R Harris wrote:
> > Wagner, David --- Senior Programmer Analyst --- CFS wrote:
> >> You pass as a refernce as ni
> >> called_sub(\...@d);
> >> Now when you update, you are updating @d and not a copy.
> >
> > No need to use a reference for that:
> >
> > perl -wle
> On Wed, 16 Dec 2009 17:47:16 -0600, Bryan R Harris wrote:
>>> Okay, here's one I struggle with often -- is one of these better than
>>> the other?
>>>
>>> **
>>> A.
>>> if ( isFlat($tire) ) { changeTire($tire); }
>>>
>>> B.
>>> checkFlat
> On Wed, 16 Dec 2009 17:47:16 -0600, Bryan R Harris wrote:
>> Okay, here's one I struggle with often -- is one of these better than
>> the other?
>>
>> **
>> A.
>> if ( isFlat($tire) ) { changeTire($tire); }
>>
>> B.
>> checkFlatAndChange
> Wagner, David --- Senior Programmer Analyst --- CFS wrote:
>
>> You pass as a refernce as ni
>> called_sub(\...@d);
>> Now when you update, you are updating @d and not a copy.
>
> No need to use a reference for that:
>
> perl -wle '
>
> sub inc{ ++$_ for @_ }
>
> my @x = 1 .. 5;
>
>> What's the difference between pointers and references? Where can I read
>> about that difference?
>
> The key difference in my mind is this: Perl references are defined in
> terms of perl datatypes. C pointers are defined (more or less) in
> terms of memory locations.
>
> If you think about
>> Is there any way to make a new variable, @something, that is just another
>> name for the array that was passed in by reference? Since I'm building a
>> complex data structure, having to include all those @{}'s can get annoying.
>
> Elements of a hash referenced by $h can be accessed by $h->
From: Peter Scott
On Wed, 16 Dec 2009 17:47:16 -0600, Bryan R Harris wrote:
>> Okay, here's one I struggle with often -- is one of these better than
>> the other?
>>
>> **
>> A.
>> if ( isFlat($tire) ) { changeTire($tire); }
>>
>> B.
>> chec
Peter Scott wrote:
> Neither will you find Perl
> programmers enamored of Hungarian notation, for instance.
That's because there are few datatypes in Perl but context is
everything. It's hard to describe context using Hungarian notation. :)
--
Just my 0.0002 million dollars worth,
Shaw
On Wed, 16 Dec 2009 17:47:16 -0600, Bryan R Harris wrote:
> Okay, here's one I struggle with often -- is one of these better than
> the other?
>
> **
> A.
> if ( isFlat($tire) ) { changeTire($tire); }
>
> B.
> checkFlatAndChangeTireIfNecessa
Wagner, David --- Senior Programmer Analyst --- CFS wrote:
You pass as a refernce as ni
called_sub(\...@d);
Now when you update, you are updating @d and not a copy.
No need to use a reference for that:
perl -wle '
sub inc{ ++$_ for @_ }
my @x = 1 .. 5;
inc @x;
Bryan R Harris wrote:
>
>>> No other perl programmers here, unfortunately. Good advice, though.
>> Why don't you post your ideas here for criticism then? I wouldn't post
>> an entire several hundred line script, but you could post your
>> specification and your plan for writing a code which met s
>> No other perl programmers here, unfortunately. Good advice, though.
>
> Why don't you post your ideas here for criticism then? I wouldn't post
> an entire several hundred line script, but you could post your
> specification and your plan for writing a code which met said
> specification. If
2009/12/16 Bryan R Harris :
> What's the difference between pointers and references? Where can I read
> about that difference?
The key difference in my mind is this: Perl references are defined in
terms of perl datatypes. C pointers are defined (more or less) in
terms of memory locations.
If you
Jim Gibson wrote:
> If you pass an array by reference, there is no copy in the subroutine. Any
> changes you make to the array in the subroutine will be retained in the
> calling program after the subroutine returns.
You can use dclone() from Storable to copy deeply-nested data
structures. See `p
On 12/16/09 Wed Dec 16, 2009 6:57 AM, "Bryan R Harris"
scribbled:
>
>
> [stuff cut out]
>
>>> For example, if I'm populating a complex variable @d with
>>> lots of pointers,
>>> hashes, arrays, etc. within, if I populate that within a
>>> subroutine, how do
>>> I get it back out conveniently
On Wednesday 16 Dec 2009 16:57:01 Bryan R Harris wrote:
> [stuff cut out]
>
> >> For example, if I'm populating a complex variable @d with
> >> lots of pointers,
> >> hashes, arrays, etc. within, if I populate that within a
> >> subroutine, how do
> >> I get it back out conveniently without it mak
A couple responses, mixed in below:
> 2009/12/11 Bryan R Harris :
Seems like a waste to do step 2 in a subroutine since we only do it once,
but it does fill the main body of the script with code-noise that makes it
harder to debug overall logic problems... Not much logic here, b
[stuff cut out]
>> For example, if I'm populating a complex variable @d with
>> lots of pointers,
>> hashes, arrays, etc. within, if I populate that within a
>> subroutine, how do
>> I get it back out conveniently without it making a whole
>> nother copy of it
>> outside? If it's 500 MB, isn't
On Fri, Dec 11, 2009 at 12:06 PM, Philip Potter
wrote:
> The point is that in the first version, you are constantly bouncing
> from the big-picture ideas to the low-level messy details. By
> abstracting code out into subroutines populate_x(), populate_y() and
> process_xy(), you have the main scri
> -Original Message-
> From: Bryan R Harris [mailto:bryan_r_har...@raytheon.com]
> Sent: Friday, December 11, 2009 15:10
> To: Beginners Perl
> Subject: Re: being smart about script structure
>
>
>
>
> >> Seems like a waste to do step 2 in a su
2009/12/11 Bryan R Harris :
>>> Seems like a waste to do step 2 in a subroutine since we only do it once,
>>> but it does fill the main body of the script with code-noise that makes it
>>> harder to debug overall logic problems... Not much logic here, but
>>> certainly in more complex scripts.
>>
Bryan R Harris wrote:
> Let me guess, the number of lines on a standard terminal in the old days?
> =)
No, that was 25. But the last line was used for status by both vi and
emacs, so:
perl -le 'print scalar reverse "24"'
Actually, the number varies from as low as 20 to as high as 60. 60
being
>> Seems like a waste to do step 2 in a subroutine since we only do it once,
>> but it does fill the main body of the script with code-noise that makes it
>> harder to debug overall logic problems... Not much logic here, but
>> certainly in more complex scripts.
>
> A waste of what exactly? Yo
> Bryan R Harris wrote:
>>
>> I'm not even sure how to ask this question, but here goes:
>>
>> I struggle knowing how to structure my code, what things belong as their own
>> subroutines and what things can stay in the main script. How do the smart
>> guys make these decisions?
>>
>> For exam
Bryan R Harris wrote:
>
> I'm not even sure how to ask this question, but here goes:
>
> I struggle knowing how to structure my code, what things belong as their own
> subroutines and what things can stay in the main script. How do the smart
> guys make these decisions?
>
> For example, let's s
2009/12/11 Bryan R Harris :
> I'm not even sure how to ask this question, but here goes:
>
> I struggle knowing how to structure my code, what things belong as their own
> subroutines and what things can stay in the main script. How do the smart
> guys make these decisions?
>
> For example, let's
I'm not even sure how to ask this question, but here goes:
I struggle knowing how to structure my code, what things belong as their own
subroutines and what things can stay in the main script. How do the smart
guys make these decisions?
For example, let's say I need to:
1. Read a complex fil
31 matches
Mail list logo