Home > Archive > PERL Beginners > November 2006 > line position
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Tim Wolak 2006-11-03, 6:57 pm |
| All,
I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file. As I have never done
this before, can someone point me in the right direction as to get
started?
Thanks for the help!
Tim
| |
| Wagner, David --- Senior Programmer Analyst --- WG 2006-11-03, 6:57 pm |
| If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position
All,
I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file. As I have never done
this before, can someone point me in the right direction as to get
started?
Thanks for the help!
Tim
****************************************
******************************
This message contains information that is confidential and proprietary to F=
edEx Freight or its affiliates. It is intended only for the recipient name=
d and for the express purpose(s) described therein. Any other use is proh=
ibited.
****************************************
******************************
| |
| Tom Smith 2006-11-03, 6:57 pm |
| Tim Wolak wrote:
> All,
>
> I need to parse lines from a file and at a certain position test to see
> if it is what a want, if so I need to grab information from other
> positions in the line and drop it into a file. As I have never done
> this before, can someone point me in the right direction as to get
> started?
>
> Thanks for the help!
> Tim
>
I think part of what you're looking for is s (). This will allow you
to move the cursor to a specific position within a file in relation to
the cursor's current position.
I'm still quite new to Perl, so I'll leave the more complicated answers
to those with more experience in this area. :-D
~ Tom
| |
| Tim Wolak 2006-11-03, 6:57 pm |
| Here is an example of the lines I am reading in below. This is one
continuous line. I need information from positions 70-71, if they match
what I want then print that and position 92(also sub-positions C,P,D).
Being that I have never had to do this before I'm not sure what to use
to step me through this file to get the information that I need.
Tim
CME008885071BIOH72006102816122900MO00000
02006091415300020070316083000BQB
IOH7 FE 00000000000000005000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
000011 000000000000000000 000000000000000000USD0000100000000
0001000000000500USD 000000000000000000 00100100
2006102710000000000000082580000000000000
00860800000000000000079080
BQF60000
000000010000000037501605F 000000000000000000 000000000000000000 F
0000000000000002400 1BQ 101100
00 000000000050200703BIO
0000000000000000010200000000000000050020
00000000000000001E00000000000000
00000000000
-----Original Message-----
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:David.Wagner@freight.fedex.com]=20
Sent: Friday, November 03, 2006 12:16 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position
If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position
All,
I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file. As I have never done
this before, can someone point me in the right direction as to get
started?
Thanks for the help!
Tim
****************************************
******************************
This message contains information that is confidential and proprietary
to FedEx Freight or its affiliates. It is intended only for the
recipient named and for the express purpose(s) described therein. Any
other use is prohibited.
****************************************
******************************
| |
| David --- Senior Programmer Analyst --- WGO Wagner 2006-11-03, 6:57 pm |
| So what makes up a line? CME through the next CME? You can
concatenate all the data together if desired( do a chomp first) and
check if CME or What denotes the next rcd? Then you could either do a
equal(ie,=20
if ( next rcd ) {
if ( substr($MyData,70,2) eq q[xx] ) {
# now pull what I need, place in another file or
print
}
$MyData =3D q[]; # clear the buffer and get ready for next
data
}
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 10:30
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position
Here is an example of the lines I am reading in below. This is one
continuous line. I need information from positions 70-71, if they match
what I want then print that and position 92(also sub-positions C,P,D).
Being that I have never had to do this before I'm not sure what to use
to step me through this file to get the information that I need.
Tim
CME008885071BIOH72006102816122900MO00000
02006091415300020070316083000BQB
IOH7 FE 00000000000000005000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
000011 000000000000000000 000000000000000000USD0000100000000
0001000000000500USD 000000000000000000 00100100
2006102710000000000000082580000000000000
00860800000000000000079080
BQF60000
000000010000000037501605F 000000000000000000 000000000000000000 F
0000000000000002400 1BQ 101100
00 000000000050200703BIO
0000000000000000010200000000000000050020
00000000000000001E00000000000000
00000000000
-----Original Message-----
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:David.Wagner@freight.fedex.com]=20
Sent: Friday, November 03, 2006 12:16 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position
If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position
All,
I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file. As I have never done
this before, can someone point me in the right direction as to get
started?
Thanks for the help!
Tim
****************************************
******************************
This message contains information that is confidential and proprietary
to FedEx Freight or its affiliates. It is intended only for the
recipient named and for the express purpose(s) described therein. Any
other use is prohibited.
****************************************
******************************
| |
| Tim Wolak 2006-11-03, 6:57 pm |
| The whole thing below is the line, its just word wrapped in scrt. I
can't concatenate it because everything is in a specific position for
what I need. Is the s module what I need to be using? I just need
to collect the two characters in position 70 and 71, test if they are
GE,E$,E0,etc.. If they are then I need the data from position 92 and
write the line to a file that consists of positions 70-71 and position
92, then go on to the next line.
Tim
-----Original Message-----
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:David.Wagner@freight.fedex.com]=20
Sent: Friday, November 03, 2006 12:49 PM
To: Tim Wolak; beginners@perl.org
Cc: Wagner, David --- Senior Programmer Analyst --- WGO
Subject: RE: line position
So what makes up a line? CME through the next CME? You can
concatenate all the data together if desired( do a chomp first) and
check if CME or What denotes the next rcd? Then you could either do a
equal(ie,=20
if ( next rcd ) {
if ( substr($MyData,70,2) eq q[xx] ) {
# now pull what I need, place in another file or
print
}
$MyData =3D q[]; # clear the buffer and get ready for next
data
}
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 10:30
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position
Here is an example of the lines I am reading in below. This is one
continuous line. I need information from positions 70-71, if they match
what I want then print that and position 92(also sub-positions C,P,D).
Being that I have never had to do this before I'm not sure what to use
to step me through this file to get the information that I need.
Tim
CME008885071BIOH72006102816122900MO00000
02006091415300020070316083000BQB
IOH7 FE 00000000000000005000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
000011 000000000000000000 000000000000000000USD0000100000000
0001000000000500USD 000000000000000000 00100100
2006102710000000000000082580000000000000
00860800000000000000079080
BQF60000
000000010000000037501605F 000000000000000000 000000000000000000 F
0000000000000002400 1BQ 101100
00 000000000050200703BIO
0000000000000000010200000000000000050020
00000000000000001E00000000000000
00000000000
-----Original Message-----
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:David.Wagner@freight.fedex.com]=20
Sent: Friday, November 03, 2006 12:16 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position
If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position
All,
I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file. As I have never done
this before, can someone point me in the right direction as to get
started?
Thanks for the help!
Tim
****************************************
******************************
This message contains information that is confidential and proprietary
to FedEx Freight or its affiliates. It is intended only for the
recipient named and for the express purpose(s) described therein. Any
other use is prohibited.
****************************************
******************************
| |
| D. Bolliger 2006-11-03, 6:57 pm |
| Tim Wolak am Freitag, 3. November 2006 18:37:
> All,
>
> I need to parse lines from a file and at a certain position test to see
> if it is what a want, if so I need to grab information from other
> positions in the line and drop it into a file. As I have never done
> this before, can someone point me in the right direction as to get
> started?
>
> Thanks for the help!
> Tim
Hello Tim
I've read your second post with some sample data.
Here's one way to do it, certainly not the most efficient, but it's short and
you can adapt it to your needs. I use shorter sample data and other
positions, but you get the idea.
I use, for shortness, the DATA filehandle. You may want to adapt it to use
STDIN for input and print to STDOUT, so you can invoke the script with
$ script.pl < infile > outfile
What it does: It skips 4 positions, tries to match 'hi' or 'ho' at the next 2,
then skips 3, retrieves the next 2, skips again 8, and retrieves the next 6.
The retrieve is done via capturing paranthesis, see perldoc perlre.
Hope this helps,
Dani
#!/usr/bin/perl
use strict;
use warnings;
while (<DATA> ) {
if (my (@out_fields)= $_ =~ /^ .{4} (hi|ho) .{3} (.{2}) .{8} (.{6}) /x) {
print @out_fields, "\n";
}
}
__DATA__
4444hi3332288888888first*----
4444ho3332288888888second----
4444no3332288888888third*----
| |
| David --- Senior Programmer Analyst --- WGO Wagner 2006-11-03, 6:57 pm |
| If it is only one line and it is record separator is carriage
return as defined by your system, then a simple loop like:
while: ( <MYFILEIN> ) {=20
chomp;
if ( substr($_,70,2) =3D~ /(xx|xy|xz)/I ) {
# substr starts at zero vs 1
print MYFILEOUT substr($),70,2) .
Substr($_,91,1) . "\n";
}
}
simple format and should be straight forward.
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 11:05
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position
The whole thing below is the line, its just word wrapped in scrt. I
can't concatenate it because everything is in a specific position for
what I need. Is the s module what I need to be using? I just need
to collect the two characters in position 70 and 71, test if they are
GE,E$,E0,etc.. If they are then I need the data from position 92 and
write the line to a file that consists of positions 70-71 and position
92, then go on to the next line.
Tim
-----Original Message-----
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:David.Wagner@freight.fedex.com]=20
Sent: Friday, November 03, 2006 12:49 PM
To: Tim Wolak; beginners@perl.org
Cc: Wagner, David --- Senior Programmer Analyst --- WGO
Subject: RE: line position
So what makes up a line? CME through the next CME? You can
concatenate all the data together if desired( do a chomp first) and
check if CME or What denotes the next rcd? Then you could either do a
equal(ie,=20
if ( next rcd ) {
if ( substr($MyData,70,2) eq q[xx] ) {
# now pull what I need, place in another file or
print
}
$MyData =3D q[]; # clear the buffer and get ready for next
data
}
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 10:30
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position
Here is an example of the lines I am reading in below. This is one
continuous line. I need information from positions 70-71, if they match
what I want then print that and position 92(also sub-positions C,P,D).
Being that I have never had to do this before I'm not sure what to use
to step me through this file to get the information that I need.
Tim
CME008885071BIOH72006102816122900MO00000
02006091415300020070316083000BQB
IOH7 FE 00000000000000005000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
000011 000000000000000000 000000000000000000USD0000100000000
0001000000000500USD 000000000000000000 00100100
2006102710000000000000082580000000000000
00860800000000000000079080
BQF60000
000000010000000037501605F 000000000000000000 000000000000000000 F
0000000000000002400 1BQ 101100
00 000000000050200703BIO
0000000000000000010200000000000000050020
00000000000000001E00000000000000
00000000000
-----Original Message-----
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:David.Wagner@freight.fedex.com]=20
Sent: Friday, November 03, 2006 12:16 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position
If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position
All,
I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file. As I have never done
this before, can someone point me in the right direction as to get
started?
Thanks for the help!
Tim
****************************************
******************************
This message contains information that is confidential and proprietary
to FedEx Freight or its affiliates. It is intended only for the
recipient named and for the express purpose(s) described therein. Any
other use is prohibited.
****************************************
******************************
| |
| Tim Wolak 2006-11-03, 6:57 pm |
| Thanks David, that is exactly what I did just before receiving your
email! Thanks for the help!
Tim
-----Original Message-----
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:David.Wagner@freight.fedex.com]=20
Sent: Friday, November 03, 2006 3:17 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position
If it is only one line and it is record separator is carriage
return as defined by your system, then a simple loop like:
while: ( <MYFILEIN> ) {=20
chomp;
if ( substr($_,70,2) =3D~ /(xx|xy|xz)/I ) {
# substr starts at zero vs 1
print MYFILEOUT substr($),70,2) .
Substr($_,91,1) . "\n";
}
}
simple format and should be straight forward.
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 11:05
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position
The whole thing below is the line, its just word wrapped in scrt. I
can't concatenate it because everything is in a specific position for
what I need. Is the s module what I need to be using? I just need
to collect the two characters in position 70 and 71, test if they are
GE,E$,E0,etc.. If they are then I need the data from position 92 and
write the line to a file that consists of positions 70-71 and position
92, then go on to the next line.
Tim
-----Original Message-----
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:David.Wagner@freight.fedex.com]=20
Sent: Friday, November 03, 2006 12:49 PM
To: Tim Wolak; beginners@perl.org
Cc: Wagner, David --- Senior Programmer Analyst --- WGO
Subject: RE: line position
So what makes up a line? CME through the next CME? You can
concatenate all the data together if desired( do a chomp first) and
check if CME or What denotes the next rcd? Then you could either do a
equal(ie,=20
if ( next rcd ) {
if ( substr($MyData,70,2) eq q[xx] ) {
# now pull what I need, place in another file or
print
}
$MyData =3D q[]; # clear the buffer and get ready for next
data
}
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 10:30
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position
Here is an example of the lines I am reading in below. This is one
continuous line. I need information from positions 70-71, if they match
what I want then print that and position 92(also sub-positions C,P,D).
Being that I have never had to do this before I'm not sure what to use
to step me through this file to get the information that I need.
Tim
CME008885071BIOH72006102816122900MO00000
02006091415300020070316083000BQB
IOH7 FE 00000000000000005000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
0000000000000000000000000000000000000000
00000000000000000000
0000000000000000000000000000000000000000
00000000000000000000000000000000
000011 000000000000000000 000000000000000000USD0000100000000
0001000000000500USD 000000000000000000 00100100
2006102710000000000000082580000000000000
00860800000000000000079080
BQF60000
000000010000000037501605F 000000000000000000 000000000000000000 F
0000000000000002400 1BQ 101100
00 000000000050200703BIO
0000000000000000010200000000000000050020
00000000000000001E00000000000000
00000000000
-----Original Message-----
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:David.Wagner@freight.fedex.com]=20
Sent: Friday, November 03, 2006 12:16 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position
If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: Tim Wolak [mailto:twolak@sktydev.com]=20
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position
All,
I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file. As I have never done
this before, can someone point me in the right direction as to get
started?
Thanks for the help!
Tim
****************************************
******************************
This message contains information that is confidential and proprietary
to FedEx Freight or its affiliates. It is intended only for the
recipient named and for the express purpose(s) described therein. Any
other use is prohibited.
****************************************
******************************
| |
| D. Bolliger 2006-11-03, 6:57 pm |
| Wagner, David --- Senior Programmer Analyst --- WGO am Freitag, 3. November
2006 22:16:
> If it is only one line and it is record separator is carriage
> return as defined by your system, then a simple loop like:
Hello David and Tim,
The below code is a good example why one should happily place:
use strict;
use warnings;
at the beginning.
> while: ( <MYFILEIN> ) {
You meant:
while ( <MYFILEIN> ) {
> chomp;
Just omit the chomp and the code behaves the same.
> if ( substr($_,70,2) =~ /(xx|xy|xz)/I ) {
The modifier should be /i, not /I. With /I, the code doesn't even compile.
If you want to use a regex, then it might be better to:
- anchor the pattern (not completely shure though if
that makes a difference *here*)
- stop the matching process immediately after the first char does
not match
- use non-capturing parenthesis (?:) to decrease the work
of the regex engine, since the matched string is not used
- Then, since the same substring is used below, it might (not shure)
be appropriate to store the extracted string into a variable
That would leed to [untested]:
if ( (my $s=substr($_,70,2)) =~ /^x(?:x|y|z)/i ) {
> print MYFILEOUT substr($),70,2) .
You meant '$_', not '$'.
print MYFILEOUT $s . # see above alternative
> Substr($_,91,1) . "\n";
You meant:
substr ($_,91,1) . "\n";
> }
> }
>
> simple format and should be straight forward.
Dani
[snipped top-posting history]
| |
| Wagner, David --- Senior Programmer Analyst --- WG 2006-11-03, 6:57 pm |
| Sorry, but I was just giving quick code and had NOT run. Using
of strict and warnings is the only way to go. I was writing and doing
other things. I apologize for not catching, but was supplying the open
for th input or output, etc. just a inkling on what he could do to get
started.=20
If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us=20
-----Original Message-----
From: D. Bolliger [mailto:info@dbolliger.ch]=20
Sent: Friday, November 03, 2006 14:19
To: beginners@perl.org
Subject: Re: line position
Wagner, David --- Senior Programmer Analyst --- WGO am Freitag, 3.
November=20
2006 22:16:
> If it is only one line and it is record separator is carriage
> return as defined by your system, then a simple loop like:
Hello David and Tim,
The below code is a good example why one should happily place:
use strict;=20
use warnings;=20
at the beginning.
> while: ( <MYFILEIN> ) {
You meant:=20
while ( <MYFILEIN> ) {
> chomp;
Just omit the chomp and the code behaves the same.
> if ( substr($_,70,2) =3D~ /(xx|xy|xz)/I ) {
The modifier should be /i, not /I. With /I, the code doesn't even
compile.
If you want to use a regex, then it might be better to:
- anchor the pattern (not completely shure though if=20
that makes a difference *here*)
- stop the matching process immediately after the first char does=20
not match
- use non-capturing parenthesis (?:) to decrease the work=20
of the regex engine, since the matched string is not used
- Then, since the same substring is used below, it might (not shure)=20
be appropriate to store the extracted string into a variable=20
That would leed to [untested]:
if ( (my $s=3Dsubstr($_,70,2)) =3D~ /^x(?:x|y|z)/i ) {
> print MYFILEOUT substr($),70,2) .
You meant '$_', not '$'.
print MYFILEOUT $s . # see above alternative
> Substr($_,91,1) . "\n";
You meant:
substr ($_,91,1) . "\n";
> }
> }
>
> simple format and should be straight forward.
Dani
[snipped top-posting history]
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
****************************************
******************************
This message contains information that is confidential and proprietary to F=
edEx Freight or its affiliates. It is intended only for the recipient name=
d and for the express purpose(s) described therein. Any other use is proh=
ibited.
****************************************
******************************
|
|
|
|
|