in reply to split paragraph

actually i have found that using my(undef, $data_needed)=split(/(.+)/,$_); works if you have nothing after the pattern match. if its just my($data_needed)=(/^(.+)/,$_); it will put the whole paragraph into $data_needed for some reason. but this is just for me, and someone else may be different

thanks everyone for your input :)

Replies are listed 'Best First'.
Re^2: split paragraph
by AnomalousMonk (Archbishop) on Nov 03, 2014 at 17:02 UTC

    Your uses of the split and  m// built-in functions in this and related posts have a strong flavor of "elephants to catch eels" about them. Consider the following code, which operates on a test string containing embedded newlines because you seem to be using paragrep mode, implying such newlines:

    c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "$_ = qq{abc\ndef\nghi}; my @ra = split /(.+)/; dd \@ra; ;; @ra = /^(.+)/; dd \@ra; " ["", "abc", "\n", "def", "\n", "ghi"] ["abc"]
    Do you feel you have a fairly good grasp of what is happening in these examples? If not, time and effort invested in gaining such understanding is likely to be generously repaid.

      i have a good understanding of this example yes, but there is some things i still dont understand ofcourse. i am no seasoned professional as most of you know, and sometimes the perldocs scare me lol, so when i am able to take something out of my own script, and dull it down from 30 or 40 lines to 7-10 lines, it makes me want to share that incase any other "new" perl scripters might find it useful (or atleast the example might give them a better idea of a way they can do it)

      and i am always open to feedback. would you like to see the code that this replaces? this code dumbs down what i had before and will find the three words in the if statement (and in any order) in the paragraph. and if that is the paragraph you were looking for it should return what you need out of it trivially.

      but please do not look at me as some seasoned professional. i know alot more now than i did a few months ago when i really started to dive into perl, but i am still a long way away from being "good".

      EDIT: and yes there are many newline characters and blank lines throughout the file