-F works on command line but not on #!perl -paF line 
Author Message
 -F works on command line but not on #!perl -paF line

Pardon if this is a FAQ, but searching for "-F" or "split" on google
groups doesn't help much, and I could swear I'm following the docs. I
can't seem to figure out how to use -F on the #! line, even though it
works fine on the command line.


1:2:3
1_2_3

foo% more a.pl
#!/usr/local/bin/perl -palF/:/

foo% perl a.pl
Scalar found where operator expected at a.pl line 2, at end of line
        (Missing semicolon on previous line?)
syntax error at a.pl line 2, near "$_"
Execution of a.pl aborted due to compilation errors.

foo% chmod +x a.pl
foo% a.pl
1:3:4
1_3_4

I've tried all manner of -F/x/, -Fx, -F"x", putting the -F in
different places on the line, splitting on different regexes,
whatever. I either get errors or in rare cases no output. It happens
on ActivePerl5.6.1 as well as Solaris Perl5.005_03. Also, if I get rid
of the -F, then it works fine, splitting on whitespace.

I would think this would be a popular bug, and I can't imagine why I
haven't found it mentioned. In fact, I've even seen Perl golf results
using it. (Perl golf is why I can't just do a split in the text of the
script and avoid this issue. The scripts are run by the judges as
"perl a.pl".)

Help!

-Amir Karger



Mon, 02 May 2005 15:34:10 GMT  
 -F works on command line but not on #!perl -paF line

Quote:

> Pardon if this is a FAQ, but searching for "-F" or "split" on google
> groups doesn't help much, and I could swear I'm following the docs. I
> can't seem to figure out how to use -F on the #! line
> foo% more a.pl
> #!/usr/local/bin/perl -palF/:/

> The scripts are run by the judges as "perl a.pl"

In this case you don't need a (valid) path to perl on the #! line, so
you can remove the "/usr/local/bin/" prefix and save yourself a number
of characters.

Chris

until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}



Mon, 02 May 2005 17:00:10 GMT  
 -F works on command line but not on #!perl -paF line

Quote:

> Pardon if this is a FAQ, but searching for "-F" or "split" on google
> groups doesn't help much, and I could swear I'm following the docs. I
> can't seem to figure out how to use -F on the #! line, even though it
> works fine on the command line.

perldoc perlrun

will give you a list of all the run time switches you can use with perl



Mon, 02 May 2005 20:15:33 GMT  
 -F works on command line but not on #!perl -paF line

Quote:

> Pardon if this is a FAQ, but searching for "-F" or "split" on google
> groups doesn't help much, and I could swear I'm following the docs. I
> can't seem to figure out how to use -F on the #! line, even though it
> works fine on the command line.


> 1:2:3
> 1_2_3

You don't have to use split for this.

perl -pe's/:/_/g'

Or

perl -pe'y/:/_/'

Or

perl -072l137pe1

Quote:
> foo% more a.pl
> #!/usr/local/bin/perl -palF/:/

> foo% perl a.pl
> Scalar found where operator expected at a.pl line 2, at end of line
>         (Missing semicolon on previous line?)
> syntax error at a.pl line 2, near "$_"
> Execution of a.pl aborted due to compilation errors.

> foo% chmod +x a.pl
> foo% a.pl
> 1:3:4
> 1_3_4

> I've tried all manner of -F/x/, -Fx, -F"x", putting the -F in
> different places on the line, splitting on different regexes,
> whatever. I either get errors or in rare cases no output. It happens
> on ActivePerl5.6.1 as well as Solaris Perl5.005_03. Also, if I get rid
> of the -F, then it works fine, splitting on whitespace.

It works fine on my system: Perl 5.6.0 on Linux

John
--
use Perl;
program
fulfillment



Tue, 03 May 2005 10:55:23 GMT  
 -F works on command line but not on #!perl -paF line
But that's just the point! As I said in the rest of my post, when I
remove the full path to perl (or when I run it on Windows), I get an
error. (`which perl` does return /usr/local/bin/perl, so it's not like
I'm secretly running a different perl or something.)

And thanks for the other suggestions of how to golf this script, but I
wrote it just as a very simple test case for the post. I didn't want
to post the real -aF I was trying, because it was complicated.

I can't imagine that noone else has seen this utterly simple bug on
Windows or Solaris. OTOH, I really did cut and paste that stuff from
my command line runs! This is severely weird.

-Amir

Quote:


> > Pardon if this is a FAQ, but searching for "-F" or "split" on google
> > groups doesn't help much, and I could swear I'm following the docs. I
> > can't seem to figure out how to use -F on the #! line

> > foo% more a.pl
> > #!/usr/local/bin/perl -palF/:/

> > The scripts are run by the judges as "perl a.pl"

> In this case you don't need a (valid) path to perl on the #! line, so
> you can remove the "/usr/local/bin/" prefix and save yourself a number
> of characters.

> Chris



Tue, 03 May 2005 19:16:18 GMT  
 -F works on command line but not on #!perl -paF line
[snip]

Quote:

> > 1:2:3
> > 1_2_3

> You don't have to use split for this.

> perl -pe's/:/_/g'

> Or

> perl -pe'y/:/_/'

The quotes are unnecessary, unless slash or colon are special to the
shell.  (I think that colon is special, but only at the beginning of a
line).

   perl -pey.:._.

--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]



Thu, 05 May 2005 05:35:15 GMT  
 -F works on command line but not on #!perl -paF line
[Please don't top-post. It makes the chronology hard to follow]

Quote:

> Pardon if this is a FAQ, but searching for "-F" or "split" on google
> groups doesn't help much, and I could swear I'm following the docs. I
> can't seem to figure out how to use -F on the #! line
> foo% more a.pl
> #!/usr/local/bin/perl -palF/:/

> The scripts are run by the judges as "perl a.pl"

> In this case you don't need a (valid) path to perl on the #! line, so
> you can remove the "/usr/local/bin/" prefix and save yourself a number
> of characters.


Quote:
> But that's just the point! As I said in the rest of my post, when I
> remove the full path to perl (or when I run it on Windows), I get an
> error. (`which perl` does return /usr/local/bin/perl, so it's not like
> I'm secretly running a different perl or something.)

You pointed out a different between running the program as
        perl a.pl
and
        ./a.pl

one of which appears to tickle a parsing bug. I can't help you with that,
other than to confirm that it appears to happen with my versions of perl
(5.00503 and 5.6.1) on GNU/Linux, too.

Further, you said that the end program will be run using the first of
these two choices. I explained that this means that you don't need a
valid path to perl on the first line.

The example you gave had #!/usr/local/bin/perl as the interpreter path
in the first line of the script, but *THIS IS IRRELEVANT* when you type
"perl a.pl" at the command line; it's the perl you used on the command
line that executes the script.

Chris

until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}



Fri, 06 May 2005 10:29:37 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. perl program works on command line, but not when run through www server

2. command line args not working correctly

3. system call works in command line mode but not from web

4. System call works at command line but not within CGI

5. Blat works from command line but not in CGI script

6. work on command line and not via browser?

7. Command line Perl works but IIS Perl doesn't

8. Perl command line search and line replace

9. Can't get command line perl to work right

10. Perl daemon (demon) runs from command line but not in startup script

11. tk installed---only works from command line ($perl...)

12. -ln015 on #! line -vs- command line

 

 
Powered by phpBB® Forum Software