Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: Grabbing first column of text

by twerq (Deacon)
on Aug 02, 2001 at 22:40 UTC ( [id://101739]=note: print w/replies, xml ) Need Help??


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:??;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://101739]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-06-14 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.