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 8848795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:29:33+00:00 2026-06-14T12:29:33+00:00

I have a file which I would like to read data from. This is

  • 0

I have a file which I would like to read data from. This is a sample of the data:

NODELOAD         28     27132    3.29108E+04    7.94536E+04    0.00000E+00
NODELOAD         29     27083    9.89950E+04    9.89950E+04    0.00000E+00
NODELOAD         29     27132    6.08112E+04    6.08112E+04    0.00000E+00
NODELOAD         30     27083    1.29343E+05    5.35757E+04    0.00000E+00
NODELOAD         30     27132    7.94536E+04    3.29108E+04    0.00000E+00
NODELOAD         31        68    4.80185E+04   -5.47647E+04   -1.17033E+04
                                -1.27646E+03    1.18350E+04   -2.03885E+03
NODELOAD         31      1114    1.20706E+05   -3.31323E+04   -7.17280E+04
                                 2.28198E+03    2.75582E+04    5.74460E+02

I have this code and am able to read all values of a single line and save them to an array:

  foreach my $line (@input) {
    if($line =~ /^\s*NODELOAD\s+/i) {
      $line =~ s/^\s*//;
      @a = split(/\s+/,$line);

      $modelData{"NODELOAD"}->{$a[1]}->{$a[2]}->{"Fx"} = $a[3];
      $modelData{"NODELOAD"}->{$a[1]}->{$a[2]}->{"Fy"} = $a[4];
      $modelData{"NODELOAD"}->{$a[1]}->{$a[2]}->{"Fz"} = $a[5];

However, there are some “NODELOAD” definitions in the file that are defined on two lines and have 6 load values instead of 3 (the first two numbers on each line are identifiers, the following 3/6 are data).

Is it easiest writing an if statement, which saves the data if the following line does not begin with “NODELOAD” and contains numbers? The very last line after this part in the text file will not contain any numbers, but may be blank or contain text.

  • 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. Editorial Team
    Editorial Team
    2026-06-14T12:29:34+00:00Added an answer on June 14, 2026 at 12:29 pm

    Yes, the easiest approach would be to keep values from previous call in some variable, then if if(/NODELOAD/) doesn’t match, you get just 3 values and process them using identifiers from previous line (and previous look iteration). You could also skip a regexp in if, and check for the first element of split result:

    my @last_values;
    foreach my $line (@input) {
        $line =~ s/^\s+//;
        my @values = split(/\s+/, $line);
        if( $values[0] ne 'NODELOAD' ) {
            unshift( @values, @last_values[0..2] ); # Get first 3 values from previous call
            # Then process it however you'd like to
            $modelData{"NODELOAD"}->{$values[1]}->{$values[2]}->{"Fx2"} = $values[3];
        }
        elsif {
            # process like previously...
            $modelData{"NODELOAD"}->{$values[1]}->{$values[2]}->{"Fx"} = $values[3];
            $modelData{"NODELOAD"}->{$values[1]}->{$values[2]}->{"Fy"} = $values[4];
            $modelData{"NODELOAD"}->{$values[1]}->{$values[2]}->{"Fz"} = $values[5];
            @last_values = @values; # and save for future reference
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one file in my project, (the readme file,) which I would like
I have a large 100mb file which I would like to perform about 5000
I have a long list of files and file extensions which I would like
I have a file template.txt which contains the following: Hello ${something} I would like
Suppose I have file which goes like this : a void measure() { a
Example: I read data from an XML file. This data has unique id elements.
--I have some rows from my table which I would like to export in
I have a text file (tab separated) which consist of 17 column. I would
I have a file which contains lines of data in the following format: a11
I have a file which I'm trying to extract information from, the file has

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.