LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need Perl Script to extract last octent of an Argument (https://www.linuxquestions.org/questions/linux-newbie-8/need-perl-script-to-extract-last-octent-of-an-argument-673270/)

pooppp 09-30-2008 07:17 AM

Need Perl Script to extract last octent of an Argument
 
Hi,

I need Perl script to extract last octent of third Argument in command line.

Eg:

./filename.pl linux 2.6.26

Now i need to extract last octent 26 in third argument (ie., 2.6.26).

can anyone help on this?

keefaz 09-30-2008 07:45 AM

This is one way to do it:
Code:

my $number = $ARGV[1];
$number =~ s/.*\.(\d+)$/\1/;
print "number: $number\n";

Another way:
Code:

my ($first, $second, $third) = split /\./,  $ARGV[1];
print "number: $third\n";


Telemachos 09-30-2008 08:13 AM

Is this homework? What have you tried so far?


All times are GMT -5. The time now is 07:35 PM.