1999 twenty-four merry days of Perl Feed

Testing various indentation of verbatim code blocks

perl - 1999-12-07

1 space

 sub do_it {
     state $scalar = 137;
     state @array = qw( 1, 3, 7 );
     state %hash = map { $_, 1 } (1, 3, 7);

     if( exists $hash{$args[0]} ) { ... } # leave off the ->
 }

2 spaces

  sub do_it {
      state $scalar = 137;
      state @array = qw( 1, 3, 7 );
      state %hash = map { $_, 1 } (1, 3, 7);

      if( exists $hash{$args[0]} ) { ... } # leave off the ->
  }

3 spaces

   sub do_it {
       state $scalar = 137;
       state @array = qw( 1, 3, 7 );
       state %hash = map { $_, 1 } (1, 3, 7);
 
       if( exists $hash{$args[0]} ) { ... } # leave off the ->
   }

4 spaces

   sub do_it {
       state $scalar = 137;
       state @array = qw( 1, 3, 7 );
       state %hash = map { $_, 1 } (1, 3, 7);
 
       if( exists $hash{$args[0]} ) { ... } # leave off the ->
   }

5 spaces

     sub do_it {
         state $scalar = 137;
         state @array = qw( 1, 3, 7 );
         state %hash = map { $_, 1 } (1, 3, 7);
   
         if( exists $hash{$args[0]} ) { ... } # leave off the ->
     }

6 spaces

      sub do_it {
          state $scalar = 137;
          state @array = qw( 1, 3, 7 );
          state %hash = map { $_, 1 } (1, 3, 7);
    
          if( exists $hash{$args[0]} ) { ... } # leave off the ->
      }

1 tab

        sub do_it {
            state $scalar = 137;
            state @array = qw( 1, 3, 7 );
            state %hash = map { $_, 1 } (1, 3, 7);
        
            if( exists $hash{$args[0]} ) { ... } # leave off the ->
        }

2 tabs

                sub do_it {
                    state $scalar = 137;
                    state @array = qw( 1, 3, 7 );
                    state %hash = map { $_, 1 } (1, 3, 7);
                
                    if( exists $hash{$args[0]} ) { ... } # leave off the ->
                }
Gravatar Image This article contributed by: Thibault DUPONCHELLE <thibault.duponchelle@gmail.com>