Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Re: Re: This looks like someone sneezed and hit the keyboard

by MCS (Monk)
on Feb 03, 2004 at 17:05 UTC ( [id://326255]=note: print w/replies, xml ) Need Help??

in reply to Re: Re: This looks like someone sneezed and hit the keyboard
in thread This looks like someone sneezed and hit the keyboard

The reason that most people say you shouldn't use .* is because it can match nothing (or everything) so matching just .* is pointless because it will match everything (including nothing) However, if you were looking for "hi" some ammount of text and then "there" you could use:

$line =~ /hi.*there/;

and it would match. Of course it's greedy and might not be exactly what you wanted but there are times when it is needed. However, it is overused a lot and usually something better can be used.

To answer your question though, /.* doesn't grab everything because it has required stuff after that. If you try and match /.*some text/ It has to find "some text" or it will fail. However, if you try and match something like: /.*\d?/ it could match nothing since the \d is optional.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-06-22 09:26 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    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.