Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Remove from character to end of line

by CukiMnstr (Deacon)
on Aug 01, 2002 at 12:50 UTC ( #186835=note: print w/replies, xml ) Need Help??


in reply to Remove from character to end of line

you have the s/// operator in perl. this should do what you want:
while(<>) { s#^([^/]+).*#$1#; print; }

hope this helps,

Update: even if the s/// works, split() is faster:

while(<>) { print((split '/')[0], "\n"); }

Update: ++Abigail-II. I need to work on my golfing skills... ;)

Replies are listed 'Best First'.
Re: Remove from character to end of line
by Abigail-II (Bishop) on Aug 01, 2002 at 12:56 UTC
    But that has to capture. You can do without capture:
    s!/.*!!;
    It's smaller code too. ;-)

    Abigail

      GREAT!!!

      Not only smaller code, but smart code too. I knew there had to be an easy way. It is amazing how dumb I feel with out my reference books.

      Thanks much,
      Simon

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2020-02-23 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (104 votes). Check out past polls.

    Notices?