[ create a new paste ] login | about

Link: http://codepad.org/UO4hH4sQ    [ raw code | output | fork ]

Perl, pasted on Aug 18:
my $commentcol = 30;

my (@lines) = (";komentar - prva linija\n",
   	       "1234 X200.18Y50.41Z42.78\n",
   	       "5678 Y=452.54 Z28.10  X=94.75\n",
   	       "90 Z=12.689 Y87.91  X42.58\n",
   	       ";komentar - zadnja linija\n");

{ print <<HEADER; }
/* generirani podaci */

HEADER

print "Lines:\n";	#lines
for (@lines)
{     chomp;
      s/\r//;
      my $line = $_;	#$line je procitana linija
      my $code = '  ';
      my $data = $line;
      print "WHILE\n\n";
      print "\$data\@start = ".$data."\n\n";
      #while ($data =~ s/(X=?\d+\.?\d+|Y=?\d+\.?\d+|Z=?\d+\.?\d+)//)
      while ($data =~ s/(X=?\d+\.?\d+)|(Y=?\d+\.?\d+)|(Z=?\d+\.?\d+)//)
      {
      	print "\$data = ".$data."\n\n";		#nakon 'vadjenja' broja
      	print "\$1 = ".$1."\n\n";
      	print "\$2 = ".$2."\n\n";
      	print "\$3 = ".$3."\n\n";
      }
      print "END WHILE\n\n";
      $code .= ' 'x($commentcol-length($code));		#ubaci razmake
      $code .= "( $_ )\n";				#procitana linija
      print $code;					#ispisi liniju
}


Output:
/* generirani podaci */

Lines:
WHILE

$data@start = ;komentar - prva linija

END WHILE

                              ( ;komentar - prva linija )
WHILE

$data@start = 1234 X200.18Y50.41Z42.78

$data = 1234 Y50.41Z42.78

$1 = X200.18

$2 = 

$3 = 

$data = 1234 Z42.78

$1 = 

$2 = Y50.41

$3 = 

$data = 1234 

$1 = 

$2 = 

$3 = Z42.78

END WHILE

                              ( 1234 X200.18Y50.41Z42.78 )
WHILE

$data@start = 5678 Y=452.54 Z28.10  X=94.75

$data = 5678  Z28.10  X=94.75

$1 = 

$2 = Y=452.54

$3 = 

$data = 5678    X=94.75

$1 = 

$2 = 

$3 = Z28.10

$data = 5678    

$1 = X=94.75

$2 = 

$3 = 

END WHILE

                              ( 5678 Y=452.54 Z28.10  X=94.75 )
WHILE

$data@start = 90 Z=12.689 Y87.91  X42.58

$data = 90  Y87.91  X42.58

$1 = 

$2 = 

$3 = Z=12.689

$data = 90    X42.58

$1 = 

$2 = Y87.91

$3 = 

$data = 90    

$1 = X42.58

$2 = 

$3 = 

END WHILE

                              ( 90 Z=12.689 Y87.91  X42.58 )
WHILE

$data@start = ;komentar - zadnja linija

END WHILE

                              ( ;komentar - zadnja linija )


Create a new paste based on this one


Comments: