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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:04:37+00:00 2026-05-22T17:04:37+00:00

I have a script that processes the contents of a file from a CAD

  • 0

I have a script that processes the contents of a file from a CAD program, for use in another CAD program. Can the unused variables in the block be skipped, or written around? The script works fine with them in place, I was just curious if there was a cleaner way to write it. Thank you.

    string = IO.read("file.txt")

    string.scan(/regex/m) {|a,b,c,d,e,f,g|

    # captures 7 items, I use 1-4, & 6 below, skipping 5 & 7

    print a, b+".ext", c.to_f/25400000, d.to_f/25400000, f,"\n"
    }

My question lies in the last line – if I’m not using them all – do I still have to declare them all, for it to work properly, and remain in the correct order?

Elements 5 & 7 may be used at a later time, but for now, they are just part of the regex, for future flexibility.

  • 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-05-22T17:04:37+00:00Added an answer on May 22, 2026 at 5:04 pm

    You could use an array instead of an explicit list of variables and then pick things out of the array by index:

    string.scan(/regex/m) { |a|
        print a[0], a[1] + ".ext", a[2].to_f / 25400000, a[3].to_f / 25400000, a[5], "\n"
    }
    

    Either that or rework your regular expression to only capture what you need.

    You can use the same variable multiple times in the list so just renaming the things you’re not using to unused would probably be the simplest choice:

    string.scan(/regex/m) { |a, b, c, d, unused, f, unused|
        print a, b + ".ext", c.to_f / 25400000, d.to_f / 25400000, f, "\n"
    }
    

    At least this way it is (or should be) obvious that you’re not using the fifth and seventh captures. However, this doesn’t work in 1.9 so you’d have to use unused1 and unused2 in 1.9.

    An ideal balance would be to use 1.9’s named capture groups but scan doesn’t give you access to them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP CLI script, that processes a csv file, inserting it's content
I have an IronPython script that looks for current running processes using WMI. The
I have a Python script that manages a series of CasperJS tasks and processes
I have a script that will convert a text file into a resource file,
I have a script that writes a file to the file system, here is
I have a batch script that calls a process and currently it waits for
I have a script that uses Parallel::ForkManager . However, the wait_all_children() process takes incredibly
I have a Perl script that launches 2 threads,one for each processor. I need
I have a shell script that launches a Maven exec:java process - exec mvn
I have a custom script step in my build process that zips the executable.

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.