- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- PERL Programming question .
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2005 09:06 AM
02-11-2005 09:06 AM
PERL Programming question .
I am new to PERL . Trying to script something .
@list=`ls -al /dev/vg00'
now my array element is
crw-r----- 1 root sys 64 0x000000 Aug 15 2004 /dev/vg00/group
I do not want to store all the info, what I need is minor number and VG name .
I tried to include awk , like this
@list=`ls -ld /dev/vg00|awk '{print $6,$NF}'`;
But Perl is giving compilation error ,
I there any function to split the array element (similar we achive with awk )
substr function will not work for me , since all array elements do not have same size ...
Please reply ,
Thanks in advance,
BL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2005 09:35 AM
02-11-2005 09:35 AM
Re: PERL Programming question .
Here's a snippet that will do what you are trying to do with your awk:
#!/usr/bin/perl -w
use strict;
my @list = `ls -la /dev/vg00`;
chomp(@list);
my $i = 0;
while ($i <= $#list)
{
my @array = split /\s+/,$list[$i];
if ($#array > 5)
{
printf("%s %s\n",$array[5],$array[$#array]);
}
++$i;
}
This could have been written far more tersely but I intentionally do it step by step for clarity. Note the use of $#array to yield the maximum allowed subscript of @array. \s+ says grab all the white space.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2005 09:37 AM
02-11-2005 09:37 AM
Re: PERL Programming question .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2005 09:38 AM
02-11-2005 09:38 AM
Re: PERL Programming question .
(undef, undef, undef, undef, undef, $minornum, undef, undef, undef, $vgname) = qw(`ls -al /dev/vg00`);
I think you will need the 'qw' to break out each element.
Also, I believe there are perl built-in functions that can do this for you. I don't have my docs in front of me, but take a look at functions related to stat. I have used stat to get time stamps on files;
$time = (stat($file))[8];
so it would be something like;
($minornum, $vgname) = (stat(/dev/vg00/group))[7,9];
or even;
(undef, undef, undef, undef, undef, $minornum, undef, undef, undef, $vgname) = stat(/dev/vg00/group);
The elements of stat are not isn the same order as 'ls -l' so you will need to look at that.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2005 09:50 AM
02-11-2005 09:50 AM
Re: PERL Programming question .
@list=`ls -la /dev/vg00|awk '{print \$6,\$NF}'`;
You just needed to escape the $6 and $NF so that Perl would leave them alone.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2005 06:31 PM
02-13-2005 06:31 PM