Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Sort then conditionally sort

by lukez (Initiate)
on Apr 10, 2009 at 04:46 UTC ( [id://756754]=note: print w/replies, xml ) Need Help??


in reply to Re: Sort then conditionally sort
in thread Sort then conditionally sort

Hi Kyle, thank you sorry i didnt have code, I am JUST learning and I learn by looking at code solutions AND READING faqs and books etc.
I was confused about this part of your code;
my $op_io = <<'OP_INPUT_AND_OUTPUT';
and all the example before and after columns listed in between
OP_INPUT_AND_OUTPUT ;
My request for help had the columns on the left as an example of the input data file to be sorted... the 2 columns on the right are the sorted /cond sorted data that needs to go in a separate file. This confused me. thank you for taking the time to help me.

Replies are listed 'Best First'.
Re^3: Sort then conditionally sort
by kyle (Abbot) on Apr 10, 2009 at 15:20 UTC

    The construct is called a "here-document", and you can find them documented in perlop. It's basically a way to include some large chunk of text as a value in your program.

    In this case, I used it to hold your example data. After setting $op_io to that value, I use split to cut it into individual lines, and I loop over those lines to pull the individual values out. When I'm done, I have your inputs and desired output.

    I did it that way so I wouldn't have to reformat what you posted. I just pasted it in and wrote some code to pull out what I wanted.

      Thanks Kyle, but How would this be adapted to read in a file and out put to another/

        Have a look at open and print. This code does nothing but copy an input file to the output file to show their use. For your application, you'll want to do a lot more "stuff" between the reading and writing.

        my $in_filename = 'in.txt'; my $out_filename = 'out.txt'; open my $in_fh, '<', $in_filename or die "Can't read '$in_filename': $!"; open my $out_fh, '>', $out_filename or die "Can't write '$out_filename': $!"; while ( my $in_line = <$in_fh> ) { print {$out_fh} $in_line; } close $in_fh or die "close failed: $!"; close $out_fh or die "Close failed: $!";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://756754]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-25 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found