pastorizah has asked for the wisdom of the Perl Monks concerning the following question:

Say your reading from a file to extract a word from a particular line, but all lines in the file are tab indented. What are you suppose to do extract this word?

Replies are listed 'Best First'.
Re: File Processing
by thor (Priest) on Jun 09, 2004 at 20:14 UTC
    Err...come again? As far as perl is concerned, it doesn't matter that all of the files begin with a tab. In your scenario, how does one identify the "particular line"? Line number? Other words on the same line? Voodoo? Throw us a bone and we'll throw you one.

    thor

      The info looks like this, and I want to extract 2W36164K and write it to another file... I am identifying the line using if ((substr($line,1,12)) eq ("Trunk Group:")) Trunk Group: 2W36164K CLEAR_CHANNEL_TR 01/05/04 MON 12:00 48 194 1,556 01/09/04 FRI 10:00 48 192 1,560
        Okay, that's a start. What you're doing isn't technically wrong, but it's not very perl-ish. perl has a wonderful pattern matching facility; you may as well take advantage of it. If I'm understanding your problem, you could approach it like this:
        if ($line =~ m/Trunk Group: (\w+)/) { my $match = $1; #do things with $match }
        I suggest you do a 'perldoc perlre' and read up on regular expressions. I think you'll be pleasantly surprised by what you find there.

        thor

        Regex is a better solution, but to answer your original question you would use a \t to represent a tab character.

        if ((substr($line,1,13)) eq ("\tTrunk Group:"))
        The text your are looking for 2W36164K, why not use a simple pattern regex?