On Sep 17, 1:28 am, [EMAIL PROTECTED] (Cancer) wrote:
> Hi,
> I am using Perl on Linux server. I m writing a code which will tell
> us the Linux distro with version. For this the command is
>
> cat /etc/issue
>
> which is common for all the distributions of linux. But the output
> varies for different distributions.
>
> For e.g.
>
> SUSE
>
> Welcome to openSUSE 11.0 (X86-64) - Kernel \r (\l).
>
> REDHAT
>
> Red Hat Enterprise Linux Server release 5 (Tikanga)
>
> I am able to save the output in a string. Now I want a code or
> function which will give me only the number from the string.
Untested:
------------------------------------
use warnings;
use strict;
use Scalar::Util ('looks_like_number');
my $string = `cat /etc/issue`;
my $num = get_num($string);
print $num, "\n";
sub get_num {
my @stuff = split /\s/, $_[0];
for(@stuff) {
return $_ if looks_like_number($_);
}
die "Couldn't find a number";
}
------------------------------------
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/