Sergio Escalada wrote:
Hi all! I would like to know if it's possible to make an array sorting with
a subroutine call.
Usually, a sort is made as, for example:
sort {$a = $b} @array;
But my intention is something like:
sort subroutine_call @array;
sub subroutine
{
$a = $b;
}
How could
Thanks for replies.
The purpouse of this mini-script is to list the rows from a database loaded
in memory ($ref_db is the reference to hashtable that cotains the DB). So I
want to order the fields by different sort rules, and make the proccess as
abstract as it's possible with a subrutine (sub
On 12/2/06, Sergio Escalada [EMAIL PROTECTED] wrote:
The purpouse of this mini-script is to list the rows from a database loaded
in memory ($ref_db is the reference to hashtable
Another idea -
sub sortrows {
my $sorted = @_;
$sorted = -(($a-{ahash} eq 'x') = ($b-{ahash} eq 'x')) if
The purpouse of this mini-script is to list the rows from a database loaded
in memory ($ref_db is the reference to hashtable that cotains the DB). So I
want to order the fields by different sort rules, and make the proccess as
abstract as it's possible with a subrutine (sub cmpRule). This sub
On 12/02/2006 06:22 AM, Sergio Escalada wrote:
Hi all! I would like to know if it's possible to make an array sorting with
a subroutine call.
Usually, a sort is made as, for example:
sort {$a = $b} @array;
But my intention is something like:
sort subroutine_call @array;
sub subroutine
#
# hashref? Why in the WORLD is the database being kept in a hashref?
#
Oh, it's an exercise for class, and I must keep data in a hashtable, it's
not my fault ^_^
Thanks for your code :)
#
# if you have a small number of columns you want to sort by, build a
# simple subroutine to sort by
sorting subroutines explicitly,
since their number may be high (sort by one ore more fields, in
different order, ascending/descending, numeric/string sort
- in different combinations.
Instead, we code an abstract subroutine (sort_sub_factory)
that returns sorting subroutines created
possible to give a code block
(delivering a subroutine reference) as argument to sort that does the
actual sort.
2. We don't code these different possible sorting subroutines explicitly,
since their number may be high (sort by one ore more fields, in
different order, ascending/descending
sorting?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response
instead of the via the 4th octet.
Is there a Perl module that does proper IP sorting?
http://search.cpan.org/~sarenner/Net-IPAddress-1.10/IPAddress.pm
You can use the ip2num, sort and then num2ip.
OR:
You can represent them with IP-objects:
http://search.cpan.org/~luismunoz/NetAddr-IP-4.004
On Mon, 13 Nov 2006 14:38:25 +0100
Roman Daszczyszak [EMAIL PROTECTED] wrote:
Is there a Perl module that does proper IP sorting?
I think you could use NetAddr::IP for that job. Or something simpler
like that:
use Socket;
@sorted = map { inet_ntoa($_) } sort map { inet_aton($_) } @unsorted
Hi Roman,
Please sort the IP addresses with this way could help you,
@list = sort { $b = $a } @ip_addresses;
rgds,
Rajeev
-- Forwarded message --
From: Roman Daszczyszak [EMAIL PROTECTED]
Date: Nov 13, 2006 7:08 PM
Subject: Looking for a Perl module for proper IP sorting
module that does proper IP sorting?
my @sorted = sort {
my @a = $a =~ /(\d+)/g;
my @b = $b =~ /(\d+)/g;
shift @a = shift @b or
shift @a = shift @b or
shift @a = shift @b or
shift @a = shift @b
} @ips;
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail
octet.
Is there a Perl module that does proper IP sorting?
No need for a module:
$ perl -le'
print for map unpack( q[x4 A*], $_ ),
sort
map pack( q[C4 A*], /\d+/g, $_ ),
qw[
192.168.0.1
192.168.0.100
192.168.0.101
192.168.0.114
192.168.0.115
192.168.0.116
192.168.0.117
my @sorted = sort {
my @a = $a =~ /(\d+)/g;
my @b = $b =~ /(\d+)/g;
shift @a = shift @b or
shift @a = shift @b or
shift @a = shift @b or
shift @a = shift @b
} @ips;
Rob
Thanks, that did it!
Now I have to figure out why that works... hmm..
Roman
--
To unsubscribe, e-mail:
Please sort the IP addresses with this way could help you,
@list = sort { $b = $a } @ip_addresses;
Wouldn't this do the same kind of sort I've been doing (aka a textual one)?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
Please sort the IP addresses with this way could help you,
@list = sort { $b = $a } @ip_addresses;
Wouldn't this do the same kind of sort I've been doing (aka a textual
one)?
No, I don't think so.
perl -MSocket -wle 'print for map { inet_ntoa($_) } sort map
{ inet_aton($_) } '
John W. Burns am Donnerstag, 28. September 2006 17:11:
Sorting DBM Hash
Greetings:
Hello John W.
I've run into what appears to be a conflict in sorting
a DBM Hash. The DBM is opened and closed through tie and untie to store
selections
from Perl Tk medical questionnaire which uses
Sorting DBM Hash
Greetings:
I've run into what appears to be a conflict in sorting
a DBM Hash. The DBM is opened and closed through tie and untie to store
selections from Perl Tk medical questionnaire which uses checkboxes, radio
buttons and
lists, and contains over 200 items. I'm attempting
Sorting DBM Hash
Greetings:
I've run into what appears to be a conflict in sorting
a DBM Hash. The DBM is opened and closed through tie and untie to store
selections
from Perl Tk medical questionnaire which uses checkboxes, radio buttons and
lists, and contains over 200 items. I'm
John W. Krahn wrote:
Hardly Armchair wrote:
Hello List,
Hello,
I have a data structure like so:
%p_mod = {
^
You are using the wrong punctuation. That would produce a warning if you had
warnings enabled.
Sorry. I'm actually generating this data structure dynamically and
be greater
than 5 (due to the nature of the data), so a default sort will do the
same thing as a numeric sort. This is good because it is easy and, I've
heard, using default sort is faster than any other way of sorting in
Perl. However, I am curious as to how this would be accomplished
a default sort will do the
same thing as a numeric sort. This is good because it is easy and, I've
heard, using default sort is faster than any other way of sorting in
Perl. However, I am curious as to how this would be accomplished the
proper way; that is, by numerically sorting the keys
that the numbers will never be greater
than 5 (due to the nature of the data), so a default sort will do the
same thing as a numeric sort. This is good because it is easy and, I've
heard, using default sort is faster than any other way of sorting in
Perl. However, I am curious as to how
macromedia wrote:
Hi,
Hello,
I can't seem to get my script to sort properly.
Yes, it is a bit tricky to get right.
Below is my code along with
a sample input.txt file. I also have what the output.txt file should look
like. Also note any duplicate should be striped out
which seems to
perldoc perlop.
No, this doesn't quite do it. I see your data is a little more
complicated than what I thought before. When you have unusual
sorting requirements, you need unusual sorting keys. I decided
to use sprintf() to give me keys that are formatted perfectly
for sorting:
require
On 07/25/2006 08:32 PM, macromedia wrote:
Hi,
I can't seem to get my script to sort properly. [...]
Here is a shortened version of your program:
use strict;
use warnings;
use File::Slurp;
my %tags;
foreach my $line (read_file 'sort_tags.dat') {
if ($line =~ m/id=(\d*)([[:alpha:]]*)/) {
Hi,
I can't seem to get my script to sort properly. Below is my code along with a
sample input.txt file. I also have what the output.txt file should look like.
Also note any duplicate should be striped out
which seems to work ok.
Something is getting messed up when I have the numerials along
Opps.
Once you save my code to a file the syntax woiuld be:
perl mycode.pl input.txt output.txt
Below is what I get now when I run my code on the input.txt file. As you can
see its not sorting the way I like. It should sort like the OUTPUT.TXT file
inmy previsou email.
tag id=1Test./tag
On 07/25/2006 08:32 PM, macromedia wrote:
Hi,
I can't seem to get my script to sort properly. Below
is my code [...]
sort { $a-[0] cmp $b-[0] || $a-[7] = $b-[7] }
[...]
Cmp does string comparisons. Use = for numeric
comparisons. Read perldoc perlop.
--
To
at this level to key/sort on
[0] - this level contains the 'meat'
...data...
{typedefName} = xyz; - would like to sort on this but its
nested
[1]
[1]
Normally for sorting on an array we can do
my @funcs
] - this level contains the 'meat'
...data...
{typedefName} = xyz; - would like to sort on this but its
nested
[1]
[1]
Normally for sorting on an array we can do
my @funcs = sort {$a-{typedefName} cmp $b-{typedefName
Beast wrote:
Hi,
I have some rather big chunk of data, returned from ldap server. The
format is simple:
Displa name [EMAIL PROTECTED]
Simply displying data as is is simple, but how do I sorted by
display name?
pls note that display name contains space and might not unique so I
can't put
Beast am Mittwoch, 31. Mai 2006 07.59:
Hi,
Hi
I have some rather big chunk of data, returned
How 'returned'?
from ldap server. The
format is simple:
Displa name [EMAIL PROTECTED]
Simply displying
in the sense of printing to STDOUT?
data as is is simple, but how do I sorted by
Hi
$ cat data
chandru k [EMAIL PROTECTED]
prg [EMAIL PROTECTED]
chandru k [EMAIL PROTECTED]
$ cat script.pl
#!/usr/bin/perl
while()
{
chomp;
($mail,$name)=split(/\t/,reverse($_),2);
$ha{reverse($mail)}=reverse($name);
}
foreach $k(sort values(%ha))
{
print $k\n;
Beast wrote:
Hi,
I have some rather big chunk of data, returned from ldap server. The
format is simple:
Displa name [EMAIL PROTECTED]
Simply displying data as is is simple, but how do I sorted by
display name?
pls note that display name contains space and might not unique so I
can't put
Beast am Mittwoch, 31. Mai 2006 12.06:
Beast wrote:
Hi,
I have some rather big chunk of data, returned from ldap server. The
format is simple:
Displa name [EMAIL PROTECTED]
Simply displying data as is is simple, but how do I sorted by
display name?
pls note that display name
Hi,
I have some rather big chunk of data, returned from ldap server. The
format is simple:
Displa name [EMAIL PROTECTED]
Simply displying data as is is simple, but how do I sorted by
display name?
pls note that display name contains space and might not unique so I
can't put it on %hash.
- Original Message -
From: Beast [EMAIL PROTECTED]
Date: Wednesday, May 31, 2006 1:59 pm
Subject: sorting?
Hi,
I have some rather big chunk of data, returned from ldap server.
The
format is simple:
Displa name [EMAIL PROTECTED]
Simply displying data as is is simple, but how
I have a rather large group of files (~5000) that I would like to sort
into directories by date. Initially by year, then perhaps later by
year/month.
I'm looking at the -M operator, but it seems like that would require you
find the number of days of the year, today is, then do the math.
[EMAIL PROTECTED] wrote:
I have a rather large group of files (~5000) that I would like to sort
into directories by date. Initially by year, then perhaps later by
year/month.
I'm looking at the -M operator, but it seems like that would require you
find the number of days of the year, today
[EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] wrote:
I have a rather large group of files (~5000) that I would like to sort
into directories by date. Initially by year, then perhaps later by
year/month.
I'm looking at the -M operator, but it seems like that would require
you
Ed [EMAIL PROTECTED] asked:
[...]
I'm reading from a file and constructing an array of arrays.
Here's an example of what's in the file:
net localgroup Field Aidan /ADD
[...]
I want to sort the lines in the file by the 3rd column
(Field, Internal, CM, DocAdmin)
If you're not particularly
Ed wrote:
: my @lineArray;
: while(F)
: {
: # if the line is a net localgroup line add it to the array
: if( $_ =~ $s_criteria )
You probably should be testing against a regular expression.
if ( $_ =~ /$s_criteria/ )
Or just:
if ( /$s_criteria/ )
:
Ed wrote:
I want to sort the lines in the file by the 3rd column (Field,
Internal, CM, DocAdmin)
Since Perl doesn't really support multidimensional arrays but instead
uses references, something like this should work:
sort { $$a[2] cmp $$b[2] } @array;
This is more or less like the typical
Thomas Bätzler wrote:
Ed [EMAIL PROTECTED] asked:
push( @lineArray, @_ ); ---no it's an array of arrays.
This will append all the items in @_ to @lineArray.
You shoul've said push( @lineArray, [EMAIL PROTECTED] ); instead.
No he shouldn't have. @_ is a global variable so
Charles K. Clarkson wrote:
Ed wrote:
: push( @lineArray, @_ ); ---no it's an array of arrays.
An array of arrays is a short name for an array of array
references. Array elements can only hold scalar values and arrays
are not scalars. References to arrays are scalars.
I'm still hobbled by my thinking in C problem so I'm looking for a way
to do this.
I'm reading from a file and constructing an array of arrays.
Here's an example of what's in the file:
net localgroup Field Aidan /ADD
net localgroup Internal Aidan /ADD
net localgroup CM Aidan /ADD
net localgroup
Hi group,
I am trying to process a hash (words as keys and frequency counts in an
array as values). Instead of just sorting it by values, I want to sort
it by the probabilities and I tried this...
foreach $rule (sort {\compute_probability($b) =
\compute_probability($a)} keys %rules_new
And it doesn't work. Any help is appreciated.
Hello,I'd modify your script as follow,and it could work for me.
use strict;
use warnings;
my %rules_new = (aaa = [11,22,33,44],
bbb = [55,66,77,88],
);
for my $rule (sort {compute_probability($b) =
Hi..
I have:
$code[0][0] = AAA
$code[0][1] = 19.5
$code[1][0] = AAD
$code[1][1] = 20.0
$code[2][0] = ZZZ
$code[2][1] = 10.7
$code[3][0] = XXA
$code[3][1] = 5.9
$code[4][0] = YXA
$code[4][1] = 27.1
$code[5][0] = AZX
$code[5][1] = 1.9
What would be the best way to sort this?
--
Ash Varma
Ash == Ash Varma [EMAIL PROTECTED] writes:
Ash Hi..
Ash I have:
Ash $code[0][0] = AAA
Ash $code[0][1] = 19.5
Ash $code[1][0] = AAD
Ash $code[1][1] = 20.0
Ash $code[2][0] = ZZZ
Ash $code[2][1] = 10.7
Ash $code[3][0] = XXA
Ash $code[3][1] = 5.9
Ash $code[4][0] = YXA
Ash $code[4][1] = 27.1
Ash
Ash Varma [EMAIL PROTECTED] writes:
Hi..
I have:
$code[0][0] = AAA
$code[0][1] = 19.5
$code[1][0] = AAD
$code[1][1] = 20.0
$code[2][0] = ZZZ
$code[2][1] = 10.7
$code[3][0] = XXA
$code[3][1] = 5.9
$code[4][0] = YXA
$code[4][1] = 27.1
$code[5][0] = AZX
$code[5][1] = 1.9
What would
sorry for an incomplete question, but this is exactly what I was after..
:)
Thanks
On 3/20/06, Christer Ekholm [EMAIL PROTECTED] wrote:
Ash Varma [EMAIL PROTECTED] writes:
Hi..
I have:
$code[0][0] = AAA
$code[0][1] = 19.5
$code[1][0] = AAD
$code[1][1] = 20.0
$code[2][0] =
Scott Palmer wrote:
I am attempting to sort by a field in a hash within a hash and I am
having a hard time finding the right direction. I want the print out to
sort from smallest to largest in size. Any help would be greatly
appreciated.
--
I am attempting to sort by a field in a hash within a hash and I am
having a hard time finding the right direction. I want the print out to
sort from smallest to largest in size. Any help would be greatly
appreciated.
Scott
--
#!/usr/bin/perl
# Set your
Scott Palmer wrote:
I am attempting to sort by a field in a hash within a hash and I am
having a hard time finding the right direction. I want the print out
to sort from smallest to largest in size. Any help would be greatly
appreciated.
Scott
--
A variation on the same theme, for sorting by value instead of key:
use strict;
use warnings;
my %hash = qw(1 A 2 B 3 C);
foreach my $key ( sort {$hash{$a} = $hash{$b} } keys %hash ) {
print $key = $hash{$key}\n;
}
-Original Message-
From: Charles K. Clarkson
Hi!
I have a script like:
%hash = qw(1 A 2 B 3 C);
while (($key, $value) = each %hash) {
print $key = $value\n;
}
it prints out:
1 = A
3 = C
2 = B
I want it to print out a sorted hash like:
1 = A
2 = B
3 = C
How do I do that?
Regards Anders.
Anders Stegmann
Ph.d. student
Anders Stegmann am Montag, 26. Dezember 2005 15.22:
Hi!
Hello
I have a script like:
%hash = qw(1 A 2 B 3 C);
while (($key, $value) = each %hash) {
print $key = $value\n;
}
it prints out:
1 = A
3 = C
2 = B
I want it to print out a sorted hash like:
1 = A
2 = B
3 = C
How
structure for your solution? If you are sorting a hash
more than once, you may want to use a sorted hash
module or you may want to use a different data
structure.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands
question is: Are you using the right data
structure for your solution? If you are sorting a hash
more than once, you may want to use a sorted hash
module or you may want to use a different data
structure.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
--
To unsubscribe, e-mail
I have been trying to sort a hash but I cannot figure it out for the
life of me
The hash is in the form:
my %message {
messageid { From=
To=
all the way at the end of the things you're
sorting. I don't think you actually know what $a and $b are. $a and $b
represent two elements of the list you're sorting -- this means they're
two keys from %message. This means the ONLY place it makes sense for them
to be is $message
Hi
Sorry for the trouble...I got it
we can use reverse function...
Once again Sorry
Anish
- Original Message -
From: Anish Kumar K
To: beginners@perl.org
Sent: Monday, September 12, 2005 11:20 AM
Subject: Need help with sorting on perl template toolkit
Hi
I
Hi
I needed the help as how to sort descending in a hash
[%FOREACH keyValue = wordCount.nsort(wordCount.$keyValue)%]
tr bgcolor=[%BGCOLOR%]
td[% keyValue %]/td
td[% wordCount.$keyValue %]/td
/tr
[%END%]
This is sorting in ASCENFDING order. I tried out giving - , NOT ASC
I've got an array full of hashrefs:
my @a = ( {N = '10.1.2.1'},
{N = '10.1.9.1'},
{N = '10.3.5.1'},
{N = '10.1.1.3'},
);
I want to sort this array, and print. I expect the output resemble:
10.1.1.3
10.1.2.1
10.1.9.1
10.3.5.1
I've fumbled with this for a
On Tue, Aug 09, 2005 at 06:03:18AM -0400, Jeremy Kister wrote:
I've got an array full of hashrefs:
my @a = ( {N = '10.1.2.1'},
{N = '10.1.9.1'},
{N = '10.3.5.1'},
{N = '10.1.1.3'},
);
I want to sort this array, and print. I expect the output
On 8/9/2005 6:26 AM, Paul Johnson wrote:
my @s = map { $_ - [0] }
sort { $a-[0] = $b-[0] ||
$a-[1] = $b-[1] ||
$a-[2] = $b-[2] ||
$a-[3] = $b-[3] }
map { [ $_, split /\./ ] }
map { $_-{N} } @a;
You clearly solved the
On Tue, Aug 09, 2005 at 06:53:33AM -0400, Jeremy Kister wrote:
On 8/9/2005 6:26 AM, Paul Johnson wrote:
my @s = map { $_ - [0] }
sort { $a-[0] = $b-[0] ||
$a-[1] = $b-[1] ||
$a-[2] = $b-[2] ||
$a-[3] = $b-[3] }
map { [
Jeremy Kister wrote:
On 8/9/2005 6:26 AM, Paul Johnson wrote:
my @s = map { $_ - [0] }
sort { $a-[0] = $b-[0] ||
$a-[1] = $b-[1] ||
$a-[2] = $b-[2] ||
$a-[3] = $b-[3] }
map { [ $_, split /\./ ] }
map { $_-{N} } @a;
You
On 8/9/2005 8:43 AM, John W. Krahn wrote:
Jeremy Kister wrote:
I've apparently dumbed down my code and question a bit too much: I have
multiple hashrefs in each element of the array, and I need the resulting
sorted array to contain all the data in the original array, simply
sorted by the value
On Aug 9, Jeremy Kister said:
my @s = map $_-[ 1 ],
sort { $a-[ 0 ] cmp $b-[ 0 ] }
map [ inet_aton( $_-{ N } ), $_ ],
@a;
Now to analyze WTF we're doing here :)
Paul's answer had a slight typo in it -- he was comparing $a-[0],
$a-[1], $a-[2], and $a-[3], when he
On Tue, Aug 09, 2005 at 05:00:44PM -0400, Jeff 'japhy' Pinyan wrote:
On Aug 9, Jeremy Kister said:
my @s = map $_-[ 1 ],
sort { $a-[ 0 ] cmp $b-[ 0 ] }
map [ inet_aton( $_-{ N } ), $_ ],
@a;
Now to analyze WTF we're doing here :)
Paul's answer had a slight
Beast wrote:
Jeff 'japhy' Pinyan wrote:
Is there any builtin function in perl to sort the above array based
on uid, username or fulname?
There is a built-in function to sort a list, yes. But the mechanism
by which to sort the list is, in this case, up to you to provide.
This works:
MNibble wrote:
Beast wrote:
Jeff 'japhy' Pinyan wrote:
Is there any builtin function in perl to sort the above array based
on uid, username or fulname?
There is a built-in function to sort a list, yes. But the mechanism
by which to sort the list is, in this case, up to you to
I have an array:
my @employee = ( [29243, 'john', 'John doe'],
[24322, 'jane', 'Jane doe'],
[27282, 'james', 'James doe']
);
Is there any builtin function in perl to sort the above array based on
uid, username or fulname?
--
--beast
--
On Jul 13, Beast said:
my @employee = ( [29243, 'john', 'John doe'],
[24322, 'jane', 'Jane doe'],
[27282, 'james', 'James doe']
);
Is there any builtin function in perl to sort the above array based on uid,
username or fulname?
There is a
Jeff 'japhy' Pinyan wrote:
Is there any builtin function in perl to sort the above array based on
uid, username or fulname?
There is a built-in function to sort a list, yes. But the mechanism by
which to sort the list is, in this case, up to you to provide. This works:
my @sorted =
On Jul 13, Beast said:
Jeff 'japhy' Pinyan wrote:
Is there any builtin function in perl to sort the above array based on uid,
username or fulname?
There is a built-in function to sort a list, yes. But the mechanism by
which to sort the list is, in this case, up to you to provide. This
the column on what you want to search as a argument..
my $i = $ARGV[0] || 0;
# sort subroutine..
my $subsort = sub {
#no warnings;
$a-[$i] = $b-[$i]
||
$a-[$i] cmp $b-[$i]
};
print Sorting by column $i\n;
foreach my $j ( sort $subsort @employee ){
print @$j\n;
}
__END__
Jeff 'japhy' Pinyan mailto:[EMAIL PROTECTED] wrote:
On Jul 13, Beast said:
Jeff 'japhy' Pinyan wrote:
Is there any builtin function in perl to sort the above array based
on uid, username or fulname?
There is a built-in function to sort a list, yes. But the mechanism
by which to sort
On Jul 13, Ankur Gupta said:
Jeff 'japhy' Pinyan wrote:
Is there any builtin function in perl to sort the above array based
on uid, username or fulname?
my @sorted = sort {
$a-[0] = $b-[0]
} @employees;
Hey, This will sort only numbers. Will have no effect if the values have
Here is one way to approach:
!perl
use strict;
use warnings;
my %AlphaToNbr = qw(jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8
sep 9
oct 10 nov 11 dec 12);
foreach my $MySortedFile (sort { $a-[1] = $b-[1]
or
$AlphaToNbr{lc($a-[2])} =
$AlphaToNbr{lc($b-
On Jul 7, Ryan Frantz said:
foreach my $MySortedFile (sort { $a-[1] = $b-[1]
or
$AlphaToNbr{lc($a-[2])} =
$AlphaToNbr{lc($b-
[2])} or
$a-[3] = $b-[3]
}
map {[$_, /^.(\d{4})(\w{3})(\d{2})/]}
Ryan Frantz wrote:
Here is one way to approach:
!perl
use strict;
use warnings;
my %AlphaToNbr = qw(jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8
sep 9 oct 10 nov 11 dec 12); foreach my $MySortedFile (sort {
$a-[1] = $b-[1]
or
$AlphaToNbr{lc($a-[2])} =
Just take DATA and replace that with @user_links. The code
should
look like:
@user_links = ( sort {
$a-[1] = $b-[1]
or
$AlphaToNumber{lc($a-[2])} = $AlphaToNumber{lc($b-[2])}
or
$a-[3] = $b-[3]
}
map {[$_, /^.(\d{4})(\w{3})(\d{2})/]}
Ryan Frantz wrote:
[snip]
Many thanks to Wags and japhy; I've really learned a lot from the both
of you. I'm off the pick up 'Programming Perl' after I finish 'Learning
Perl'...
ry
Pick up the Learning Perl Object, References, and Modules book before
picking up Programming Perl, it
this better?
I thought about grabbing the ctime of each file and sorting on that but
I'm not sure if that would add unnecessary complexity to the script.
The primary problem is that the dates in the filenames are formatted as
mmmDD rather than MMDD. Before sorting the filenames, you
of each file and sorting on that but
I'm not sure if that would add unnecessary complexity to the script.
Incidentally, these files are created by SARG (Squid log analyzer) and
I've found nothing in the config that lets me customize the naming
convention for the directories.
ry
--
To unsubscribe, e
?
I thought about grabbing the ctime of each file and sorting on that
but I'm not sure if that would add unnecessary complexity to the
script.
Incidentally, these files are created by SARG (Squid log analyzer) and
I've found nothing in the config that lets me customize the naming
convention
on.
I thought about grabbing the ctime of each file and sorting on that
but I'm not sure if that would add unnecessary complexity to the
script.
Incidentally, these files are created by SARG (Squid log analyzer)
and
I've found nothing in the config that lets me customize the naming
grabbing the ctime of each file and sorting on that but
I'm not sure if that would add unnecessary complexity to the script.
The primary problem is that the dates in the filenames are formatted as
mmmDD rather than MMDD. Before sorting the filenames, you
could convert the month NAMES
I'm stumped on how to sort an array based on a hash refrences's key in
each element of my array.
this is dumbed down code of what I have:
my @array;
while(my $row = $sth-fetchrow_arrayref){
my %hash = (id = $row-[0], name = $row-[1]);
push(@array, \%hash);
}
after the while loop, I'm trying to
Jeremy Kister wrote:
I'm stumped on how to sort an array based on a hash refrences's key in
each element of my array.
this is dumbed down code of what I have:
my @array;
while(my $row = $sth-fetchrow_arrayref){
my %hash = (id = $row-[0], name = $row-[1]);
push(@array, \%hash);
}
after the
On Tue, Jun 07, 2005 at 10:40:43PM -0400, Jeremy Kister wrote:
I'm stumped on how to sort an array based on a hash refrences's key in
each element of my array.
this is dumbed down code of what I have:
my @array;
while(my $row = $sth-fetchrow_arrayref){
my %hash = (id = $row-[0], name =
Jeremy Kister mailto:[EMAIL PROTECTED] wrote:
: I'm stumped on how to sort an array based on a hash refrences's
: key in each element of my array.
:
: this is dumbed down code of what I have:
: my @array;
: while(my $row = $sth-fetchrow_arrayref){
: my %hash = (id = $row-[0], name = $row-[1]);
Hello,
ran into a strange problem when doing a sort. we have a file like this:
0::Accounts;Local Language
1::Anatomy;Local Language
2::Arabic;Local Language
..
26::German;Local Language
27::Governmentpolitics;Local Language
.
3::Architecture;Local Language
Look at using lc (lower case). It can make your sort case-insensitive.
On Jun 3, 2005, at 7:17 PM, Mike Blezien wrote:
Hello,
ran into a strange problem when doing a sort. we have a file like this:
0::Accounts;Local Language
1::Anatomy;Local Language
2::Arabic;Local Language
How that apply to our code:
foreach $key (sort { $lang-{$a}-[0] cmp $lang-{$b}-[0] } keys(%{$lang}))
{
# do stuff here
}
Sean Davis wrote:
Look at using lc (lower case). It can make your sort case-insensitive.
On Jun 3, 2005, at 7:17 PM, Mike Blezien wrote:
Hello,
ran into
201 - 300 of 685 matches
Mail list logo