IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Perl Discussion :

Perl efface la première ligne de code..


Sujet :

Langage Perl

  1. #1
    Candidat au Club
    Femme Profil pro
    Développeur Web
    Inscrit en
    Avril 2011
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Avril 2011
    Messages : 2
    Points : 2
    Points
    2
    Par défaut Perl efface la première ligne de code..
    Salut!

    J'ai un PERL script qui nettoie/remplace le code dans mes pages .ASP, mais pour une raison quelquonque, perl efface toujours la première ligne de code dans chacune de mes pages??! Je cherche maintenant depuis plusieurs heures sans en trouver la cause...J'espère que vous pouvez m'aider

    Voici le code en son entier, filelist.txt contient le lien vers mes pages ASP

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
     
    #!/usr/bin/perl
    use Cwd;
    use File::Find;
     
    	open (LISTFILE, "j:test_perl/filelist.txt") or die "I couldn't get at filelist.txt";
     
    		#print ("\n$LISTFILE\n");
     
        @listin = <LISTFILE>;
     
    # beginning of it all
     
        foreach $line (@listin) {
    	#print "\n$line";
    	$filepath = $line;
    	$filepath =~ s/\\/\//g;
     
    	$current = $filepath;
    	@folders = split ( "/" ,$filepath);
     
    	$dir = "";
    	foreach $folder (@folders){
     
    		#print "\n$folder\n";
    		unless ($folder =~ /html$|:$/)
    		{$dir = $dir . "/" . $folder;}
     
    		#print "\n$dir\n";
    		}
     
    	# work on current file
    	$flag=0;
    	$string_index=0;
    	$index_counter=0;
    	$num_spaces=0;
    	$spaceFlag=0;
        open(INFILE,"$current") || ((warn "Can't open file please check permissions of : $_\n") ); 
    	print "$current\n--------------------------------------------------------------------------\n";
    	while (<INFILE>) 
    	{ 
    		push @CODE, $_;
    		foreach $line (@CODE)
    		{	
     
    		# Update DC.title
     
    			if ($line =~ /<title>/)
    			{	
    				$titleline = $line;
    				$titleline =~ s/<title>(.*?)<\/title>/$1/;
    				$titleline =~ s/\n//g;
    			}
    			if ($line =~ /DC\.title/i)
    			{	
    				$line =~ s/content=\"(.*?)\" \/>/content=\"$titleline\" \/>/;
    			}	
    		# update dc.date.modified field with today's date
     
    			if ($line =~ /DC\.date\.modified/)
    			{
    				$line =~ s/content=\"(.*?)\" \//content=\"$today\" \//;
    			}
     
     
    		# replace blockquotes with div tags
     
    			if ($line =~ /<blockquote>/)
    			{
    				$line =~ s/<blockquote>/<div class=\"indent1\">\n/;
    				print "\nBlockquote open fixed\n";
    			}
     
    			if ($line =~ /<\/blockquote>/)
    			{
    				$line =~ s/<\/blockquote>/<\/div>\n/;
    				print "\nBlockquote close fixed\n";
    			}
     
    		# fix common link errors
    			$line =~ s/<span class="AddText_a">(.*?)<\/span>/\1/g; #remove color
    			$line =~ s/<span class="Text_deleted">(.*?)<\/span>//g; #remove deleted
     
    			$line =~ s/<h1 (.*?)align="(.*?)"(.*?)>/<h1 \1 class="align\2" \3>/g;
    			$line =~ s/<h2 (.*?)align="(.*?)"(.*?)>/<h2 \1 class="align\2" \3>/g;
    			$line =~ s/<h3 (.*?)align="(.*?)"(.*?)>/<h3 \1 class="align\2" \3>/g;
    			$line =~ s/<h4 (.*?)align="(.*?)"(.*?)>/<h4 \1 class="align\2" \3>/g;
    			$line =~ s/<h5 (.*?)align="(.*?)"(.*?)>/<h5 \1 class="align\2" \3>/g;
    			$line =~ s/<h6 (.*?)align="(.*?)"(.*?)>/<h6 \1 class="align\2" \3>/g;
     
    			$line =~ s/<span (.*?)align="(.*?)"(.*?)>/<span \1 class="align\2" \3>/g;
    			$line =~ s/<p (.*?)align="(.*?)"(.*?)>/<p \1 class="align\2" \3>/g;
    			$line =~ s/<a (.*?)align="(.*?)"(.*?)>/<a \1 class="align\2" \3>/g;
    			$line =~ s/<div (.*?)align="(.*?)"(.*?)>/<div \1 class="align\2" \3>/g;
    			$line =~ s/<ul (.*?)align="(.*?)"(.*?)>/<ul \1 class="align\2" \3>/g;
    			$line =~ s/<li (.*?)align="(.*?)"(.*?)>/<li \1 class="align\2" \3>/g;
    			$line =~ s/<em (.*?)align="(.*?)"(.*?)>/<em \1 class="align\2" \3>/g;
    			$line =~ s/<strong (.*?)align="(.*?)"(.*?)>/<strong \1 class="align\2" \3>/g;
     
     
    #removes double anchors 
    			$line =~ s/(-e\.asp\#[a-zA-Z0-9_]+)\#[a-zA-Z0-9_]+/\1/g;
    			$line =~ s/(-f\.asp\#[a-zA-Z0-9_]+)\#[a-zA-Z0-9_]+/\1/g;
     
    			$line =~ s/&isPrinting/&amp;isPrinting/g;
    			$line =~ s/&showonlyarticle/&amp;showonlyarticle/g;
    			$line =~ s/&form/&amp;form/g;
    			$line =~ s/&dept/&amp;dept/g;
     
    			$line =~ s/<u>/<span class="underline">/g;
    			$line =~ s/<\/u>/<\/span>/g;
     
     
     
    			#puts the capital letter for the justification
    			$line =~s/<(.*?) class="aligncenter"(.*?)>/<\1 class="alignCenter" \2>/g;
    			$line =~s/<(.*?) class="alignleft"(.*?)>/<\1 class="alignLeft" \2>/g;
    			$line =~s/<(.*?) class="alignright"(.*?)>/<\1 class="alignRight" \2>/g;
     
     
    		# remove style from all tags ->taf	
    			$line =~ s/<(.*?)style="(.*?)"(.*?)>/<\1\3>/g;
    			$line =~ s/<(.*?)class="style(.*?)"(.*?)>/<\1\3>/g;
     
    		# color removed - this line of code stores the first (.*?) in to $1 and second (.*?) in to $2 but to print use \1 and \2
    			$line =~ s/<(.*?)class="AddText(.*?)"(.*?)>/<\1\3>/g;
    			$line =~ s/<(.*?)class='AddText(.*?)'(.*?)>/<\1\3>/g;
     
    			$line =~ s/<span class="Text_deleted">(.*?)<\/span>//g;
     
    			$line =~ s/<h1 (.*?)class="Text_deleted"(\s*)>(.*?)<\/h1>//g; 
    			$line =~ s/<h2 (.*?)class="Text_deleted"(\s*)>(.*?)<\/h2>//g; 
    			$line =~ s/<h3 (.*?)class="Text_deleted"(\s*)>(.*?)<\/h3>//g; 
    			$line =~ s/<h4 (.*?)class="Text_deleted"(\s*)>(.*?)<\/h4>//g; 
    			$line =~ s/<h5 (.*?)class="Text_deleted"(\s*)>(.*?)<\/h5>//g; 
    			$line =~ s/<h6 (.*?)class="Text_deleted"(\s*)>(.*?)<\/h6>//g; 
    		#	if ($line =~ /<a (.[^>]*)class="Text_deleted"(.*?)>(.*?)<\/a>/){
    		#	print "\n1:  $line";
    		#	print "\n2:  $line";
    		#	}
    			$line =~ s/<s>(.*?)<\/s>//g;
    			$line =~ s/<a (.[^>]*)class="Text_deleted"(.*?)>(.*?)<\/a>//g;
    			$line =~ s/<em (.*?)class="Text_deleted">(.*?)<\/em>//g;
    			$line =~ s/<strong (.*?)class="Text_deleted">(.*?)<\/strong>//g;
     
    			$line =~ s/<div (.*?)class="Text_deleted">(.*?)<\/div>//g;
    			$line =~ s/<li class="Text_deleted">(.*?)<\/li>//g;
    			$line =~ s/<ul (.*?)class="Text_deleted">(.*?)<\/ul>//g; 
    			$line =~ s/<p (.*?)class="Text_deleted"(.*?)>(.*?)<\/p>//g; 
     
    			$line =~ s/<th (.*?)class="Text_deleted"(.*?)>(.*?)<\/th>//g;
    			$line =~ s/<td (.*?)class="Text_deleted"(.*?)>(.*?)<\/td>/<td \1\2>&nbsp;<\/td>/g;
    			#$line =~ s/<tr (.*?)class="Text_deleted"(.*?)>(.*?)<\/tr>/<tr \1\2>&nbsp;<\/tr>/g;
     
     
    			#$line =~ s/<(.*?) class="Text_deleted">(.*?)<\/\1>/\ /g;
    			#$line =~ s/<(.*?)class="Text_deleted"(.*?)>(.*?)<\/\1>/\ /g;
     
    			$line =~ s/<span class="AddText_a">new hyperlink	<\/span>//g;
     
     
    		#font tag cleanup
    			$line =~ s/<font (.*?)>//g;
    			$line =~ s/<\/font>//g;
     
    		# illegal character cleanup
    			$line =~ s/ndash/nbsp;-&nbsp/g;
    			$line =~ s/\#8211/nbsp;-&nbsp/g;
    			$line =~ s/mdash/nbsp;-&nbsp/g;
    			$line =~ s/\#8212/nbsp;-&nbsp/g;
    			$line =~ s/\#8209/nbsp;-&nbsp/g;
     
    		# accented character conversion
    			$line =~ s/à/&agrave;/g;
    			$line =~ s/À/&Agrave;/g;
    			$line =~ s/â/&acirc;/g;
    			$line =~ s/Â/&Acirc;/g;
    			$line =~ s/ç/&ccedil;/g;
    			$line =~ s/Ç/&Ccedil;/g;
    			$line =~ s/é/&eacute;/g;
    			$line =~ s/É/&Eacute;/g;
    			$line =~ s/è/&egrave;/g;
    			$line =~ s/È/&Egrave;/g;
    			$line =~ s/ê/&ecirc;/g;
    			$line =~ s/Ê/&Ecirc;/g;
    			$line =~ s/ë/&euml;/g;
    			$line =~ s/Ë/&Euml;/g;
    			$line =~ s/î/&icirc;/g;
    			$line =~ s/Î/&Icirc;/g;
    			$line =~ s/ï/&iuml;/g;
    			$line =~ s/Ï/&Iuml;/g;
    			$line =~ s/ô/&ocirc;/g;
    			$line =~ s/Ô/&Ocirc;/g;
    			$line =~ s/ù/&ugrave;/g;
    			$line =~ s/Ù/&Ugrave;/g;
    			$line =~ s/û/&ucirc;/g;
    			$line =~ s/Û/&Ucirc;/g;
    			$line =~ s/ü/&uuml;/g;
    			$line =~ s/Ü/&Uuml;/g;
    			$line =~ s/’/&acute;/g;
    			$line =~ s/–/&ndash;/g;		
     
     
    		# wrap phone number with noWrap style
     
    			unless ($line =~ /<span class="noWrap">/)
    			{
    				$line =~ s/(\d)\-(\d{3})\-(\d{3})\-(\d{4})/<span class="noWrap">$1\-$2\-$3\-$4<\/span>/g;
    			}
     
    			unless ($line =~ /<span class="noWrap">/)
    			{
    				$line =~ s/(\d{3})\-(\d{3})\-(\d{4})/<span class="noWrap">$1\-$2\-$3<\/span>/g;
    			}
     
     
    		# here is where we figure out how many leading spaces in the line
    		# first don't touch first two lines
    			if ($flag>=1)
    			{
    				if ($spaceFlag==0)
    				{
    					# if spaceFlag is 0, then we need to calculate the leading spaces
    					$string_index = index($line," ",0);
    					if ($string_index==0) # we have first leading space
    					{	
    						#print("space counting loop");
    						$index_counter=$string_index+1;
    						$num_spaces=1;
    						$compare_index=0;
    						while ($compare_index==0)
    						{	
    							$string_index = index($line," ",$index_counter);
    							$compare_index = $index_counter-$string_index;
    							if (($string_index!=-1)&&($compare_index==0))
    							{
    								$num_spaces+=1;
    								$index_counter=$string_index+1; # the +1 moves counter to one after last find
    								#print($index_counter);
    								#print(" DEEP\n");
    								#print($num_spaces);
    							}
    						#print($string_index);
    						#print(" - inside loop \n");
    						}
    					}
    				}
    				#print($num_spaces);
    				$spaceFlag=100; # make it non-zero, reset at next file
    				$line =~ s/^ {$num_spaces}//;# okay, try this
    			}
    			else
    			{
    				#only get here for the first line, therefore only the DOCTYPE statment/tag will be affected
    				#print("other end of if statement \n");
    				$line =~ s/^ +//;
    			}
    		$line=~ s/<h1>(\s*)<\/h1>//g;
    		$line=~ s/<h2>(\s*)<\/h2>//g;
    		$line=~ s/<h3>(\s*)<\/h3>//g;
    		$line=~ s/<h4>(\s*)<\/h4>//g;
    		$line=~ s/<h5>(\s*)<\/h5>//g;
    		$line=~ s/<h6>(\s*)<\/h6>//g;
     
     
    		$line=~ s/<li>(\s*)<\/li>//g;
    		$line=~ s/<ul>(\s*)<\/ul>//g;
    		$line=~ s/<p>(\s*)<\/p>//g;
    		$line=~ s/<strong>(\s*)<\/strong>//g;
    		$line=~ s/<span>(\s*)<\/span>//g;
    		$line=~ s/<div>(\s*)<\/div>//g;
     
    			# convert remaining spaces into tabs
    			$line =~ s/^ +/\t/;
    			$flag+=1;
    		}
    	}	
     
    	close(INFILE);
    	open(OUTFILE, ">$current") || ((warn "Can't open the file $_ please make sure it had write access\n\n"), next FILE);
    	#print OUTFILE TRIM("@CODE");
    	#print OUTFILE "@CODE";
    	$flag=0;
        $size = @CODE;
    	print OUTFILE "\n";
     
    	for ($count=1; $count<=$size; $count++)
    	{
    		$CODE[$count]=~ s/<h1>(\s*)<\/h1>//g;
    		$CODE[$count]=~ s/<h2>(\s*)<\/h2>//g;
    		$CODE[$count]=~ s/<h3>(\s*)<\/h3>//g;
    		$CODE[$count]=~ s/<h4>(\s*)<\/h4>//g;
    		$CODE[$count]=~ s/<h5>(\s*)<\/h5>//g;
    		$CODE[$count]=~ s/<h6>(\s*)<\/h6>//g;
     
    		$CODE[$count]=~ s/<li>(\s*)<\/li>//g;
    		$CODE[$count]=~ s/<ul>(\s*)<\/ul>//g;
    		$CODE[$count]=~ s/<p>(\s*)<\/p>//g;
    		$CODE[$count]=~ s/<strong>(\s*)<\/strong>//g;
    		$CODE[$count]=~ s/<span>(\s*)<\/span>//g;
    		$CODE[$count]=~ s/<div>(\s*)<\/div>//g;
     
    		if ($CODE[$count] =~ /<table (.*?)class="Text_deleted"(.*?)>(.*$)/){
    			$CODE[$count]=~ s/<table (.*?)class="Text_deleted"(.*?)>(.*$)//g;
    			#print OUTFILE $CODE[$count];
    			$count=$count+1;
    			while($CODE[$count] !~ /<\/table>/){
    				if ($CODE[$count] =~ /<table (.*?)>/){
    					all_remove("table",$count)
    				}
    				$CODE[$count]=~ s/(.*?)//g;
    			}	
    		    continue {
    				$count=$count+1;
        		}
     
    			$CODE[$count]=~ s/(^.*)<\/table>//g;
    		}
    	#if ($count>257){
    	#print "\n$CODE[$count]";
    	#print "-->$count<--";
    	#}
     
    		if ($CODE[$count] =~ /<tr (.*?)class="Text_deleted"(.*?)>(.*$)/){
    			$CODE[$count]=~ s/<tr (.*?)class="Text_deleted"(.*?)>(.*$)//g;
    			#print OUTFILE $CODE[$count];
    			$count=$count+1;
     
    			while($CODE[$count] !~ /<\/tr>/){
    				if ($CODE[$count] =~ /<tr (.*?)>/){
    					all_remove("tr",$count)
    				}
     
    				$CODE[$count]=~ s/(.*?)//g;
    			}	
    		    continue {
    				$count=$count+1;
        		}
     
    			$CODE[$count]=~ s/(^.*)<\/tr>//g;
    		}
     
    		if ($CODE[$count] =~ /<td (.[^>]*)class="Text_deleted"(.*?)>(.*?)/){
    	#	print "\n$count:  $CODE[$count]";
    			$CODE[$count]=~ s/<td (.*?)class="Text_deleted"(.*?)>(.*$)/<td \1\2>/g;
    			$CODE[$count]=~ s/<td (.*?)class="Text_deleted"(.*?)>/<td \1\2>/g;
    			print OUTFILE $CODE[$count];
    			$count=$count+1;
     
    			while($CODE[$count] !~ /<\/td>/){
    				$CODE[$count]=~ s/(.*?)//g;
    			}	
    		    continue {
    				$count=$count+1;
        		}
     
    			$CODE[$count]=~ s/(^.*)<\/td>/<\/td>/g;
    		}
     
    		if ($CODE[$count] =~ /<ul (.*?)class="Text_deleted"(.*?)>(.*?)/){
    			$CODE[$count]=~ s/<ul (.*?)class="Text_deleted"(.*?)>(.*$)//g;
    			#print OUTFILE $CODE[$count];
    			$count=$count+1;
     
    			while($CODE[$count] !~ /<\/ul>/){
    				if ($CODE[$count] =~ /<ul (.*?)>/){
    					all_remove("ul",$count)
    				}
    				$CODE[$count]=~ s/(.*?)//g;
    			}	
    		    continue {
    				$count=$count+1;
        		}
     
    			$CODE[$count]=~ s/(.*?)<\/ul>//g;
    		}
    #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
     
    		if ($CODE[$count] =~ /(.*?)<ul>(\s+$)/){
    			if (($CODE[$count+1] =~ /(^\s*)<ul>/) && ($CODE[$count+2] !~ /<ul>/)){
    				$CODE[$count]=~ s/(.*?)<ul>/\1/g;
    				$CODE[$count+1]=~ s/<ul>/<ul class="whitecircle">/g;
     
    				while($CODE[$count] !~ /<\/ul>/){
    					if ($CODE[$count] =~ /<li (.*)class="Text_deleted"(.*?)>(.*?)/){
    						$CODE[$count]=~ s/<li (.*)class="Text_deleted"(.*?)>(.*?)//g;
    						#print OUTFILE $CODE[$count];
    						$count=$count+1;
    						litext_remove($count);
    					}
     
    					print OUTFILE $CODE[$count];
    				}	
    		   		continue {
    					$count=$count+1;
    					if ($CODE[$count] =~ /(.*?)<ul>/){
    						while($CODE[$count] !~ /<\/ul>/){
    							if ($CODE[$count] =~ /<li (.*)class="Text_deleted"(.*?)>(.*?)/){
    								$CODE[$count]=~ s/<li (.*)class="Text_deleted"(.*?)>(.*?)//g;
    								#print OUTFILE $CODE[$count];
    								$count=$count+1;
    								litext_remove($count);
    							}
    							print OUTFILE $CODE[$count];
    							#print "\n$CODE[$count]";
    						}	
    		   				continue {			
    							$count=$count+1;
    		    			}
    						print OUTFILE $CODE[$count];
    						$count=$count+1;
    					}
    	    		}
    				$CODE[$count]=~ s/<\/ul>//g;
    				#$count=$count+1;
    			}
    			if (($CODE[$count+1] =~ /(^\s*)<ul>(\s+$)/) && ($CODE[$count+2] =~ /(^\s*)<ul>/)){
    				$CODE[$count]=~ s/(.*?)<ul>/\1/g;
    				$CODE[$count+1]=~ s/<ul>//g;
    				$CODE[$count+2]=~ s/<ul>/<ul class="blacksquare">/g;
     
    				while($CODE[$count] !~ /<\/ul>/){
    					if ($CODE[$count] =~ /<li (.*)class="Text_deleted"(.*?)>(.*?)/){
    						$CODE[$count]=~ s/<li (.*)class="Text_deleted"(.*?)>(.*?)//g;
    						#print OUTFILE $CODE[$count];
    						$count=$count+1;
    						litext_remove($count);
    					}
    					print OUTFILE $CODE[$count];
    				}	
    		   		continue {
    					$count=$count+1;
    					if ($CODE[$count] =~ /(.*?)<ul>/){
    						while($CODE[$count] !~ /<\/ul>/){
    							if ($CODE[$count] =~ /<li (.*)class="Text_deleted"(.*?)>(.*?)/){
    								$CODE[$count]=~ s/<li (.*)class="Text_deleted"(.*?)>(.*?)//g;
    								#print OUTFILE $CODE[$count];
    								$count=$count+1;
    								litext_remove($count);
    							}
    							print OUTFILE $CODE[$count];
    							#print "\n$CODE[$count]";
    						}	
    		   				continue {
    							$count=$count+1;
    		    			}
    						print OUTFILE $CODE[$count];
    						$count=$count+1;
    					}
    	    		}
    				$CODE[$count]=~ s/<\/ul>//g;
    				$count=$count+1;
    				$CODE[$count]=~ s/<\/ul>//g;
    			}
    			if (($CODE[$count+1] =~ /^\s*$/) && ($CODE[$count+2] =~ /<\/ul>/)){
    				$CODE[$count]=~ s/(.*?)<ul>/\1/g;
    				$CODE[$count+2]=~ s/<\/ul>(.*?)/\1/g;
    			}			
    			print OUTFILE $CODE[$count];
    			$count=$count+1;
     
    		}		
     
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    		if ($CODE[$count] =~ /<li class="Text_deleted">(.*$)/){		
    			$CODE[$count]=~ s/<li class="Text_deleted">(.*$)//g;
    			$count=$count+1;
    			litext_remove($count);
    		}
    		if ($CODE[$count] =~ /<span (.*?)class="Text_deleted"(.*?)>(.*$)/){
    			if ($CODE[$count]=~ /<span class="Text_deleted">(.*$)/) {
    				$CODE[$count]=~ s/<span class="Text_deleted">(.*$)//g;
    			}
    			else {
    				$CODE[$count]=~ s/<span (.*?)class="Text_deleted"(.*?)>(.*$)//g;
    			}
    			#print "\n$CODE[$count]";
    			print OUTFILE $CODE[$count];
    			$count=$count+1;
     
    			while($CODE[$count] !~ /(.*?)<\/span>/){
    				if ($CODE[$count] =~ /<span (.*?)>/){
    					all_remove("span",$count)
    				}
    				$CODE[$count]=~ s/(.*?)//g;
    			}	
    		    continue {
    				$count=$count+1;
        		}
     
    			$CODE[$count]=~ s/(.*?)<\/span>//g;
    		}
    		if ($CODE[$count] =~ /<p (.*?)class="Text_deleted"(.*?)>(.*$)/){
    			#print "\n$CODE[$count]";
    			$CODE[$count]=~ s/<p (.*?)class="Text_deleted"(.*?)>(.*$)//g;
    			#print"\nhere:  $CODE[$count]";
    			$count=$count+1;
     
    			while($CODE[$count] !~ /<\/p>/){
    				if ($CODE[$count] =~ /<p (.*?)>/){
    					all_remove("p",$count)
    				}
    				$CODE[$count]=~ s/(.*?)//g;
    			}	
    		    continue {
    				$count=$count+1;
        		}
     
    			$CODE[$count]=~ s/(.*?)<\/p>//g;
    		}
     
    		if ($CODE[$count] =~ /<div (.*?)class="Text_deleted"(.*?)>(.*$)/){
    			#print "\n$CODE[$count]";
    			$CODE[$count]=~ s/<div (.*?)class="Text_deleted"(.*?)>(.*$)//g;
    			$count=$count+1;
     
    			while($CODE[$count] !~ /<\/div>/){
    				if ($CODE[$count] =~ /<div (.*?)>/){
    					all_remove("div",$count)
    				}
    				$CODE[$count]=~ s/(.*?)//g;
    			}	
    		    continue {
    				$count=$count+1;
        		}
     
    			$CODE[$count]=~ s/(.*?)<\/div>//g;
    		}
    		if ($CODE[$count] =~ /<em (.*?)class="Text_deleted"(.*?)>(.*$)/){
    			if ($CODE[$count]=~ /<em class="Text_deleted">(.*$)/) {
    				$CODE[$count]=~ s/<em class="Text_deleted">(.*$)//g;
    			}
    			else {
    				$CODE[$count]=~ s/<em (.*?)class="Text_deleted"(.*?)>(.*$)//g;
    			}
    			#print "\n$CODE[$count]";
    			print OUTFILE $CODE[$count];
    			$count=$count+1;
     
    			while($CODE[$count] !~ /(.*?)<\/em>/){
    				if ($CODE[$count] =~ /<em (.*?)>/){
    					all_remove("em",$count)
    				}
    				$CODE[$count]=~ s/(.*?)//g;
    			}	
    		    continue {
    				$count=$count+1;
        		}
     
    			$CODE[$count]=~ s/(.*?)<\/em>//g;
    		}
     
    		if ($CODE[$count] =~ /<a (.*?)class="Text_deleted"(.*?)>(.*$)/){
    			if ($CODE[$count]=~ /<a class="Text_deleted">(.*$)/) {
    				$CODE[$count]=~ s/<a class="Text_deleted">(.*$)//g;
    			}
    			else {
    				$CODE[$count]=~ s/<a (.*?)class="Text_deleted"(.*?)>(.*$)//g;
    			}
    			#print "\n$CODE[$count]";
    			print OUTFILE $CODE[$count];
    			$count=$count+1;
     
    			while($CODE[$count] !~ /(.*?)<\/a>/){
    				if ($CODE[$count] =~ /<a (.*?)>/){
    					all_remove("a",$count)
    				}
    				$CODE[$count]=~ s/(.*?)//g;
    			}	
    		    continue {
    				$count=$count+1;
        		}
     
    			$CODE[$count]=~ s/(.*?)<\/a>//g;
    		}
     
    		if ($CODE[$count] =~ /<div (.*?)>(\s+$)/ || $CODE[$count] =~ /<div>(\s+$)/){# <DIV>
    			if (($CODE[$count] =~ /<div(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<div>(\s+$)/){
    				emptyTags_removed("div",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<p (.*?)>(\s+$)/ || $CODE[$count] =~ /<p>(\s+$)/){# <P>
    			if (($CODE[$count] =~ /<p(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<p>(\s+$)/){
    				emptyTags_removed("p",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<span (.*?)>(\s+$)/ || $CODE[$count] =~ /<span>(\s+$)/){# <SPAN>
    			if (($CODE[$count] =~ /<span(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<span>(\s+$)/){
    				emptyTags_removed("span",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<tr (.*?)>(\s+$)/ || $CODE[$count] =~ /<tr>(\s+$)/){# <TR>
    			if (($CODE[$count] =~ /<tr(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<tr>(\s+$)/){
    				emptyTags_removed("tr",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<li (.*?)>(\s+$)/ || $CODE[$count] =~ /<li>(\s+$)/){# <LI>
    			if (($CODE[$count] =~ /<li(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<li>(\s+$)/){
    				emptyTags_removed("li",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<ul (.*?)>(\s+$)/ || $CODE[$count] =~ /<ul>(\s+$)/){# <UL>
    		#print "\n$count: $CODE[$count]";
    			if (($CODE[$count] =~ /<ul(.[^>]*)>(\s+$)/) || ($CODE[$count] =~ /<ul>(\s+$)/)){
    				emptyTags_removed("ul",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<table (.*?)>(\s+$)/ || $CODE[$count] =~ /<table>(\s+$)/){# <TABLE>
    			if (($CODE[$count] =~ /<table(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<table>(\s+$)/){
    				emptyTags_removed("table",$count);
    			}
    		}
    		 print OUTFILE $CODE[$count];
    	} 
     
    	close(OUTFILE);	
     
     
    	open(LASTFILE, ">$current") || ((warn "Can't open the file $_ please make sure it had write access\n\n"), next FILE);
    	$flag=0;
        $size = @CODE;
    	print LASTFILE "\n";
     
    	for ($count=1; $count<=$size; $count++){
    		$CODE[$count]=~ s/<h1>(\s*)<\/h1>//g;
    		$CODE[$count]=~ s/<h2>(\s*)<\/h2>//g;
    		$CODE[$count]=~ s/<h3>(\s*)<\/h3>//g;
    		$CODE[$count]=~ s/<h4>(\s*)<\/h4>//g;
    		$CODE[$count]=~ s/<h5>(\s*)<\/h5>//g;
    		$CODE[$count]=~ s/<h6>(\s*)<\/h6>//g;
     
    		$CODE[$count]=~ s/<li>(\s*)<\/li>//g;
    		$CODE[$count]=~ s/<ul>(\s*)<\/ul>//g;
    		$CODE[$count]=~ s/<p>(\s*)<\/p>//g;
    		$CODE[$count]=~ s/<strong>(\s*)<\/strong>//g;
    		$CODE[$count]=~ s/<span>(\s*)<\/span>//g;
    		$CODE[$count]=~ s/<div>(\s*)<\/div>//g;
     
    		if ($CODE[$count] =~ /<div (.*?)>(\s+$)/ || $CODE[$count] =~ /<div>(\s+$)/){# <DIV>
    			if (($CODE[$count] =~ /<div(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<div>(\s+$)/){
    				emptyTags_removed("div",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<p (.*?)>(\s+$)/ || $CODE[$count] =~ /<p>(\s+$)/){# <P>
    			if (($CODE[$count] =~ /<p(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<p>(\s+$)/){
    				emptyTags_removed("p",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<span (.*?)>(\s+$)/ || $CODE[$count] =~ /<span>(\s+$)/){# <SPAN>
    			if (($CODE[$count] =~ /<span(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<span>(\s+$)/){
    				emptyTags_removed("span",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<tr (.*?)>(\s+$)/ || $CODE[$count] =~ /<tr>(\s+$)/){# <TR>
    			if (($CODE[$count] =~ /<tr(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<tr>(\s+$)/){
    				emptyTags_removed("tr",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<li (.*?)>(\s+$)/ || $CODE[$count] =~ /<li>(\s+$)/){# <LI>
    			if (($CODE[$count] =~ /<li(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<li>(\s+$)/){
    				emptyTags_removed("li",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<ul (.*?)>(\s+$)/ || $CODE[$count] =~ /<ul>(\s+$)/){# <UL>
    		#print "\n$count: $CODE[$count]";
    			if (($CODE[$count] =~ /<ul(.[^>]*)>(\s+$)/) || ($CODE[$count] =~ /<ul>(\s+$)/)){
    				emptyTags_removed("ul",$count);
    			}
    		}
    		if ($CODE[$count] =~ /<table (.*?)>(\s+$)/ || $CODE[$count] =~ /<table>(\s+$)/){# <TABLE>
    			if (($CODE[$count] =~ /<table(.[^>]*)>(\s+$)/) || $CODE[$count] =~ /<table>(\s+$)/){
    				emptyTags_removed("table",$count);
    			}
    		}
    		print LASTFILE $CODE[$count];
    	}
     
     
    	close(LASTFILE);	
    }
     
    	print ("\nDone\n");
    	$st = <STDIN>;
     
     
    	sub litext_remove{
    		my $valt = $_[0];
     
    			while($CODE[$valt] !~ /<\/li>/){
    				if (($CODE[$valt] =~ /<li(.*?)>(.*$)/) && ($CODE[$valt] !~ /<li(.*?)>(.*?)<\/li>/)){
    					$CODE[$valt]=~ s/<li(.*?)>(.*$)//g;
    					$valt=$valt+1;
    					litext_remove($valt)
    				}
    				$CODE[$valt]=~ s/(.*?)//g;
    			}	
    		    continue {
    				$valt=$valt+1;
    				while ($CODE[$valt] =~ /<li(.*?)>(.*?)<\/li>/){
    					$CODE[$valt] =~ s/<li(.*?)>(.*?)<\/li>//g;
    				}
    			    continue {
    					$valt=$valt+1;
       				}
       			}
    			$CODE[$valt]=~ s/(.*?)<\/li>//g;
     
    	}
     
    	sub all_remove {
         my $val = $_[0];
    	 my $val2 = $_[1];
    			if ($CODE[$val2] =~ /<$val (.*?)>/){
    				$CODE[$val2]=~ s/<$val (.*?)>//g;
    				while($CODE[$val2] !~ /<\/$val>/){
    					if ($CODE[$val2] =~ /<$val(.*?)>/){
    						#$CODE[$valt2]=~ s/<$val(.*?)>//g;
    						#$valt2=$val2t+1;
    						all_remove($val,$val2)
    					}
    					$CODE[$val2]=~ s/(.*?)//g;
    				}	
    		    	continue {
    					$val2=$val2+1;
        			}
    				$CODE[$val2]=~ s/(.*?)<\/$val>//g;
    			}
    	}
     
     
    sub emptyTags_removed{
    		my $valE = $_[0];
    		my $count = $_[1];
    		if (($CODE[$count] =~ /<$valE(.*?)>\s+$/) && ($CODE[$count] !~/<$valE(.[^>]*)>(.*?)<\/$valE>/)){
    			$temp=$count;
    			$count=$count+1;
     
    			if ($CODE[$count] =~ /^\s+$/){
    				while(($CODE[$count] !~ /(^\s*)<\/$valE>/) && ($CODE[$count] =~ /(^\s*$)/) ){
    				#print "\n$count:  $CODE[$count]";
    					$CODE[$count]=~ s/$CODE[$count]//g;
    					$count=$count+1;
    				}			
    			}
     
    			if ($CODE[$count] =~ /(^\s*)<\/$valE>/){
     
    		#	print "\n$CODE[$count]";
    				$CODE[$temp]=~ s/<$valE(.*?)>(.*?)//g;
    				$CODE[$count]=~ s/<\/$valE>//g;
    			}else{
    				$count=$temp;
    			}
    		}
    }

  2. #2
    Expert confirmé

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    3 577
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 577
    Points : 5 753
    Points
    5 753
    Par défaut
    Ton script a au moins le problème suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    	while (<INFILE>) 
    	{ 
    		push @CODE, $_;
    		foreach $line (@CODE)
    Dans cette partie de code, ta boucle while parcours chaque ligne de ton fichier, que tu ajoutes dans le tableau @CODE.
    Mais à chaque ligne de ton tableau, ta boucle foreach va parcourir toutes lignes déjà enregistrées dans @CODE pour les traiter.

    Ainsi, ce traitement n'est pas optimum, puisque tu vas traiter d'abord la ligne 1, puis la ligne 1 et la ligne 2, puis la ligne 1, 2 et 3, et ainsi de suite...

    Je ne sais pas si cela règlera ton soucis, mais c'est un premier point à régler avant de passer aux suivants. Et pour nous permettre de débugger ton script, il serait bon de nous donner un exemple de fichier à traiter...

Discussions similaires

  1. Arrêt à la première ligne de code en mode debug
    Par Mister Nono dans le forum NetBeans
    Réponses: 0
    Dernier message: 22/04/2014, 15h55
  2. Réponses: 1
    Dernier message: 25/12/2013, 23h50
  3. effacer la première ligne
    Par ibtisss dans le forum Langage
    Réponses: 2
    Dernier message: 05/01/2006, 11h32
  4. Comment sélectionner la première ligne ?
    Par MartinH dans le forum Langage SQL
    Réponses: 5
    Dernier message: 06/04/2004, 12h56
  5. Calculeur de ligne de code
    Par Bernybon dans le forum Autres éditeurs
    Réponses: 9
    Dernier message: 05/03/2004, 17h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo