New to Perl

N

nos

I am looking for a way to look into a file and determine the next
number in a sequence that is not present within a range of numbers.
Example:
File 10000
10001
10003
10004

I want it to find 10002 as the missing number. Any suggestions.

Thanks,
Nos
 
J

John W. Krahn

nos said:
I am looking for a way to look into a file and determine the next
number in a sequence that is not present within a range of numbers.
Example:
File 10000
10001
10003
10004

I want it to find 10002 as the missing number. Any suggestions.


perl -lne'print for $last + 1 .. $_ - 1; $last = $_' yourfile



John
 
M

Mark

nos said:
I am looking for a way to look into a file and determine the next
number in a sequence that is not present within a range of numbers.
Example:
File 10000
10001
10003
10004

I want it to find 10002 as the missing number. Any suggestions.

Thanks,
Nos

Well you could just subtract each number from the next. If the answer is
<> -1 your have a gap.
 
T

Tad McClellan

nos said:
Any suggestions.


I suggest putting the subject of your article in the Subject
of your article.

Your post was *not* about being new to Perl.
 
B

Bob

John W. Krahn said:
perl -lne'print for $last + 1 .. $_ - 1; $last = $_' yourfile
John

c:\tmp> perl -lne'print for $last + 1 .. $_ - 1; $last = $_' data

where data is file with 4 lines..
10001
10003
10004
10005

on w2k sp2 system - I get following error msg
Can't find string terminator "'" anywhere before EOF at -e line 1.
 
S

Sam Holden

c:\tmp> perl -lne'print for $last + 1 .. $_ - 1; $last = $_' data

where data is file with 4 lines..
10001
10003
10004
10005

on w2k sp2 system - I get following error msg
Can't find string terminator "'" anywhere before EOF at -e line 1.

perldoc -q one-liner

Why don't Perl one-liners work on my DOS/Mac/VMS system?
 
J

John W. Krahn

Bob said:
c:\tmp> perl -lne'print for $last + 1 .. $_ - 1; $last = $_' data

where data is file with 4 lines..
10001
10003
10004
10005

on w2k sp2 system - I get following error msg
Can't find string terminator "'" anywhere before EOF at -e line 1.

Sorry, I don't use Windows, but my understanding from reading the Perl
documentation is that you have to use " instead of ' when running on
Windows.

perl -lne"print for $last + 1 .. $_ - 1; $last = $_" data


John
 
B

Bob

Sam Holden said:
perldoc -q one-liner

Why don't Perl one-liners work on my DOS/Mac/VMS system?

that explains why perldoc -q terminator or perldoc -q EOF or a host of
other perldoc inquiries did not provide me with an answer.
thanks
 
B

Bob

John W. Krahn said:
Sorry, I don't use Windows, but my understanding from reading the Perl
documentation is that you have to use " instead of ' when running on
Windows.

perl -lne"print for $last + 1 .. $_ - 1; $last = $_" data


John

thanks. that works.. ( in a way).. starts at 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,120
Messages
2,570,710
Members
47,283
Latest member
hopkins1988

Latest Threads

Top