<html> <body> <div align="center"> <center> <pre><b><u><font size="4">SOLUZIONE ESERCIZIO IN PERL</font></u></b></pre> </center> </div> <pre>#!/usr/local/bin/perl use strict; my ($fname, $laststr, $done, $cur1, $cur2, $line1, $line2); if (@ARGV < 1) { die("Usage: ",$0," file_name\n"); } $fname=shift @ARGV; open(FILEIN,$fname) || die("open $fname: $!\n"); $laststr=<FILEIN>; $done=0; while ($line2 = <FILEIN>) { if ($line2 lt $laststr) { $cur2=tell FILEIN; last; } $laststr=$line2; } if (!defined($line2)) { $done=1; } seek FILEIN,0,0; while ($line1=<FILEIN>) { if (($line1 lt $line2) || $done) { print $line1; } else { $cur1=tell FILEIN; while ($line1 gt $line2) { print $line2; seek FILEIN, $cur2, 0; if (eof(FILEIN)) { $done=1; last; } else { $line2=<FILEIN>; $cur2=tell FILEIN; } } print $line1; seek FILEIN, $cur1, 0; } last if ($line1 eq $laststr); } if (!$done) { print $line2; seek FILEIN, $cur2, 0; while (<FILEIN>) { print $_; } }</pre> </body> </html> -- Users.AntonioValletta - 15 Nov 2001 <br>
This topic: Sistemioperativi1
>
SoluzionePerl19Gennaio2000
Topic revision: r1 - 2001-11-15 - AntonioValletta
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback