Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Regular Expression help, MS Access Pipe delimited export gone bad

by hawson (Monk)
on Nov 06, 2001 at 07:21 UTC ( [id://123493]=note: print w/replies, xml ) Need Help??


in reply to Regular Expression help, MS Access Pipe delimited export gone bad

How about this:
#!/usr/bin/perl -w use strict; my ($line, $spacer); while(defined($_=<>)) { s/\n//g; if ($_ =~ /^[0-9]{3,5}/) { print "$line\n" if defined($line); $line=$_; } else { $spacer = (/^\|/ || $line =~ /\|$/) ? "" : " "; $line.="$spacer$_"; } } print "$line\n"; #get last one...
If a line starts or ends with a pipe ("|"), then it assumes you do not want extra whitespace around it. Otherwise, it should honor any leading and trailing whitespace on each line (so if one line ends with a tab, and the next starts with one, the code will spit out two tabs in a row).
  • Comment on Re: Regular Expression help, MS Access Pipe delimited export gone bad
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found