Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl and indent

Reply
Thread Tools

perl and indent

 
 
Bill Cunningham
Guest
Posts: n/a
 
      10-27-2012
I use indent when I'm writing C code but I just started looking at perl.
I am in the perlintro document. Is there a way to use indent with perl?

Bill


 
Reply With Quote
 
 
 
 
Peter J. Holzer
Guest
Posts: n/a
 
      10-27-2012
On 2012-10-27 19:39, Bill Cunningham <(E-Mail Removed)> wrote:
> I use indent when I'm writing C code but I just started looking at perl.
> I am in the perlintro document. Is there a way to use indent with perl?


Use perltidy.

hp


--
_ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
|_|_) | Sysadmin WSR | Man feilt solange an seinen Text um, bis
| | | http://www.velocityreviews.com/forums/(E-Mail Removed) | die Satzbestandteile des Satzes nicht mehr
__/ | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      10-28-2012
"Bill Cunningham" <(E-Mail Removed)> wrote:
> I use indent when I'm writing C code but I just started looking at perl.
>I am in the perlintro document. Is there a way to use indent with perl?


Any editor used for programming should automatically indent program code
as it fits for the particular programming language. If it doesn't then
probably it misses many other useful features, too, and you may want to
consider using a different editor.

jue
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      10-29-2012
Henry Law wrote:
> I suspect there may be a precise technical meaning of "I use indent";
> if so then I'm about to sound like an idiot ...
>
> My experience of using indentation for Perl programming prompts these
> musings, which may be of help to you:
>
> * Your editor, if it's any good, probably has a mode for Perl. I use
> Emacs, which definitely does, and also Eclipse via the
> specifically-Perl "Epic" plug-in. The editor should handle
> indentation within braces, and aligning closing braces properly.
>
> * I find two characters of indentation plenty; three at most. You may
> need to customise your editor to get that.
>
> * I advocate using "soft tabs" (spaces) rather than hard tabs.
> Occasionally I'll "cat" (Linux) or "type" (Windows) a Perl file just
> to have a look at it and the built-in tab is usually far too big
> (like .

[snip]

I use nano. I'll check more into it. I'm new to Perl. I'm just now looking
at it as a second language along with C. So far it looks C like.

Bill


 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      10-30-2012
Henry Law <(E-Mail Removed)> wrote:
>On 29/10/12 17:35, Bill Cunningham wrote:
>
>> I use nano. I'll check more into it. I'm new to Perl. I'm just now looking
>> at it as a second language along with C. So far it looks C like.

>
>Bill, nice to have you aboard. Yes, it's C-like, and many of the
>differences are (IMO) improvements. But there are people who say "Don't
>write C in Perl; learn to write Perl" and if you read people's code
>you'll see -- at least partly -- what they mean.
>
>For example (and I'm only an amateur at this), the C structure for an
>"if" statement translates to Perl as this:


A far better example would be something, where there is no analog
construct in C, e.g. a foreach loop.
foreach my $elem (@list) {
process($elem);
}

Or filtering a list:
@foo = grep {!/^#/} @bar; # weed out lines that begin with #
Try writing this as concise in C.

jue
 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      10-30-2012
On 2012-10-30 01:16, Jürgen Exner wrote:
> Henry Law <(E-Mail Removed)> wrote:


>> For example (and I'm only an amateur at this), the C structure for an
>> "if" statement translates to Perl as this:
>> [... The code was removed, but why? ...]

>
> A far better example would be something, where there is no analog
> construct in C, e.g. a foreach loop.
> foreach my $elem (@list) {
> process($elem);
> }


I don't see what is 'far better' here. A while on an iterator would be
very similar in C.


An even more perlish alternative;

process($_) for @list;


> Or filtering a list:
> @foo = grep {!/^#/} @bar; # weed out lines that begin with #


That comment is more 'what' than 'why',
and that is already clear from the code.
Consider: "ignore comment lines".

--
Ruud

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      10-30-2012
"Dr.Ruud" <(E-Mail Removed)> wrote:
>On 2012-10-30 01:16, Jürgen Exner wrote:
>> Henry Law <(E-Mail Removed)> wrote:

>
>>> For example (and I'm only an amateur at this), the C structure for an
>>> "if" statement translates to Perl as this:
>>> [... The code was removed, but why? ...]

>>
>> A far better example would be something, where there is no analog
>> construct in C, e.g. a foreach loop.
>> foreach my $elem (@list) {
>> process($elem);
>> }

>
>I don't see what is 'far better' here. A while on an iterator would be
>very similar in C.


I respectfully disagree. The point is that in C you cannot access the
elements of an array or list without using an explicit index which means
you have to iterate (i.e. explicitely initialize, increment, and
terminate) over that index.

Therefore the difference is between
"with each element of the list do foobar()"
and
"initialize $i to start index;
as long as $i is smaller than the end index
{do foobar() with element array[$i] and increment $i}

To me it is a very major difference if I have to invent and maintain an
auxiliary index variable or not.

>An even more perlish alternative;
> process($_) for @list;


This is where _I_ would ask what is the difference to
foreach (@list) {process ($_)};

jue
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      10-31-2012
>>>>> "JE" == Jürgen Exner <(E-Mail Removed)> writes:

>> An even more perlish alternative;
>> process($_) for @list;


JE> This is where _I_ would ask what is the difference to
JE> foreach (@list) {process ($_)};

no block entry on each loop iteration which is overhead. also i would
almost never format a foreach loop on one line so the for modifier save
lines, pixels, {} chars and thousand of lost souls. actually fewer lines
mean fewer bugs given the old saw of 1 bug per 100 lines in any language
average.

i like foreach modifier a great deal and use it when i can.

uri
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      10-31-2012
>>>>> "S(J)M" == Shmuel (Seymour J ) Metz <(E-Mail Removed)> writes:

S(J)M> In <(E-Mail Removed)>, on 10/31/2012
S(J)M> at 12:27 AM, Uri Guttman <(E-Mail Removed)> said:

>> actually fewer lines mean fewer bugs


S(J)M> I've dealt with code that had no white space not required by the
S(J)M> language; it wasn't pretty. I'll take my code prettyprinted, TYVM.

i never said no white space. i said fewer lines when you can. foreach
modifier is one of those times. there is a balance to be found. foreach
modifier is a win for that and other reasons.

uri
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java 1.5.0_11: How to indent xml output by DOMImplementationLS and LSSerializer Rolf.Kemper@eu.necel.com Java 0 05-31-2007 08:12 AM
gnu indent: how to avoid extra indent? dt C Programming 4 12-31-2006 11:31 AM
Nested if and expected an indent block kagard@gmail.com Python 7 08-14-2006 08:42 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
Indent button and a keyboard in MS WORD and Excel ? Father Jack Hackett Computer Support 9 11-24-2004 03:39 PM



Advertisments