Re: Map or Regex and Sorting
From: Matija Papec (perl_at_my-header.org)
Date: 05/24/04
- Next message: Brian Helterline: "Re: How to substitute a variable containing a directory path into Apache httpd.conf file????"
- Previous message: Paul Lalli: "Re: Perl inplace editing"
- In reply to: Herr Hardy: "Re: Map or Regex and Sorting"
- Next in thread: Herr Hardy: "Re: Map or Regex and Sorting"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 24 May 2004 22:38:55 +0200
X-Ftn-To: Herr Hardy
Herr Hardy <schaumfestiger@gmx.de> wrote:
>>to the lines. Make the key -1 if the line contains "OPEN", otherwise
>>use the first group of digits. Sort according to keys, throw the
>>keys away.
>
>ooh great, Anno, I'd already seen the Schwartzian transform while
>googling, but I'm pretty unfamiliar with that mighty map function and
>wouldn't get that assignment
>> map [ $_ , /OPEN/ ? -1 : ( /(\d+)/ )[ 0] ], # assign keys
>to work.
If you're familiar with references, learning map is very usefull
use Data::Dumper;
print Dumper
# map [ $_ , /OPEN/ ? -1 : ( /(\d+)/ )[ 0] ], # assign keys
map {
my ($value_for_sorting) = /(\d+)/;
$value_for_sorting = -1 if /OPEN/;
[ $_, $value_for_sorting ];
}
<DATA>;
-- Secure and instant E-pay for web shops http://www.ouroboros.hr/?e-placanje
- Next message: Brian Helterline: "Re: How to substitute a variable containing a directory path into Apache httpd.conf file????"
- Previous message: Paul Lalli: "Re: Perl inplace editing"
- In reply to: Herr Hardy: "Re: Map or Regex and Sorting"
- Next in thread: Herr Hardy: "Re: Map or Regex and Sorting"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|