Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: outputing specific co-ordinates

by Khen1950fx (Canon)
on Nov 19, 2011 at 12:01 UTC ( #938963=note: print w/ replies, xml ) Need Help??


in reply to outputing specific co-ordinates

There's no need to use no warnings 'uninitialized';---just initialize the array. Remember, too, that the 1st arg to each must be a hash.

I tried your script in a slightly different way. I used a hash because I wanted to keep each.
#!/usr/perl/bin/perl use Modern::Perl; $|=1; my($data) = '/root/Desktop/inputfile.txt'; open STDIN, '<', $data or die "File error: input file: $!"; open STDOUT, '>', '/root/Desktop/output.log' or die "File error: output file: $!"; my(%result) = (); while (defined($_ = <STDIN>)) { chomp $_; my ($index, $value) = split( /\s/, $_, 0 ); $result{$index} = $value; } while (my ($index, $value) = each(%result)) { do { say "$index => $value" if $value > 500; }; } close STDIN; close STDOUT;
Outputs:
5 => 550


Comment on Re: outputing specific co-ordinates
Select or Download Code
Re^2: outputing specific co-ordinates
by Not_a_Number (Parson) on Nov 19, 2011 at 13:01 UTC
Re^2: outputing specific co-ordinates
by Anonymous Monk on Nov 19, 2011 at 13:06 UTC

    Many thanks for your response I'm just wondering how this differs from the first script will i get the same output?

      sorry forgot to log in!

        The main difference is that I used a hash. The output was the same using 5.8.8, 5.10.1, and 5.14.1.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (14)
As of 2014-12-18 17:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (59 votes), past polls