in reply to Re^2: sanity check
in thread sanity check

C:\>perl -e "use 5.012; my $foo='abc def';my @foo=split(/ /,$foo); for + (@foo) {say $_;} abc def C:\>perl -e "use 5.012; my $foo='abc def';my @foo=split m/ /,$foo; for + (@foo) {say $_;} abc def

What did I miss?

Replies are listed 'Best First'.
Re^4: sanity check
by jwkrahn (Abbot) on Sep 21, 2011 at 05:39 UTC

    That split(/ /,$foo) and split m/ /,$foo are exactly the same.    I was pointing out the difference between split m/ /, $line and split(" ", $line)

    $ perl -le' use Data::Dumper; $Data::Dumper::Useqq = 1; my $foo = " abc\t\tdef\r\rghi\n"; print Dumper $_ for split / /, $foo; ' $VAR1 = ""; $VAR1 = ""; $VAR1 = "abc\t\tdef\r\rghi\n"; $ perl -le' use Data::Dumper; $Data::Dumper::Useqq = 1; my $foo = " abc\t\tdef\r\rghi\n"; print Dumper $_ for split " ", $foo; ' $VAR1 = "abc"; $VAR1 = "def"; $VAR1 = "ghi";
Re^4: sanity check
by BrowserUk (Patriarch) on Sep 21, 2011 at 03:12 UTC
    What did I miss?

    If you use -E instead of -e, you can save yourself from typing use 5.012; :)

    C:\test>perl -E "my $foo='abc def';my @foo=split m/ /,$foo; for (@foo) + {say $_}" abc def

    A little more by omitting the $_:

    C:\test>perl -E "my $foo='abc def';my @foo=split m/ /,$foo; for (@foo) + {say}" abc def

    More still by using the modifier form of for:

    C:\test>perl -E "my $foo='abc def';my @foo=split m/ /,$foo; say for @f +oo" abc def

    A lot more by using the string constant directly in the only place it is used:

    C:\test>perl -E "my @foo=split m/ /,'abc def'; say for @foo" abc def

    And finally, do away with the variables completely:

    C:\test>perl -E "say for split m/ /,'abc def'" abc def

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.