Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Build your array with push

by radiantmatrix (Parson)
on Feb 01, 2006 at 16:35 UTC ( [id://527103]=note: print w/replies, xml ) Need Help??


in reply to Re: Build your array with push
in thread Build your array with push

I use the former idiom as well, but I've run across this style a couple of times, too:

my @array = ( 'Hibbs' ,'Daglish' ,'Schwartz' ,'Vroom' );

The one time I had the chance to actually ask a coder about that style, he gave me two rationales. First, he liked it because of a string-cat convention that's similar:

my $string = 'this is a very long string that has a certain number ' .$number .' of segments.' ."\n";

In print statements, this coder often mirrored that convention using commas instead of periods to pass the list of strings to print. (This is apparently faster, though it smacks of premature optimization to me. But I digress.)

The second reason was that he found the trailing comma to be confusing; by moving commas to the front, he provided a visual reminder to put the comma in when adding to the list but without the "confusing" trailing comma. To each their own, I guess.

Anyone have thoughts on this style? Just curious as to what advantages/disadvantages there might be.

<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

Replies are listed 'Best First'.
Re^3: Build your array with push
by ikegami (Patriarch) on Feb 06, 2006 at 17:50 UTC

    That doesn't really help here since you can't insert at the top safely.

    The style has been called The Perlish Coding Style. Accoding to that document, the following would be the proper alignment:

    { my @array = ( 'Hibbs' , 'Daglish' , 'Schwartz' , 'Vroom' ) ; my $string = 'this is a very long string that has a certain number ' . $number . ' of segments.' . "\n" }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://527103]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-03-29 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found