Solved

ST logic

Posted on 2001-06-10
2
190 Views
Last Modified: 2010-03-05
sub ST(&@)
 {
  my $metric=shift; map{$_->[0]} sort{$b->[1]<=>$a->[1]} map{[$_,&{$metric}]} @_;
 };

print NEWFILE ST{return (split/\|/)[1]}<OLDFILE>;

# What corresponds to the above code in one line?
# (How do I remove the subroutine?)
0
Comment
Question by:superquestions
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 25 total points
ID: 6173888
#assumng (split/\|/)[1] are integers
print NEWFILE map{/\|(.*)/s}sort map{join'|',5e14-(/\|([^|]*)/)[0],$_}<OLDFILE>;
0
 
LVL 1

Author Comment

by:superquestions
ID: 6174861
# The complete code is like this:

@list=("joined.txt","posted.txt");

sub ST(&@)
 {
  my $metric=shift; map{$_->[0]} sort{$b->[1]<=>$a->[1]} map{[$_,&{$metric}]} @_;
 };

foreach $file(@list)
 {
  open(OLDFILE, "<$file.txt");
   flock OLDFILE, 1;

   open(NEWFILE, ">$file.tmp");
    flock NEWFILE, 2;

    print NEWFILE ST{return (split/\|/)[1]}<OLDFILE>;

   close(NEWFILE);
  close(OLDFILE);
 };

# Is it an intenger?
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now