perl.beginners
[Top] [All Lists]

Re: Array indexing question

Subject: Re: Array indexing question
From: Brad Baxter
Date: Thu, 10 Jul 2008 05:40:30 -0700 PDT
Newsgroups: perl.beginners

On Jul 10, 5:59 am, anirban.adhik...@xxxxxxxxx (Anirban Adhikary)
wrote:
> Dear list
> I want to capture the output of w and then I want to do some job as per the
> o/p of w command in my linux system. So i have written the code as follows
>
> use strict;
> use warnings;
>
> open (LS, "w|") or die "can't open w: $!";

Success for pipes should be checked when you close them.

> my @arr = <LS>;
> close (LS);
> shift @arr;
> shift @arr;
> my($one,$two,$three,$four,$five,$six,$seven,$eight);
>
> foreach my $el(@arr)
>  {
>   ($one,$two,$three,$four,$five,$six,$seven,$eight) = split(/ /,$el);

Change that to split " ".  When you split / / you get fields in
between
each space.

--
Brad


<Prev in Thread] Current Thread [Next in Thread>