Charles K. Clarkson <mailto:[EMAIL PROTECTED]> wrote:
Repost your script to the previous web link and I'll take another look on Thursday.
I will do that. In the meantime, I've implimented many of the suggestions everyone has given me, but I'm a bit stumped on this:
I have the function:
sub which_line { my $record = shift; # pipe symbols appear on line 1 at character positions 27 and 38, and do # not appear at those positions on line 2 return 1 if $record =~ ((/\|[0A-Z]\|$/)
^ You have a left parenthesis in the wrong place.
&& ($record =~ /^.{26}\|/) && ($record =~ /^.{37}\|/));
That statement is evaluated as:
return 1 if $record =~ (($_ =~ /\|[0A-Z]\|$/) && ($record =~ /^.{26}\|/) && ($record =~ /^.{37}\|/));
You should just remove all the parentheses:
return 1 if $record =~ /\|[0A-Z]\|$/ && $record =~ /^.{26}\|/ && $record =~ /^.{37}\|/;
Or you could combine all the patterns into one regular expression:
return 1 if $record =~ /^.{26}\|.{10}\|.*\|[0A-Z]\|$/;
return 2 if $record =~ /^.{30}\|[BNPG]\|/; return 3; }
But it isn't working. It appears to always find line 1 and never line two. I had these two reversed (looked for line 2 first) because the line 1 match I had before will match both line 1 and line 2, which is why I've added the /^.{26}\|/ and /^.{37}\|, as those characters do not exist on line 2 at those positions, but they're matching anyway with what I've got above. My guess is that the regex is finding any "|" in any position after the ^.{X}, but I don't know how to fix that.
Any clues as to what I've done wrong?
The input being sent to the program is of the form:
|6643 |Jason Balicki | |0501211243|000:00:00| 0| S |0| | |13145551212 |N| | 0|001001|001001| 100| 10|B|A|
And the pipes will (should) always be at the locations shown in the example.
I have also tried:
sub which_line {
my $record = shift;
# pipes (|) appear on line 1 at character positions 27 and 38, and do
# not appear at those positions on line 2
# also tried 'eq "|"' and $position=26 and 28. Just in case I was
# off on my count
my $position=27
if ((substr($record, $position) eq "\|")
Without the third argument, substr() returns the string from $position to the end of the string in $record which in your case will never be equal to a single character. (Also, the vertical bar is only special in a regular expression so you don't have to put a backslash in front of it in a string.)
&& ($record =~ /\|[0A-Z]\|$/)){ return 1; } elsif ($record =~ /^.{30}\|[BNPG]\|/){ return 2; } else { return 3; } }
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>