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]\|$/)
&& ($record =~ /^.{26}\|/)
&& ($record =~ /^.{37}\|/));
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 "\|")
&& ($record =~ /\|[0A-Z]\|$/)){
return 1;
}
elsif ($record =~ /^.{30}\|[BNPG]\|/){
return 2;
}
else {
return 3;
}
}
but, for whatever reason, the (substr($record, 27) eq "|")
doesn't match at all (when line 1 is passed through) and
I end up with a return value of 3.
The current (as of 1/26/2005 at 11:49 am) whole program
can be found at:
http://www.nothingimportant.net/perl-stuff/alcatel_readserial
Thanks again,
--J(K)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>