Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

autosplit behaviour with and without F

by Jasper (Chaplain)
on Aug 13, 2003 at 12:37 UTC ( [id://283520]=perlquestion: print w/replies, xml ) Need Help??

Jasper has asked for the wisdom of the Perl Monks concerning the following question:

I was puzzled when my script gave me different behaviour when I attached an F to the switches:
[jmccrea@juno jmccrea]$ cat testy2 #!perl -ap split; [jmccrea@juno jmccrea]$ perl -MO=Deparse testy2 LINE: while (defined($_ = <ARGV>)) { @F = split(/\s+/, $_, 0); split(/\s+/, $_, 0); } continue { print $_; } testy2 syntax OK [jmccrea@juno jmccrea]$ cat testy #!perl -apF split; [jmccrea@juno jmccrea]$ perl -MO=Deparse testy LINE: while (defined($_ = <ARGV>)) { @F = split(/\n/, $_, 0); split(/\s+/, $_, 0); } continue { print $_; } testy syntax OK
So with the F, the autosplit splits on /\n/, otherwise on /\s+/. Having thought about it, it appears that the next character after the F is interpreted as the pattern on which to split, that character being a carriage return. It just seems very odd that it wouldn't grab the empty string instead. Can't find anything in the docs.

Jasper

Replies are listed 'Best First'.
Re: autosplit behaviour with and without F
by Abigail-II (Bishop) on Aug 13, 2003 at 13:19 UTC
    I cannot duplicate that.
    $ cat -vET ttt #!/usr/bin/perl -apF$ split;$ $ perl -le 'print $]' 5.008 $ perl -MO=Deparse ttt LINE: while (defined($_ = <ARGV>)) { our(@F) = split(" ", $_, 0); split(" ", $_, 0); } continue { print $_; } ttt syntax OK $

    Note that also the first argument of split is translated differently (and incorrect in your case). Perhaps you are dealing with an older version of Perl, which has even more bugs in B::Deparse?

    Abigail

      I'm using 5.6.0, so you're probably right.

      It's not Deparse, though, the program runs differently (in the way Deparse indicates), so it's Perl that's at fault. I can't duplicate it in 5.8.0, either, so it would appear to be 'fixed'.

      Jasper
        If you can't duplicate it 5.6.1, I would call it one of the many bugs in 5.6.0.

        ------
        We are the carpenters and bricklayers of the Information Age.

        The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: autosplit behaviour with and without F
by tbone1 (Monsignor) on Aug 13, 2003 at 13:19 UTC
    It may be ... may be ... that the \n is the default for the -F switch if no pattern is given. I am at work, so I can't go delving into source code to look at this, but now you've piqued my curiosity.

    --
    tbone1
    Ain't enough 'O's in 'stoopid' to describe that guy.
    - Dave "the King" Wilson

Re: autosplit behaviour with and without F
by jsprat (Curate) on Aug 13, 2003 at 15:19 UTC
    I get the same thing on a 5.6.0 installation, but not on 5.8.

    Changing the shebang from #!perl -apF to #!perl -aF -p fixes it.

      Changing the shebang from #!perl -apF to #!perl -aF -p fixes it.

      Not for me, it doesn't. Deparse reads the -aF -p thing as:

      split(/\s+/, $_, 0);

      So it ignores the -p bit totally. That's not so good. -p -aF, on the other hand, seems fine.

      Jasper
Re: autosplit behaviour with and without F
by bsb (Priest) on Aug 28, 2003 at 09:40 UTC
    I think there's a bug when the -F is last.

    I've noticed this before when scripts that worked under linux broke under windows. The -F argument contained "\r" which broke the BEGIN block that the -F produces (toke.c:2457)

    So don't put -F last.

    echo "a:b" |perl "-lanF:\r" -e 'print $F[1]' $ echo "hi=there" | perl '-lanF/=/);print("JAPH"' -e 'print @F' JAPH hithere perl "-lanFi'~#" -e1 perl $'-lanFi\'~#\200' -e1

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://283520]
Approved by gjb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found