Matthew Stapleton <[EMAIL PROTECTED]> wrote: > [...] I am wanting to read a line of a file and then > extract a digit from the beginning of the line. A > typical line looks something like this: > > 100. text text text > > So I am using a file handle to open the file and read > the lines on by one with a while loop. > > while (<TXT>){} > > That part is pretty straight forward. Each line is then > given to $_ > > But how do I get just the digit at the beginning of the > line out of $_ ? I thought about adding zero to $_ and > then passing this to another variable but this does not > seem to work. >
Adding zero should work (with a warning) my $number = $_ + 0; But usually you'll use split() or a regex to extract the digits. while (<TXT>) { next unless /^(\d+)/; my $number = $1; ... } Good place to start reading: $ perldoc perlrequick -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]