texuser74 has asked for the wisdom of the Perl Monks concerning the following question:
input: test.txt
My present code does it, but i want to do it with fewer lines of code<item>sample item text one <item>sample item text two <item>sample item text three <item>sample item text four
The required output is:open(IN, "test.txt") || die "\nCan't open test.txt \n"; open(OUT, ">test.out"); $/=""; { local $/ = '<item>'; print OUT scalar <IN>; for (<IN>) { s@([\d\D]*?<item>)@ my $var = $1; $var =~ s!\s+! !g; $var @e; print OUT; } } close(IN); close(OUT);
<item>sample item text one <item>sample item text two <item>sample item text three <item>sample item text four
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: formatting text
by ikegami (Patriarch) on Jun 20, 2008 at 03:00 UTC | |
|
Re: formatting text
by Narveson (Chaplain) on Jun 20, 2008 at 03:22 UTC | |
|
Re: formatting text
by waldner (Beadle) on Jun 20, 2008 at 07:40 UTC | |
|
Re: formatting text
by jwkrahn (Abbot) on Jun 20, 2008 at 03:51 UTC | |
by Narveson (Chaplain) on Jun 20, 2008 at 04:00 UTC |