Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Placing text onto multiple lines

by Limbic~Region (Chancellor)
on May 11, 2003 at 22:33 UTC ( [id://257294]=note: print w/replies, xml ) Need Help??

in reply to Placing text onto multiple lines

Anonymous Monk,
This seems like what you want, but if not - say so and I will try something else:

#!/usr/bin/perl -w use strict; open (INPUT,"jobs.txt") or die "Unable to open input : $!"; open (OUTPUT,"jobs.txt") or die "Unable to open output : $!"; select OUTPUT; $\ = "\n"; while (<INPUT>) { chomp; my @fields = split /\t/; unless (@fields > 2) { print join "\t" , @fields; } else { my $firstfield = shift @fields; while (my $nextfield = shift @fields) { print $firstfield, "\t", $nextfield; } } } close INPUT; close OUTPUT;

Cheers - L~R

Update: Both vladb++ and pzbagel++ have simpler solutions than this. The only thing I would point out is you said tab delimited.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://257294]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-06-13 10:25 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.