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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:46:47+00:00 2026-06-17T22:46:47+00:00

I am opening a file (in perl) and I was wondering how do I

  • 0

I am opening a file (in perl) and I was wondering how do I determine what a tab character looks like.

I know they are in my file, but I was wondering how I can tell what it is. I know that for output to a file you would use \t, but its not the same for reading a file.

I also know that it reads it as some sort of TAB character because I printed out a line char by char on every line and could easily see the TABed lines.

  • 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-17T22:46:48+00:00Added an answer on June 17, 2026 at 10:46 pm

    Tab character is always \t, there is nothing more to say about it.

    However, some editors use conventions about how many spaces single tab character should represent. Common wisdom says 8, but often people mean 4, and I have seen it to mean 3 and even 2 spaces.

    Some editors (like Komodo or Komodo Edit) try to be smart: they read source file and count typical distribution of leading spaces and tabs. For example, if only 4,8,12,… leading spaces can be seen, it may implicitly assume that your tab character should mean 4 spaces. Or, if 2,4,6,… leading spaces are observed, it may use 2 spaces per tab.

    If I understood you correctly, you want similar behavior for leading spaces.

    In this case, you can determine most likely tab to space value using code below. Note that this code is not optimal: it would ignore lines with actual tabs, it only considers first indentation level to get tab indent and so on. Consider this only as starting point to get good implementation:

    my %dist;
    while (my $line = <>) {
        my ($spaces) = ($line =~ /(^ *)/);
        my $len = length($spaces);
        $dist{$len}++;
    }
    my @sp = sort {$a <=> $b} keys %dist;
    print "Leading space distribution in file: "
        . join(",", @sp) . "\n";
    if (scalar @sp >= 2) {
        print "Most likely tab setting is: ", $sp[1] - $sp[0];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm opening a file and finding the line I need, but then I have
I'm having trouble opening a file for reading, but only when it is inside
Can someone advise on why I get errors opening the file in the code
How can I check whether a file exists, before opening it for reading in
I'm writing a script in Perl that reads from a file and prints the
I am new programmar in Ruby. Can someone take an example about opening file
I am streaming a file of size 714kB but receiving only 635kB. Can you
After opening a file created by root in vim , how to change the
I am opening a file using the ACTION_VIEW intent from my app. Now i
I am opening a file which has 100,000 URL's. I need to send an

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.