I am using a Linux system (Ubuntu 9.10).
It took me several hours of frustration to realise something about $0. This built-in variable is defined in
perlvar as "the name of the program being executed". Perlvar doesn't mention that its meaning can change, even inside the same program running under the same system, according to the way the program is run.
You have this code:
#!/usr/bin/perl -w
use UI::Dialog; # sudo apt-get install libui-dialog-perl
my $statement = "My name is $0...\n";
my $d1 = new UI::Dialog(title => 'I know my name');
$d1->msgbox(text => $statement);
print $statement;
exit;
You save it into a file named "knowthyself" in your Desktop.
You give the file executable permissions (chmod 755 knowthyname).
Then you run the program 3 times:
- The first time you open a terminal and type "perl knowthyself". You get this output: "My name is knowthyself..."
- Then you use the terminal and type "./knowthyself". You get this output: "My name is ./knowthyself..."
- Finally you go to your file manager (Nautilus) and click on the file. You are asked what to do: Do you want to run it in a terminal, do you want to show its contents, do you want to cancel the action, or do you want to just run it? Of course you choose this last action (run the program without opening a terminal). You get this output (in a window): My name is /home/user/Desktop/knowthyself...
Moral: even if you are running your program under one and the same system, even if it supports $0, you have to be very careful before relying on what $0 returns.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.