perlCrazy has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: text file problem
by jmcnamara (Monsignor) on Oct 13, 2005 at 12:18 UTC

    Here is one way to do it:
    perl -l -0777 -pe 's/\n+(\D)/\1/g' file

    Or if the lines shouldn't be joined across the blank lines then this:

    perl -l -00 -pe 's/\n(\D)/\1/g' file

    --
    John.

Re: text file problem
by Skeeve (Parson) on Oct 13, 2005 at 12:19 UTC
    use strict; use warnings; $_=<DATA>; chomp; print; while (<DATA>) { chomp; s/^\s*$// or /^\D/ or print "\n"; print; } print "\n"; __DATA__ 4374564735|fegfg|sfffsg|QDFWFWwefwe cty|Sd|45|445|35 7345634785|24756|4864586|2356 845245|2347624|264|2376274|2846242 |sfh|Sgfdg|EFgefg|434590|563456 |9345890345|84|3457|345|wdfdhiwdfh 324523|24562|248|2048|2323480|2923472 |3568245|34057|23|43057345734|2472

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: text file problem
by Perl Mouse (Chaplain) on Oct 13, 2005 at 12:57 UTC
    Untested:
    my $buffer = ""; while (<FH>) { next unless /\S/; # Skip blank lines. if (/^\D/) { # A bar is a non-digit as well. chomp $buffer; $buffer .= $_; next; } print $buffer; $buffer = $_; } print $buffer;
    Another way:
    my $nl = ""; while (<FH>) { next unless /\S/; $nl = chomp; print $nl unless /^\d/ || $. == 1; print; } print $nl; # Prints newline if we saw at least one non-blank file.
    Perl --((8:>*
Re: text file problem
by YuckFoo (Abbot) on Oct 13, 2005 at 17:05 UTC
    No.
Re: text file problem
by Anonymous Monk on Oct 13, 2005 at 12:24 UTC
    smells like... homework
      Not to me; the specific problem is too detailed.

      It does however smell strongly of "I'm over my head with this perl stuff and my script doesn't work - fix it for me".

      --
      @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/