Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 176211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:50:10+00:00 2026-05-11T13:50:10+00:00

I am writing a program that takes in an input file from the user.

  • 0

I am writing a program that takes in an input file from the user. The file has bunch of numbers in it and I will read the numbers in the file and create a plot based on those numbers using GD::Graph.

The first line of the file is X axis, second line of the file is Y values corresponding to X axis and third, fourth, …, etc For example:

1 2 3 4 5  2 4 5 10 14 5 6 8 12 13 

So in the above, first line is x-axis, second is y values corresponding to xaxis so this will fetch 10 points. (1, 2) (1, 5) (2, 4) (2, 6)….(4,10) (4,12) (5,14) (5, 13)

I plan on reading each line of the array and then splitting the line on spaces or tabs and storing the values in an array. So, array 1 will have x-axis, array2 will have y-axis, but how should I store 3rd, 4th, 5th, …, etc lines in an array so they become (x,y)?

Furthermore, how can I find the largest value for the first and second lines (2 arrays) so I can create a limit for my X and Y axes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:50:11+00:00Added an answer on May 11, 2026 at 1:50 pm

    Whoops, misread the question, you want either an AoAoH or an AoH, depending on whether each line after the first represents a line or the are all just points to be plotted respectively. Here is how I would write it if each line in the file was to become a line in the graph:

    #!/usr/bin/perl  use strict; use warnings; use List::Util qw/min max/;  my @x_points         = split ' ', scalar <>; #read in the x axis labels my ($x_min, $x_max)  = (sort { $a <=> $b } @x_points)[0,-1]; my ($y_min, $y_max)  = (0, 0);  #lines is an AoAoH, first layer are the lines to be drawn #second layer is a list of coords #third layer are the x and y coords my @lines; while (<>) {     my @y_points = split;     #if the two arrays are not the same size, we have a problem     die 'invalid file\n' unless @y_points == @x_points;      $y_min = max($y_min, @y_points);     $y_max = min($y_max, @y_points);      push @lines, [          map { { x => $x_points[$_], y => $y_points[$_] } }       0 .. $#x_points      ]; }  use Data::Dumper;  print 'x min and max $x_min $x_max\n',       'y min and max $y_min $y_max\n',       'data:\n',       Dumper(\@lines);  my $i; for my $line (@lines) {     $i++;     print 'line $i is made up of points: ',         (map { '($_->{x}, $_->{y}) ' } @$line), '\n'; } 

    And here is how I would handle it if they are just points to be ploted:

    #!/usr/bin/perl  use strict; use warnings; use List::Util qw/min max/;  my @x_points         = split ' ', scalar <>; #read in the x axis labels my ($x_min, $x_max)  = (sort { $a <=> $b } @x_points)[0,-1]; my ($y_min, $y_max)  = (0, 0);  #lines is an AoAoH, first layer are the lines to be drawn #second layer is a list of coords #third layer are the x and y coords my @points; while (<>) {     my @y_points = split;     #if the two arrays are not the same size, we have a problem     die 'invalid file\n' unless @y_points == @x_points;      $y_min = max($y_min, @y_points);     $y_max = min($y_max, @y_points);      push @points,         map { { x => $x_points[$_], y => $y_points[$_] } }         0 .. $#x_points; }  use Data::Dumper;  print 'x min and max $x_min $x_max\n',       'y min and max $y_min $y_max\n',       'data:\n',       Dumper(\@points);  print 'Here are the points: ',      (map { '($_->{x}, $_->{y}) ' } @points), '\n'; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 103k
  • Answers 103k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer select nextval('mytable_seq') from generate_series(1,3); generate_series is a function which returns… May 11, 2026 at 8:25 pm
  • Editorial Team
    Editorial Team added an answer If you use FirstOrDefault instead of First, that will return… May 11, 2026 at 8:25 pm
  • Editorial Team
    Editorial Team added an answer If i correctly understand what your asking, then the code… May 11, 2026 at 8:25 pm

Related Questions

I'm writing a program that needs to take input from an XBox 360 controller.
I am learning C and writing a simple program that will take 2 string
I am writing a fairly large and complex data analysis program and I have
I am developing a scientific application used to perform physical simulations. The algorithms used

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.