#!/usr/bin/perl

use 5.038.2;
# use utf8;
no warnings;

# ALGORITMO DE TRASPOSICION DE LINEAS

my $DEBUG = 0;

my $sep = "\n";

my $N = 24 + int(rand() * 2);
say "N = $N" if $DEBUG;

my $page;                      # Datos originales
for my $i ( 0 .. $N ){   # draw page, de 0 a 24 o 25 lineas
    $page .= "$i$sep";
}
screen( $page );

   
my @lines = split ( $sep , $page, -1 );      # with EOL to noEOL <-------- 
# third argument -1 split for one character separation

my $i = 0;
my $j = 0;
my @alter;                       # base 0 the @lines
while ($i <= $N){
    $alter[$i] = $lines[$i+1];   # 0 .. N and 0 .. j
    $i++ ;
    $alter[$i] = $lines[$i-1];
    last if ($i > $N);
    $i++;
    $j = $i +1; 
}
    
my $page;
for (0 .. $j){
    if (defined $alter[$_] && $alter[$_] =~ /\S/){            # def & auth
	$page .= "$alter[$_]$sep" ;
    }
}
 
screen ( $page );     # done. It hurts but...

exit 3;



sub screen {
    my $contenido = shift;
    die "Error: no hay contenido que mostrar" unless $contenido;
    my $par = "no";                 # se supone una cosa
    my $tamano = 0;
    while ( $contenido =~ /$sep/g ){            
	$tamano++;
    }
    $par = "sí" if ($tamano % 2 == 0);           
    my $marco = "-" x 52;
    print $contenido, "$marco   size $tamano   paridad $par\n";   
}


__END__
  
Este algoritmo me costó. Sólo hay que dibujar lo que quieres hacer.  

