Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: how to remove empty pipe delimiters in a line which doesn't contain any data

by rpinnam (Novice)
on Oct 08, 2015 at 15:41 UTC ( [id://1144189]=note: print w/replies, xml ) Need Help??


in reply to Re: how to remove empty pipe delimiters in a line which doesn't contain any data
in thread how to remove empty pipe delimiters in a line which doesn't contain any data

I have tried it before the print statement in @item = @item[s/+/|/g]. it didn't work. Here is my code:
#!/usr/bin/perl @FILES = glob("*.txt"); foreach my $file (@FILES) { open my $fh, '<', $file; (my $fileName = $file) =~ s/\.[^.]+$//; open(my $output, '>', $fileName.".csv") or die "Could not open fil +e '$fileName' $!"; my @address; my @Detail; print $output ""; while (my $line = <$fh>) { chomp $line; @tokens = split /\|/, $line; chomp(@tokens); $objectName=$tokens[0]; if($objectName ne ""){ my @objectFields; $size = scalar(@tokens); @tokens = @tokens[1..$size]; foreach my $token (@tokens){ $token =~ s/\r|\n//g; push @objectFields,$token; } if($objectName eq "IFB"){ @Detail=@objectFields; }elsif($objectName eq "Walmart"){ @address=@objectFields; }elsif($objectName eq "Chicken"){ my @item = (@Detail,@address,@objectFields); @item = @item[s/[|]+/|/g]; print $output join("|", @item)."\n"; } } } close $output; close $fh; }
  • Comment on Re^2: how to remove empty pipe delimiters in a line which doesn't contain any data
  • Download Code

Replies are listed 'Best First'.
Re^3: how to remove empty pipe delimiters in a line which doesn't contain any data
by Corion (Patriarch) on Oct 08, 2015 at 15:45 UTC

    Where in that code did you use the following two lines?

    s/[|]+/|/g; print;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-20 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found