Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Changing the input value

by Athanasius (Archbishop)
on Apr 04, 2015 at 04:27 UTC ( [id://1122396]=note: print w/replies, xml ) Need Help??


in reply to Changing the input value

Hello battingboy, and welcome to the Monastery!

If we assume that:

  • your x values are contained in the file “x.dat”, which resides in the same directory as the Perl script
  • the values you want are in the 4th column (which is number 3, because we’re counting columns as offsets from the left, so the first column is number 0)
  • all data values are separated by whitespace
  • you want all the values in the column

then you can extract the x values like this:

#! perl use strict; use warnings; use Data::Dump; my $file = 'x.dat'; my $column = 3; my $separator = qr{\s+}; # split on whitespace my @values; open(my $fh, '<', $file) or die "Cannot open file '$file' for reading: $!"; while (my $line = <$fh>) { chomp $line; # remove the trailing newline my @cols = split $separator, $line; push @values, $cols[$column]; } close $fh or die "Cannot close file '$file': $!"; dd \@values;

And of course you will need to repeat this for the y values (which you specify are in a different file).

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-19 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found