Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

regular expression function: grep, split, substr OR NO need?

by virtuemart2 (Novice)
on Sep 09, 2013 at 08:21 UTC ( [id://1052977]=perlquestion: print w/replies, xml ) Need Help??

virtuemart2 has asked for the wisdom of the Perl Monks concerning the following question:

In Perl there are regular expression function:
grep, split, substr very helpful to process text data.

My question is: Should I use these functions OR simply NO need?
I mean use

=~

my $string = "abcde67890"; if($string =~ m/a....6/) {print "use ~"};

THANK SO MUCH FOR REPLY! continuous...
I would like to ask further, if I would like to programming like this: NOT match the keyword
if($string !=~ m/keyword/) {print "howto NOT inverse match?"}; what should be the correct gramma syntax?

Replies are listed 'Best First'.
Re: regular expression function: grep, split, substr OR NO need?
by Corion (Patriarch) on Sep 09, 2013 at 08:23 UTC

    You are misunderstanding things. grep, split and substr are not "regular expression functions". They can use regular expressions, and often are used together with them. But the regular expression binding operator =~ only applies a match. What you do with the result is where split and grep come in.

      "But the regular expression binding operator =~ only applies a match. What you do with the result is where split and grep come in."
      Firstly, thx for quick reply!
      Well, yes, I misunderstanding the difference.
      If I would like to use functions grep, split, substr... etc
      I need to use "use module" ?
      use module use IO::File;
      thank you

        In order to read and process a file, you do not need a module. As a starting point it is probably good, if you would read the documentation of split, grep and substr and find out under which circumstances they are useful. Do you have any particular application in mind? If not, search PerlMonks to find 1000s of examples for the usage of these functions!

Re: regular expression function: grep, split, substr OR NO need?
by sundialsvc4 (Abbot) on Sep 09, 2013 at 14:33 UTC

    Welcome to the Monastery!

    When you are asking questions here, may I politely recommend that you keep in mind at least these three points:

    1. Don’t use big font-sizes.   Don’t SHOUT.   You already have our attention, however briefly.   Also, don’t make your post look like a man page.
    2. Don’t waste everyone’s time (including yours) with “teach me Perl, please,” or “don’t make me look for myself” questions.   PM is not a school.   Instead, do a reasonable amount of self-study of your particular requirement and then frame a pointed, answerable question.
    3. TMTOWTDI™ == There’s More Than One Way To Do It.   In Perl circles, that is a Mantra.   We have no idea what is, for you in your case, the best way or if there is “no need,” and no one can really answer that question for you anyway but you.   We can advise you, if given a specific question with just-enough supporting information to allow us to frame a meaningful answer.

Re: regular expression function: grep, split, substr OR NO need?
by Laurent_R (Canon) on Sep 09, 2013 at 18:02 UTC

    For sure, grep, split and substr are immensely useful and expressive, you should definitely learn to use them, but I can't say whether any of them is appropriate for your specific problem at hand.

      thanks, I will read both
      http://perldoc.perl.org/index-functions-by-cat.html

      http://www.perlmonks.org/?node=split

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-04-16 19:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found