Magnolia25 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
Below are the lines in my file. I am reading them into array and storing column values into variables.
ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Suppli +er ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Suppli +er ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Suppli +er ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription at RowCode ValuesInColumn1 DataColumnB ABC RowDescription at RowCode
The following will take data from my file, split it.That works if the columns are divided on spaces. But value for colD is not captured correctly, as string in colD has sapces in between. If value for $colB = XYZ and $colD contains substring = Region , I need to replace the $colB from XYX to N/A.
foreach my $line (@a) { my ($colA, $colB, $colC,$colD) = split( /\s+/, $line); #print "$colD \n"; }
Please help.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Split lines in file to columns
by hippo (Bishop) on Mar 20, 2019 at 09:43 UTC | |
by Magnolia25 (Sexton) on Mar 20, 2019 at 09:50 UTC | |
Re: Split lines in file to columns
by hdb (Monsignor) on Mar 20, 2019 at 10:01 UTC | |
Re: Split lines in file to columns
by tybalt89 (Monsignor) on Mar 20, 2019 at 16:59 UTC | |
Re: Split lines in file to columns
by pgmer6809 (Sexton) on Mar 24, 2019 at 22:09 UTC | |
by haukex (Archbishop) on Mar 24, 2019 at 22:26 UTC |
Back to
Seekers of Perl Wisdom