Regular Expression Grabbing

Discussion in 'Perl Misc' started by Owen, Aug 31, 2003.

  1. Owen

    Owen Guest

    The Perl Cookbook 6.23 has this "bizarre" (to me) statement;

    We have found these regular expressions useful or interesting.

    Turning \ followed by n into a real newline
    s/\\n/\n/g;

    When would a \n not be a \n ? The program below sort of simulates that condition, but presumeably there is something else?

    Owen

    rcook at pcug org au



    #----------------------------------------------------
    #!/usr/bin/perl -w

    use strict;
    my $string ="Now is \n the time";
    print "$string\n";

    $string ='Now is \n the time';
    print "$string\n";

    (my $newstring = $string) =~ s/\\n/\n/g;
    print "$newstring\n";

    Now is
    the time
    Now is \n the time
    Now is
    the time
    Owen, Aug 31, 2003
    #1
    1. Advertising

  2. Owen

    Shawn Corey Guest

    Owen wrote:

    > The Perl Cookbook 6.23 has this "bizarre" (to me) statement;
    >
    > We have found these regular expressions useful or interesting.
    >
    > Turning \ followed by n into a real newline
    > s/\\n/\n/g;
    >
    > When would a \n not be a \n ?

    # not a newline
    print '\n';
    # is a newline
    print "\n";
    Shawn Corey, Aug 31, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo

    Re: Grabbing All Cookies

    S. Justin Gengo, Jul 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    357
    S. Justin Gengo
    Jul 29, 2003
  2. Ken Cox [Microsoft MVP]

    Re: Grabbing All Cookies

    Ken Cox [Microsoft MVP], Jul 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    371
    Ken Cox [Microsoft MVP]
    Jul 29, 2003
  3. VSK
    Replies:
    2
    Views:
    2,272
  4. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    831
    Alan Moore
    Dec 2, 2005
  5. GIMME
    Replies:
    3
    Views:
    11,923
    vforvikash
    Dec 29, 2008
Loading...

Share This Page