sisyphus wrote:
> On Jun 29, 1:18 am, [EMAIL PROTECTED] (Luca Villa) wrote:
>> I have a long text file like this:
>>
>> 324yellow
>> 34house
>> black
>> 54532
>> 15m21red56
>> 44dfdsf8sfd23
>>
>> How can I obtain (Perl - Windows/commandline/singleline) the
>> following?
>>
>> 1) only the numbers at the beginning before some alpha text, like
>> this:
>>
>> 324
>> 34
>> 15
>> 44
>>
>
> Just for fun - ie ignoring prettiness and requirements 2) and 3):
>
> my @stuff = qw(324yellow 34house black 54532 15m21red56
> 44dfdsf8sfd23);
> for(@stuff) {
> $x = $_ * 1;
> if($x == 0 && substr($_, 0, 1) ne "0") {$x = undef}
> if($x eq $_) {$x = undef}
> print $x, "\n" if defined $x;
> }
for (@stuff) {
no warnings 'numeric';
my $x = $_+0;
undef $x if $x eq $_ or $x == 0 and /^[^0]/;
print "$x\n" if defined $x;
}
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/