in reply to Access elements of $_

This doesn't find the second row in the file.

Which file: the one accessed by the file handle  MYFILE or by the  DMPLD handle?

Maybe try writing a program which opens a file, reads and prints each line in a  while loop, and then closes the file. This might be a good foundation for your ultimate goal.

As moritz suggested, you might then want to try splitting each line as you go through the  while loop to access its fields.

[H]ow do I reference the first element of $_ ...

$_ is a scalar; it has no elements. It may be a scalar that is a reference to an array, in which case  $_->[0], $_->[1], ... would access the first, second, etc., elements of the array.

Replies are listed 'Best First'.
Re^2: Access elements of $_
by Anonymous Monk on Aug 12, 2010 at 12:55 UTC
    Actually, I just did this to fix it following an earlier suggestion
    $id = 1 open(MYFILE,"/var/tmp/mylist.dat") or die "Cant open mylist.dat" while (<MYFILE>) { chomp; split/,/; die "Request Id $id already present in file\n" if $_[0] eq $id; } close MYFILE;