Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl sort

Reply
Thread Tools

perl sort

 
 
Jan Burdil
Guest
Posts: n/a
 
      09-22-2006
Hello,
how can I replace * with some command like cat file, ls -l in line

perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'

Thank you
Jan Burdil



 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      09-22-2006
Jan Burdil wrote:
> Hello,
> how can I replace * with some command like cat file, ls -l in line
>
> perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'


You'd use your editor, or your arrow keys, move the cursor to '*',
remove '*', and insert whatever you like.

Maybe explaining what you want to do and what you tried would get you a
better answer.
 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      09-22-2006
Jan Burdil wrote:
> how can I replace * with some command like cat file, ls -l in line
> perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'


perl -e 'print join "\n", sort { -M $b <=> -M $a } `ls -l`,"\n"'

But I find it hard to believe you REALLY want to do that... that's
nutty. There are far better ways to do that (either in Perl or using
plain shell commands).

--
David Filmer (http://DavidFilmer.com)

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      09-22-2006

Quoth "Jan Burdil" <>:
> Subject: perl sort


Please use a sensible Subject. You question has nothing to do with
sorting.

> how can I replace * with some command like cat file, ls -l in line
>
> perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'


You can skip the last "\n" by adding a -l to your commandline.
You can skip the join by putting

$, = "\n";

before the print statement, though that's arguably no simpler in this
case.

Read the section on qx in perldoc perlop.

Alternatively, you can probably do what you want from within Perl,
without calling an external command.

Ben

--
#!/bin/sh
quine="echo 'eval \$quine' >> \$0; echo quined"
eval $quine
# []
 
Reply With Quote
 
Jan Burdil
Guest
Posts: n/a
 
      09-22-2006
when I try
perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'
bb
xx
aa
Mail
mail
yy
unrar
tmp
curl.txt
abc

my files are sorted by date. And I need to sort lines from curl command.
curl ftp://1.1.1.1 give me
-rw-r--r-- 1 honza users 414 Sep 22 12:16 curl.txt
-rwx------ 1 honza users 52 May 31 21:54 bb
drwx------ 2 honza users 512 Aug 22 10:54 mail

And I would like the result to be sorted by date.

I try replace <*> with command curl ftp://1.1.1.1 like this
perl -e 'print join "\n", sort { -M $b <=> -M $a } `curl
ftp://1.1.1.1`,"\n"'
but this doesn't work

Jan Burdil



<> wrote in message
news: ups.com...
> Jan Burdil wrote:
>> how can I replace * with some command like cat file, ls -l in line
>> perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'

>
> perl -e 'print join "\n", sort { -M $b <=> -M $a } `ls -l`,"\n"'
>
> But I find it hard to believe you REALLY want to do that... that's
> nutty. There are far better ways to do that (either in Perl or using
> plain shell commands).
>
> --
> David Filmer (http://DavidFilmer.com)
>



 
Reply With Quote
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      09-22-2006
Jan Burdil wrote:

> my files are sorted by date. And I need to sort lines from curl command.
> curl ftp://1.1.1.1 give me


Somtimes the shell way is the easier way. for example:

ls -l |sort -k 1.37

(see also the -t flag of sort)

--
David Filmer (http://DavidFilmer.com)

 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      09-23-2006
On 2006-09-22 22:21, Tad McClellan <> wrote:
> Jan Burdil <> wrote:
>> And I need to sort lines from curl command.
>> curl ftp://1.1.1.1 give me
>> -rw-r--r-- 1 honza users 414 Sep 22 12:16 curl.txt
>> -rwx------ 1 honza users 52 May 31 21:54 bb
>> drwx------ 2 honza users 512 Aug 22 10:54 mail
>>
>> And I would like the result to be sorted by date.

[...]
>> like this
>> perl -e 'print join "\n", sort { -M $b <=> -M $a } `curl
>> ftp://1.1.1.1`,"\n"'

[...]
>
> You need to arrange for $a and $b to contain filenames,


How would this help? He needs to sort lines which contain a text
representation of a date by this date. -M doesn't do that, so he
shouldn't use -M but extract the date from each line and convert it to a
comparable value (e.g., seconds since the epoch, or yyyy-mm-ddThh:mm).
HTTP:ate may be helpful.

Another way might be to ditch curl in favour of Net::FTP. I haven't
looked at it, but I expect it to contain a function to parse directory
listings from FTP servers.

hp


--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
 
Reply With Quote
 
Jan Burdil
Guest
Posts: n/a
 
      09-23-2006
this command cort the output, but not good

ls -l |sort -k 1.37
drwx------ 2 honza users 512 Aug 22 10:54 mail
-rwx------ 1 honza users 54 Jun 14 11:29 aa
-rwx------ 1 honza users 832 Sep 5 19:35 yy
-rwx------ 1 honza users 52 May 31 21:54 bb

....
Jan Burdil


<> wrote in message
news: oups.com...
> Jan Burdil wrote:
>
>> my files are sorted by date. And I need to sort lines from curl command.
>> curl ftp://1.1.1.1 give me

>
> Somtimes the shell way is the easier way. for example:
>
> ls -l |sort -k 1.37
>
> (see also the -t flag of sort)
>
> --
> David Filmer (http://DavidFilmer.com)
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl sort different from unix sort Jose Luis Perl Misc 3 03-03-2011 09:14 PM
Re: When will Thunderbird support sort in place (in context sort)? Ron Natalie Firefox 0 02-02-2006 04:38 AM
can Perl Sort do this, unix sort breaks on it (muliple spaces as demiliter) colin_lyse Perl Misc 1 02-03-2005 01:13 AM
xsl:sort lang="es" modern vs. tradidional Spanish sort order nobody XML 0 06-01-2004 06:25 AM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57