Title: RE: [PMX:#] RE: [Perl-unix-users] a way to put contents of variable at comman d prompt and pip it to some other command

Thanx Brian and all for helping me out

Regards
Manish


-----Original Message-----
From: Brian Noble [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 10, 2002 10:58 AM
To: Manish Tiwari
Subject: Re: [PMX:#] RE: [Perl-unix-users] a way to put contents of
variable at comman d prompt and pip it to some other command


What about:

if (@data = "`ls" -ltr`){
        @grepped=(!/total/,@data);
        @sorted=sort(@grepped);
}

This will give you what you are asking for, but you will also get a fair bit of
blank lines (which are easy to remove) and the sort will work from right to left
on your long-listing of files, so it may not work the way you want.

brian

On Wed Oct 09, 2002 at 04:28:06PM -0700, Manish Tiwari wrote:
> Thanx Brian and Bill
>
> one approach
>
> Actually this code is in a subroutine that returns a list of files in a
> path name supplied as an argument to this subroutine
>
> i have to do to get list of files
>
> @data = "`ls" -ltr | grep -v total | sort +8` ;
>
> now $? returns exist status of "sort" not "ls"
>
> Main objective : how to make sure that "ls" command works fine ?
> so one approach is divide it into two parts
>
> @data = "`ls" -ltr ` ;
> if ( $? != 0 ) {
>       print "ls command failed " ;
>       exit 1 ;
> }
>
> now
>
> i want like
>
> @data = "`echo" @data | grep -v total | sort +8 ` ;
> this wont work  ..as data is not environment variable
>
> i can however do
>
> ls -ltr
> write output to some temporary file
>
> then do
>
> @data = "`cat" < file name > | grep -v total | sort +8 ' ;
>
>
> but then i have to create a temp file
> and write to it
> and delete it
>
> thanx
> Manish
>
>
> -----Original Message-----
> From: Brian Noble [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, October 09, 2002 2:40 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [Perl-unix-users] a way to put contents of variable at
> command prompt and pip it to some other command
>
>
> On Wed Oct 09, 2002 at 02:23:22PM -0700, Manish Tiwari wrote:
> > Hi
> >
> > i was trying to do something like
> >
> > @data = "`ls" -ltr ` ;
>
> how about,
>
> if defined(@data = "`ls" -ltr`){
>    block of code
> }
>
> >
> > < do some operation check whether ls command actually worked>
> >
> > now i want to pass the contents of "data" thru unix commands like egrep
> and
> > sort
> >
> >
> > so in all operation will be like
> >
> > ls -ltr | grep -v total | sort +8
> >
> > but making sure that ls command actually worked
> >
> >
> > any help
> >
> >
> > Thanx
> > Manish
>
> --
> Brian Noble
> Tech Support Engineer
> [EMAIL PROTECTED]
> _______________________________________________
> Perl-Unix-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

--
Brian Noble
Tech Support Engineer
[EMAIL PROTECTED]

Reply via email to