tiggyboo has asked for the wisdom of the Perl Monks concerning the following question:
I'm parsing a pipe delimited file and working my way through each element with foreach after splitting each line. What I'm finding is that uninterrupted empty fields to the end of the line are being somehow skipped for processing, i.e.:
# input example: 1|2|3|||6|7|||| @fields = split('\|', $_); foreach (@fields) { &process($_); } sub process { print $_ . "\n"; }
In this case the empty elements after "7" will not be printed. However, if I were to fill the last empty element with a value, all the empty elements in between will be printed. Any thoughts? Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: foreach skipping elements
by Tux (Canon) on Jul 19, 2013 at 15:30 UTC | |
|
Re: foreach skipping elements
by Corion (Patriarch) on Jul 19, 2013 at 15:30 UTC | |
|
Re: foreach skipping elements
by mtmcc (Hermit) on Jul 19, 2013 at 16:07 UTC | |
by kcott (Archbishop) on Jul 20, 2013 at 04:53 UTC | |
by mtmcc (Hermit) on Jul 20, 2013 at 05:25 UTC | |
by rjt (Curate) on Jul 20, 2013 at 03:49 UTC | |
by mtmcc (Hermit) on Jul 20, 2013 at 05:22 UTC | |
by tiggyboo (Initiate) on Jul 19, 2013 at 18:10 UTC |