Re: [Meta] Big examples as perl -e lines with single quotes [was Re: being smart about script structure]

2010-02-23 Thread Mike McClain
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"; > > +

Re: being smart about script structure

2009-12-22 Thread Bryan R Harris
> 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

[Meta] Big examples as perl -e lines with single quotes [was Re: being smart about script structure]

2009-12-22 Thread Shlomi Fish
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

Re: being smart about script structure

2009-12-22 Thread Dr.Ruud
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

Re: being smart about script structure

2009-12-21 Thread Shlomi Fish
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

Re: being smart about script structure

2009-12-21 Thread Bryan R Harris
> 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

Re: being smart about script structure

2009-12-21 Thread Bryan R Harris
> 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

Re: being smart about script structure

2009-12-21 Thread Bryan R Harris
> 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; >

Re: being smart about script structure

2009-12-21 Thread 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 think about

Re: being smart about script structure

2009-12-21 Thread Bryan R Harris
>> 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->

RE: being smart about script structure

2009-12-18 Thread Bob McConnell
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

Re: being smart about script structure

2009-12-17 Thread Shawn H Corey
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

Re: being smart about script structure

2009-12-17 Thread 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. > checkFlatAndChangeTireIfNecessa

Re: being smart about script structure

2009-12-16 Thread Dr.Ruud
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;

Re: being smart about script structure

2009-12-16 Thread Shawn H Corey
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

Re: being smart about script structure

2009-12-16 Thread Bryan R Harris
>> 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

Re: being smart about script structure

2009-12-16 Thread Philip Potter
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

Re: being smart about script structure

2009-12-16 Thread Shawn H Corey
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

Re: being smart about script structure

2009-12-16 Thread Jim Gibson
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

Re: being smart about script structure

2009-12-16 Thread Shlomi Fish
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

Re: being smart about script structure

2009-12-16 Thread Bryan R Harris
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

Re: being smart about script structure

2009-12-16 Thread Bryan R Harris
[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

Re: being smart about script structure

2009-12-12 Thread Robert Wohlfarth
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

RE: being smart about script structure

2009-12-12 Thread Wagner, David --- Senior Programmer Analyst --- CFS
> -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

Re: being smart about script structure

2009-12-12 Thread Philip Potter
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. >>

Re: being smart about script structure

2009-12-11 Thread Shawn H Corey
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

Re: being smart about script structure

2009-12-11 Thread 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. > > A waste of what exactly? Yo

Re: being smart about script structure

2009-12-11 Thread Bryan R Harris
> 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

Re: being smart about script structure

2009-12-11 Thread Shawn H Corey
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

Re: being smart about script structure

2009-12-11 Thread Philip Potter
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

being smart about script structure

2009-12-11 Thread 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 say I need to: 1. Read a complex fil