Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Unable to match newline

by linuxer (Curate)
on Nov 17, 2015 at 19:42 UTC ( #1147949=note: print w/replies, xml ) Need Help??


in reply to Unable to match newline

Just some thoughts:

If you want to compare Perl with grep you need to compare the same behaviour.

Your grep uses -z ("Treat the input as a set of lines, each terminated by a zero byte (the ASCII NUL character) instead of a newline."). So it breaks the "classical" definition of a line.

I do not see something similar in your perl command. So it uses the "classical" line definition. At the same time, I think, your Regex in the perl command would not match a newline character with the '.', because it does not use the /s modifier.

Replies are listed 'Best First'.
Re^2: Unable to match newline
by robinson (Novice) on Nov 17, 2015 at 19:57 UTC

    Thank you very much for your reply. Isn't "(?s)" the same as "/s" ?

    How can I emulate the -z ("a data line ends in 0 byte, not newline") behavior of grep on Perl?

      Regarding the '(?s)': Good point. I must admit, I did not recognize (obviously) that. I'm not used to it. You're right.

      Regarding the "emulate the -z": Perl has a similar switch. Checkout perldoc perlrun and look for the first command switch description ;-)

      edit: s/command line/command/

        Thank you! Thank you! Thank you! Thank you!

        So all I needed was "perl -n0e"

        I plan to convert this mix of shell and perl program into a full perl version but that will be another day as I have to learn quite a few more things about perl :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2020-06-01 16:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (5 votes). Check out past polls.

    Notices?