semio has asked for the wisdom of the Perl Monks concerning the following question:
I'm working with a number of data files that have no defined delimiter. The goal is to take the data, delimit it into appropriate columns, and then insert the data into a db. I could obtain the required results via the following code, but I would like to shoot for something more succinct. Thanks in advance for any insights and suggestions for improvement. cheers!
..which produces the desired output:#!/usr/bin/perl -w use strict; while (<DATA>) { my $line = $_; $line =~ s/\s+/\|/; $line =~ s/\s+/\|/; $line =~ s/\s+/\|/; $line =~ s/\s+/\|/; $line =~ s/\s+/\|/; print $line; } __DATA__ This# is stand alone data "but this data needs to , sta +y together/ and here is some more -but this is a single column
This#|is|stand|alone|data|"but this data needs to , stay together/
and|here|is|some|more|-but this is a single column
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: working with non-delimited files
by FunkyMonk (Bishop) on May 24, 2007 at 21:35 UTC | |
|
Re: working with non-delimited files
by runrig (Abbot) on May 24, 2007 at 22:02 UTC | |
|
Re: working with non-delimited files
by blazar (Canon) on May 24, 2007 at 21:17 UTC | |
by FunkyMonk (Bishop) on May 24, 2007 at 21:28 UTC | |
by blazar (Canon) on May 24, 2007 at 21:50 UTC |