Daniel Liston wrote: > > Here is a tool I use to unfold long lines in LDAP outputs. > It also works on mailboxes that have the Received: lines > or Content-*: lines folded.
There are two things in your code that may cause a problem. > #!/usr/bin/perl > > #syntax: unfold.pl filename > newfilename > > if ($ARGV[0]) { > local $/ = ''; > open(FILE, "<$ARGV[0]") or die "can't open $ARGV[0]: $!\n"; > @records = <FILE>; > close(FILE); > } > foreach $record (@records) { > $record =~ s/\n\s//g; > print "$record\n\n"; > } You are removing a newline and a single whitespace character. If your input looks like this: one two three Your substitution will result in: one two three And if your input looks like this: one two three Your substitution will result in: onetwothree However if you change the substitution it will screw up the record separator. You should chomp the records when you read from the file and substitute all whitespace after the newline with a single space. #!/usr/bin/perl #syntax: unfold.pl filename > newfilename @ARGV or die "usage: $0 filename\n"; my @records = do { local ( $/, *FILE ) = ''; open FILE, $ARGV[0] or die "can't open $ARGV[0]: $!"; grep chomp, <FILE>; } foreach my $record ( @records ) { $record =~ s/\n\s+/ /g; print "$record\n\n"; } Or you could pare that down a bit. :-) #!/usr/bin/perl #syntax: unfold.pl filename > newfilename @ARGV or die "usage: $0 filename\n"; $/ = ''; print for grep [ chomp, s/\n\s+/ /g, s/\z/\n\n/ ], <>; > [snip] > > The second paragraph could be modified to fit your needs > rather simply. > > $count = 0; > foreach $record (@records) { > @recordnumber$count = $record; ^^^^^^^^^^^^^^^^^^^ $ perl -le'$record = 234; @recordnumber$count = $record;' Scalar found where operator expected at -e line 1, near "@recordnumber$count" (Missing operator before $count?) syntax error at -e line 1, near "@recordnumber$count " Execution of -e aborted due to compilation errors. > $count++ > } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]