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

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

by virtuemart2 (Novice)
on Sep 09, 2013 at 08:21 UTC ( #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 (Pope) 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 (Abbot) 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
Node Status?
node history
Node Type: perlquestion [id://1052977]
Approved by hdb
help
Chatterbox?
[choroba]: LanX I miss working in a bank sometimes...
[Corion]: Discipulus: Ooof. Especially yearly things are things I like to automate instead of trying to remember how I did things last year...
[Corion]: And the second rule that I've learned is, that there is no one-off job, so writing a program for it pays off almost immediately. The third rule is to give all my programs numbers and have them reproduce that number in the name of their output files. :)
[Discipulus]: the true part is that also specification change between years.. but well our job is cheap but dont abuse of us.. ;=)
[LanX]: Choroba: do you miss chaos with ties? apply at the US government.. ;)
[ambrus]: Corion: those are good rules.
[ambrus]: Discipulus: oh sure. the input data has different filenames every time I get them.
[ambrus]: the directory structure may be 1, 2, or 3 deep, it may have spaces in the filename or not, it has dates in various format, different keywords for the same meanings, and the dates and other keywords are assembled in various ways.
[Discipulus]: no ambrus by specification i mean for example license per core instead of per socket, so fields are different

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2017-03-29 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (350 votes). Check out past polls.