Please bottom post.... > This should give you what you need: > > my $digit = 0; > foreach (@commands) { > /^\d+/; > print FILE "DIGIT = $&\n"; > } >
While simple, use of $& takes a performance penalty and a readability penalty.... >From perldoc perlvar: "The use of this variable anywhere in a program imposes a considerable performance penalty on all regular expression matches. See the BUGS manpage." http://danconia.org > Hemond, Steve wrote: > > Hi ppl, > > > > I have to split a file in pieces and I place every segment in an array. > > Each segment begins with digit(s). What I want to do is to parse the > > array, and for each segement, record its first digits into a scalar so I > > can do further manipulations on it (actually I only print the scalar > > into a file). > > > > What I do right now is : > > > > my $digit = 0; > > for (@commands) > > { > > $digit =~ /^\d+/; > > print FILE "DIGIT = $digit \n"; > > } > > > > The resulting file displays : > > 0 > > 0 > > 0 > > 0 > > 0 > > 0 > > ... etc. > > > > Here are some sample segments : > > 1NP256ES-0 <-- here it should take 1 > > 61PC61 <-- here it should take 61 > > 1LT <-- here it should take 1 > > 16PC16 <-- here it should take 16 > > > > I am missing something for sure ... but what? Any clues? > > > > Thank you so much in advance, > > > > Best regards, > > > > Steve Hemond -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>