It will not work.
It will only read the first line.
Wenn the value is set to 1 (instaed of 2) it will read the first line value.
Main Topics
Browse All TopicsHello,
I have the following question.
I have a file called: newsup.db
This is what is in it:
09/13|Welkom|0|1|0
09/15|Test op woensdag|0|2|0
What I now want to do is to read the first en second value out of the line where the fourth value is 2.
The value I use to select the line (the number 2) is called: $lastnumber.
The first value has to be called: $lastdate
The second value has to be called: $lasthead.
How to do this?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
It appears that the end-of-line charater might be something other than \n (new-line) character. If you can find out what it is, you can set the variable $/ to that character and everything will be as expected.
To find out what the end-of-line character in the file is, you will need to look at the file using the 'od' command (if you are on a Unix system) or open the file in a hex editor (if not on a unix system). Or better yet, use the perl script binhex.pl <http://www.perl.com/CPAN/
Once you found the end-of-line character, modify the script:
open FILE, "<newsup.db" or die "error: newsup.db (read); $!\n";
{
local $/ = $end-of-line-char; # whatever you have found from the hexdump
while (<FILE>) {
chomp;
my @values = split /\|/;
if ($values[3] == $lastnumber) {
($lastdate, $lasthead) = @values[0,1];
last;
}
}
}
close FILE;
Business Accounts
Answer for Membership
by: prinxPosted on 1999-09-17 at 08:05:12ID: 2054691
open(filea, "newsup.db");
while(<filea>) {
($valuea, $valueb ,$valuec, $valued, $valuee) = split(/\|/, $_);
if ($valued == "2") {
$lastdate = $valuea;
$lasthead = $valueb;
}
}
close(filea);
???