Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to use shebang with @ARGV?

Reply
Thread Tools

how to use shebang with @ARGV?

 
 
Mark_Galeck
Guest
Posts: n/a
 
      08-15-2009
Look at foobar.pl: (on WinXP and Strawberry Perl)

#!perl
print $#ARGV + 1 . " command-line arguments.\n";


D:\Perl>perl foobar.pl 1 1
2 command-line arguments.

D:\Perl>foobar.pl 1 1
0 command-line arguments.



Why is this so? How can I use @ARGV and shebang?

Thank you for your insights! Mark




 
Reply With Quote
 
 
 
 
Andrew DeFaria
Guest
Posts: n/a
 
      08-15-2009
body { font: Helvetica, Arial, sans-serif; } p { font: Helvetica, Arial, sans-serif; } ..standout { font-family: verdana, arial, sans-serif; font-size: 12px; color: #993333; line-height: 13px; font-weight: bold; margin-bottom: 10px; } ..code { border-top: 1px solid #ddd; border-left: 1px solid #ddd; border-right: 2px solid #000; border-bottom: 2px solid #000; padding: 10px; margin-top: 5px; margin-left: 5%; margin-right: 5%; background: #ffffea; color: black; -moz-border-radius: 10px; } ..codedark { border-top: 10px solid #03f; border-left: 1px solid #ddd; border-right: 2px solid grey; border-bottom: 2px solid grey; padding: 10px; margin-top: 5px; margin-left: 5%; margin-right: 5%; background: black; color: yellow; -moz-border-radius: 10px; } #code { color: black; font-size: 14px; font-family: courier; padding-left: 5px; } #line-number { color: #804000; font-family: Arial; font-size: 14px; padding-right: 5px; border-right: 1px dotted #804000; } blockquote[type=cite] { padding: 0em .5em .5em .5em !important; border-right: 2px solid blue !important; border-left: 2px solid blue !important; } blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid maroon !important; border-left: 2px solid maroon !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid teal !important; border-left: 2px solid teal !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid purple !important; border-left: 2px solid purple !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid green !important; border-left: 2px solid green !important; } Mark_Galeck wrote:

Look at foobar.pl: (on WinXP and Strawberry Perl) #!perl print $#ARGV + 1 . " command-line arguments.\n"; D:\Perl>perl foobar.pl 1 1 2 command-line arguments. D:\Perl>foobar.pl 1 1 0 command-line arguments. Why is this so? How can I use @ARGV and shebang? Thank you for your insights! Mark

What makes you think that Windows cares about shebang?


--
Andrew DeFaria
Don't bother me. I'm living happily ever after.

 
Reply With Quote
 
 
 
 
Mark_Galeck
Guest
Posts: n/a
 
      08-15-2009
>What makes you think that Windows cares about shebang?--Andrew DeFaria

That #!perl works at all.

 
Reply With Quote
 
Andrew DeFaria
Guest
Posts: n/a
 
      08-15-2009
body { font: Helvetica, Arial, sans-serif; } p { font: Helvetica, Arial, sans-serif; } ..standout { font-family: verdana, arial, sans-serif; font-size: 12px; color: #993333; line-height: 13px; font-weight: bold; margin-bottom: 10px; } ..code { border-top: 1px solid #ddd; border-left: 1px solid #ddd; border-right: 2px solid #000; border-bottom: 2px solid #000; padding: 10px; margin-top: 5px; margin-left: 5%; margin-right: 5%; background: #ffffea; color: black; -moz-border-radius: 10px; } ..codedark { border-top: 10px solid #03f; border-left: 1px solid #ddd; border-right: 2px solid grey; border-bottom: 2px solid grey; padding: 10px; margin-top: 5px; margin-left: 5%; margin-right: 5%; background: black; color: yellow; -moz-border-radius: 10px; } #code { color: black; font-size: 14px; font-family: courier; padding-left: 5px; } #line-number { color: #804000; font-family: Arial; font-size: 14px; padding-right: 5px; border-right: 1px dotted #804000; } blockquote[type=cite] { padding: 0em .5em .5em .5em !important; border-right: 2px solid blue !important; border-left: 2px solid blue !important; } blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid maroon !important; border-left: 2px solid maroon !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid teal !important; border-left: 2px solid teal !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid purple !important; border-left: 2px solid purple !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid green !important; border-left: 2px solid green !important; } Mark_Galeck wrote: What makes you think that Windows cares about shebang?--Andrew DeFaria
That #!perl works at all.
#!perl doesn't work at all in Windows. You must have a file association for .pl files. Try this. Rename that file to remove it's .pl extension - let's call it say mark_galeck - no extension at all. Then try running it. My bet would be that it doesn't run at all.

So then your Perl script is not being exec(1)'ed in the "standard" way thus I would not expect it to behave in a standard fashion.

Another test: take your Perl script to a Unix system. Bet it works there. That's because a true exec(1) is being used.


--
Andrew DeFaria
Make it idiot proof and someone will make a better idiot.

 
Reply With Quote
 
Mark_Galeck
Guest
Posts: n/a
 
      08-15-2009
Thank you Andrew.

 
Reply With Quote
 
fred
Guest
Posts: n/a
 
      08-15-2009
On Aug 15, 6:27*am, Mark_Galeck <(E-Mail Removed)>
wrote:
> Look at foobar.pl: (on WinXP and Strawberry Perl)
>
> #!perl
> print $#ARGV + 1 *. " command-line arguments.\n";
>
> D:\Perl>perl foobar.pl 1 1
> 2 command-line arguments.
>
> D:\Perl>foobar.pl 1 1
> 0 command-line arguments.
>
> Why is this so? *How can I use @ARGV and shebang?
>
> Thank you for your insights! *Mark



The #! line is not used by Windows to find the interpreter.
On Windows you need to associate the ".pl" file extension
with your perl.exe which your 2nd example shows you've done.

The problem you have shown is that the command line arguments
are not being passed to the interpreter.

Fire up regedit, and find the key:

HKEY_CLASSES_ROOT\Applications\perl5.10.0.exe\shel l\open\command

(yours might be for perl.exe or perl5.8.7.exe etc.)

It needs to be of the form:

"C:\strawberry\perl\bin\perl5.10.0.exe" "%1" %*

(obviously you'll need to use the path to your perl.exe

It's the "%*" that represents the comand line arguments that
get passed to the interpreter.

Additionally, you may want to add ".pl" to your PATHEXT environment
variable so that you can then run "foobar" rather than "foobar.pl";
and by adding the directory containnig foobar.pl to your PATH you
will be able to run it as "foobar" from any directory.

HTH.


 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      08-15-2009
On Sat, 15 Aug 2009 00:14:58 -0700 (PDT), fred <(E-Mail Removed)> wrote:

>On Aug 15, 6:27*am, Mark_Galeck <(E-Mail Removed)>
>wrote:
>> Look at foobar.pl: (on WinXP and Strawberry Perl)
>>
>> #!perl
>> print $#ARGV + 1 *. " command-line arguments.\n";
>>
>> D:\Perl>perl foobar.pl 1 1
>> 2 command-line arguments.
>>
>> D:\Perl>foobar.pl 1 1
>> 0 command-line arguments.
>>
>> Why is this so? *How can I use @ARGV and shebang?
>>
>> Thank you for your insights! *Mark

>
>
>The #! line is not used by Windows to find the interpreter.
>On Windows you need to associate the ".pl" file extension
>with your perl.exe which your 2nd example shows you've done.
>
>The problem you have shown is that the command line arguments
>are not being passed to the interpreter.
>
>Fire up regedit, and find the key:
>
>HKEY_CLASSES_ROOT\Applications\perl5.10.0.exe\she ll\open\command
>
>(yours might be for perl.exe or perl5.8.7.exe etc.)
>
>It needs to be of the form:
>
>"C:\strawberry\perl\bin\perl5.10.0.exe" "%1" %*
>
>(obviously you'll need to use the path to your perl.exe
>
>It's the "%*" that represents the comand line arguments that
>get passed to the interpreter.
>
>Additionally, you may want to add ".pl" to your PATHEXT environment
>variable so that you can then run "foobar" rather than "foobar.pl";
>and by adding the directory containnig foobar.pl to your PATH you
>will be able to run it as "foobar" from any directory.
>
>HTH.
>


Checklist:
1. Add association file extension .pl "%1" %*
2. Add .pl to PATHEXT (now an executable)
3. Add directory to PATH
4. Open a cmd window, type perl foobar
5. Double click .pl file from explorer to edit

Very nice, no confusion whatsoever.
-sln
 
Reply With Quote
 
Mark_Galeck
Guest
Posts: n/a
 
      08-16-2009


thank you everybody, this is great, I have another rather silly (I am
sure) question about sockets, in a moment
 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      08-16-2009
On Sat, 15 Aug 2009 22:14:02 -0700 (PDT), Mark_Galeck <(E-Mail Removed)> wrote:

>
>
>thank you everybody, this is great, I have another rather silly (I am
>sure) question about sockets, in a moment


Hey I got a socket question for you. Besides handshaking, what layers
if any do you send packetised over the connection. Do you ever do
private socket talk?

-sln

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
compile shebang into pyc file Joerg Schuster Python 11 04-28-2005 07:46 AM
shebang in cross platform scripts rbt Python 5 04-06-2005 05:33 PM
Optimize flag on shebang line Andres Corrada-Emmanuel Python 0 12-09-2003 07:02 PM
Re: shebang strange thing... Dan Bishop Python 19 06-29-2003 10:30 PM



Advertisments