in reply to Re: Grabbing first column of text
in thread Grabbing first column of text

You simply want to use ($first) = $line =~ /(\S*)/;

I believe that the original poster also wanted to capture a series of blank spaces, if that was what occupied the first element of a line.

\S matches non-whitespace characters only. . .

. . . the split solutions seem much more well-suited.

--twerq

Replies are listed 'Best First'.
Re: Re: Re: Grabbing first column of text
by Anonymous Monk on Aug 02, 2001 at 22:52 UTC

    No, if you'll read the entire post, you'll notice that I said "... if the line begins with spaces or is empty, I just want to print out a blank line..." Anyway, the first two examples here do just what I'm looking for. Thanks, guys!

Re: Re: Re: Grabbing first column of text
by japhy (Canon) on Aug 02, 2001 at 22:53 UTC
    No, the original post says:
    As you can see, if the line begins with spaces or is empty, I just want to print out a blank line so I can tell that there was something there.
    He either wants the column of text, or nothing. That is what I give him.

    _____________________________________________________
    Jeff japhy Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;