LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-30-2008, 08:17 AM   #1
pooppp
Member
 
Registered: May 2008
Posts: 32

Rep: Reputation: 15
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?
 
Old 09-30-2008, 08:45 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,387

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
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";

Last edited by keefaz; 09-30-2008 at 08:48 AM.
 
Old 09-30-2008, 09:13 AM   #3
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 59
Is this homework? What have you tried so far?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl command line argument noir911 Programming 8 01-15-2008 05:59 AM
awk/perl script for extract data mruknown1 Programming 3 09-11-2007 10:19 AM
awk/perl script for extract data mruknown1 Linux - Newbie 2 09-11-2007 05:42 AM
perl pass regex check as an argument lord-fu Programming 2 08-29-2007 03:55 PM


All times are GMT -5. The time now is 08:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration