Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Reducing a line read into $_

by I0 (Priest)
on Jan 04, 2001 at 14:56 UTC ( [id://49733]=note: print w/replies, xml ) Need Help??


in reply to Reducing a line read into $_

s/\[.*?\]//;

Replies are listed 'Best First'.
Re: Re: Reducing a line read into $_
by Daniellek (Sexton) on Jan 04, 2001 at 15:18 UTC
    One fast question from acolyte: why's there "?" in your regexp?
    I wrote s/^\[.*\]//; and it works, so what gives us this question mark? or this is no difference?
    -- Daniellek

      The '?' gives you non-greedy matching. It shouldn't matter on the data that we've been shown, but if there's a chance that the data will have another ']' character later in the string, then the '?' becomes essential. Compare these:

      $_ = '[Remove this] and nothing else'; s/\[.*\]//g; print; $_ = '[Remove this] and [nothing] else'; s/\[.*\]//g; print;

      and then try then again with the '?'.

      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

        Your wisdom is superb!

        So for the problem of this thread, possibly the best possible will be: s/^\[.*?\]//g;

        Am I right?

        -- Daniellek

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found