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

Re: Help with substitution - - 15 Characters from the left

by THRAK (Monk)
on Aug 13, 2001 at 22:49 UTC ( [id://104533]=note: print w/replies, xml ) Need Help??


in reply to Help with substitution - - 15 Characters from the left

There's probably better/more efficient ways to do this, but this might do what you are asking. I'm not sure because your question isn't real clear. This snippet will tab delimit the data after replacing the comma's and truncating the end spaces in the second (pos 15-25) field. In the future it is in your best interest to provide a clearer explaination and an exact representation of the data you want to parse. People will help you here, but you need to do your part also.
#!/usr/local/bin/perl -w use strict; my @data = ('client-up-to-,Doe,Smith , Inc, jwaters,pfloyd,jjoplin'); foreach my $line (@data) { chomp $line; my $beg_line = substr($line, 0, 14); my $name_field = substr($line, 14, 10); my $end_line = substr($line, 25); print "B: ~$name_field~\n"; $name_field =~ tr/,/ /; $name_field =~ s/\s*$//; print "A: ~$name_field~\n"; $line = "${beg_line}${name_field}${end_line}"; $line =~ tr/,/\t/; print "~$line~\n"; } __END__ B: ~Doe,Smith ~ #note space is still in at this point A: ~Doe Smith~ ~client-up-to- Doe Smith Inc jwaters pfloyd jjoplin~


-THRAK
www.polarlava.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2024-04-25 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found