On Thursday, June 6, 2002, at 01:56 , lz wrote: > > You were right - I got multiple lines in the file and > I guess while the variable was set when it found the > correct pattern, but was unset after it couldn't find > the pattern. > > Since, I don't need anything after I got my field, I > just used 'last' to exit out from the loop and it > seemed to work fine! [..] >> % while ( $line = <STDIN> ) >> % { >> % $idNumber = $line =~ /\((ID\d+)\)/; >> % } >> % >> % print $idNumber; // empty [..] >> Oh! I get it! There's more than one line in the >> file, right? attention to detail...... [..] >> You *probably* want something like >> >> $idNumber = ... >> last i $idNumber >> >> to jump out of the loop once it has been >> successfully set. [..]
uh dudes - since we are looking for the first non-blank line, why not look for the first non blank line? my ($line, $idNumber) = (undef, undef); while(<FH>) { next if(/^\s*$/); last; } chomp($line=$_); ($idNumber) = $line =~ /\((ID\d+)\)/; cf: http://www.wetware.com/drieux/pbl/perlTrick/firstNonBlankLineOfFile.txt ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]