in reply to Re^4: A Beginner Needs Homework help
in thread A Beginner Needs Homework help

did you mean an "while" loop or a if/or statement? or another ARGV?

I meant in english :)

See print, see return, see exit, see die

Main( @ARGV ); exit( 0 ); sub Main { for my $file ( @_ ){ TryAndDoStuffOrDieAndEndProgram( $file ); } } sub TryAndDoStuffOrDieAndEndProgram { open ... or die "Can't open ($file): $! "; ... close ... return; }

There are other moves than AndEndProgram, like move on to next file, see die/eval

Replies are listed 'Best First'.
Re^6: A Beginner Needs Homework help
by Swizzlestix617 (Novice) on Apr 11, 2014 at 01:40 UTC

    lol.

    I realized what you meant and changed the program so it would die if not read. what I'm trying to work on now is the pattern matching. Upon reading my textbook I don't really think I need substitution. What I need my program to do is to recognize similar words with their numbers and add them together, otherwise look over the word (and associate number) but print them anyway.

    ($info=~ /(\w+ (-?\d+ )+)/)

    That should match any word with its number, since \w is for word charters and \d is for numbers. + is for one or more of the same to match.. the and ? is so that the last number can still be counted. the dash in front of it is undefined to me by my text book.. (elements of programming with perl)

      lol... I don't really think I need substitution...

      :) sounds good

      ... That should ... the dash in front of it is undefined to me by my text book.. (elements of programming with perl)

      What does it say a regular expression is composed of? What is the special characters like "?" called? So if its not the same kind of character as the special "?" character, its what kind of character?

      :) Here is what rxrx says about the pattern

      (The start of a capturing block ($1)
        \w+Match an identifier character, one-or-more times (as many as possible)
        (The start of a capturing block ($2)
          -?Match a literal '-' character, one-or-zero times (as many as possible)
          \d+Match a digit, one-or-more times (as many as possible)
        )+The end of $2 (matching one-or-more times (as many as possible))
      )The end of $1

      Its pretty close except it doesn't explain the literal space character ... it does show that in the next step

      If you give rxrx a string, it will go a step further and show you how the regex matches

      To do it run rxrx

      then paste 'red:27  yellow:102  green:311  yellow:12  blue:45'

      then paste /(\w+ (-?\d+ )+)/

      then type m then enter and keep hitting space to see the next step

      Here is what a step looks like

      Trying literal whitespace ('\N{SPACE}') | V /(\w+ (-?\d+ )+)/ | V 'red:27 yellow:102 green:311 yellow:12 blue:45' [Visual of regex at 'rxrx' line 0] [step: 7]

      So hopefully you can see what you're missing, its the thing you had in split