in reply to There has to be an easier way...
Also, assuming that the fields in between the | characters do not themselves have |'s in them, you could keep it as a regex by writing:
Note that this is better than just just sayingif (m#([^\|]+)\|([^\|]+)$#) { $a=$1; $b=$1; } else { chomp; die "Bad line: $_\n"; }
because a line that does not fit your idea of what should be there (in other words, if the regex fails) will put nothing into the variables on the left.($a,$b,$c) = m/(your)(regex)(here)/;
I'd use the split myself, but this shows another way to do it, and it checks the data a little, too. Although it does *not* grab the 14th and 15th column, but merely the last two. This could be a bug or a feature: your data, your call. :)
|
|---|