[30095] in Perl-Users-Digest
Perl-Users Digest, Issue: 1338 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 6 16:09:41 2008
Date: Thu, 6 Mar 2008 13:09:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 6 Mar 2008 Volume: 11 Number: 1338
Today's topics:
Re: module needs to know its own path <lehmannmapson@cnm.de>
Re: module needs to know its own path xhoster@gmail.com
Re: module needs to know its own path <devnull4711@web.de>
Re: module needs to know its own path <lehmannmapson@cnm.de>
Re: module needs to know its own path <noreply@gunnar.cc>
Re: module needs to know its own path <ced@blv-sam-01.ca.boeing.com>
Re: module needs to know its own path <bik.mido@tiscalinet.it>
Re: module needs to know its own path <m@rtij.nl.invlalid>
Re: Notes on unicode/utf8, CGI, DBI, mysql <stoupa@practisoft.cz>
Re: Notes on unicode/utf8, CGI, DBI, mysql <joost@zeekat.nl>
Re: Notes on unicode/utf8, CGI, DBI, mysql <joost@zeekat.nl>
Re: Perl functions xhoster@gmail.com
regexp for s/// <stoupa@practisoft.cz>
Re: regexp for s/// <glennj@ncf.ca>
Re: regexp for s/// <devnull4711@web.de>
Re: regexp for s/// <devnull4711@web.de>
Re: regexp for s/// <abigail@abigail.be>
Re: regexp for s/// <someone@example.com>
scalar context for testing arguments fvdmarkt@gmail.com
Re: scalar context for testing arguments xhoster@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 06 Mar 2008 17:02:08 +0100
From: Marten Lehmann <lehmannmapson@cnm.de>
Subject: Re: module needs to know its own path
Message-Id: <63aio9F259l2eU1@mid.individual.net>
Hello,
>> within a perl module, I need to access content included with this
>> module, but stored in separate files (WSDL definitions in my case).
>>
>> If my module lies in /usr/lib/perl5/xxx/MyModule.pm, the WDSL files
>> could be stored in /usr/lib/perl5/xxx/MyModule/WSDLs/*.wsdl or similar.
>>
>> But how can the perl module find out where it has been loaded from? The
>> files I have to access would always be relative to the perl module. But
>> that doesn't help much, as the working directory within the perl module
>> for a perl script in /test/script.pl would always be /test and not the
>> path to the script. So reading from ./WSDLs/*.wsdl would fail.
>>
>> Any ideas?
>
> (my $dir = $INC{'MyModule.pm'}) =~ s#/MyModule.pm$##;
>
> chdir $dir or die "could not cd to '$dir' $!";
this cannot work and does not work. I asked how can the perl module find
out where it has been loaded from, but your code does only work within
the script that has loaded the module. But the perl module on its own
needs to know the path it is stored.
And the perl module doesn't have to be installed within the standard
perl directories necessarily. Example:
use lib "/my/own/dir";
use MyModule;
The MyModule module shall be able to get the path /my/own/dir somehow.
Regards
Marten
------------------------------
Date: 06 Mar 2008 16:27:36 GMT
From: xhoster@gmail.com
Subject: Re: module needs to know its own path
Message-Id: <20080306112737.846$mF@newsreader.com>
Marten Lehmann <lehmannmapson@cnm.de> wrote:
> Hello,
>
> >> within a perl module, I need to access content included with this
> >> module, but stored in separate files (WSDL definitions in my case).
> >>
> >> If my module lies in /usr/lib/perl5/xxx/MyModule.pm, the WDSL files
> >> could be stored in /usr/lib/perl5/xxx/MyModule/WSDLs/*.wsdl or
> >> similar.
> >>
> >> But how can the perl module find out where it has been loaded from?
> >> The files I have to access would always be relative to the perl
> >> module. But that doesn't help much, as the working directory within
> >> the perl module for a perl script in /test/script.pl would always be
> >> /test and not the path to the script. So reading from ./WSDLs/*.wsdl
> >> would fail.
> >>
> >> Any ideas?
> >
> > (my $dir = $INC{'MyModule.pm'}) =~ s#/MyModule.pm$##;
> >
> > chdir $dir or die "could not cd to '$dir' $!";
>
> this cannot work and does not work.
It works for me. Did you actually try it?
> I asked how can the perl module find
> out where it has been loaded from, but your code does only work within
> the script that has loaded the module.
%INC is a global variable. It is available from any scope, including
the scope of modules. (And apparently it is updated before
the module is compiled, which I did have some initial concerns about.)
> But the perl module on its own
> needs to know the path it is stored.
A perl module *on its own* is just a text file. It can't "know" anything.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Thu, 06 Mar 2008 17:27:29 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: module needs to know its own path
Message-Id: <63akbiF26uj5bU7@mid.individual.net>
Marten Lehmann wrote:
>> (my $dir = $INC{'MyModule.pm'}) =~ s#/MyModule.pm$##;
>>
>> chdir $dir or die "could not cd to '$dir' $!";
>
> this cannot work and does not work.
You are wrong. It works.
Put the following code in your module and you will see it:
for my $key (sort keys %INC) {
print "$key => $INC{$key}\n";
}
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
Date: Thu, 06 Mar 2008 19:11:33 +0100
From: Marten Lehmann <lehmannmapson@cnm.de>
Subject: Re: module needs to know its own path
Message-Id: <63aqaqF26rf9vU1@mid.individual.net>
Hello,
> You are wrong. It works.
ok, it works as long as perl module and script are separate files. For
testing, I was putting both in one file and then it didn't work. But
thats not a problem as I was definetely plannung to separate both.
#!/usr/bin/perl
package Test;
use strict;
use Data::Dumper;
sub new {
my ($class) = @_;
my $self = {};
bless ($self, $class);
print Dumper(%INC);
return $self;
}
my $t = Test->new();
Regards
Marten
------------------------------
Date: Thu, 06 Mar 2008 19:21:53 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: module needs to know its own path
Message-Id: <63ar6iF26q351U1@mid.individual.net>
Marten Lehmann wrote:
> Frank Seitz wrote:
>> You are wrong. It works.
>
> ok, it works as long as perl module and script are separate files.
Aren't they always?
> For testing, I was putting both in one file and then it didn't work.
<snip>
> #!/usr/bin/perl
> package Test;
> use strict;
> use Data::Dumper;
>
> sub new {
> my ($class) = @_;
> my $self = {};
> bless ($self, $class);
>
> print Dumper(%INC);
>
> return $self;
> }
>
> my $t = Test->new();
Declaring a package in a script does not make that package a module.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 6 Mar 2008 12:20:39 -0800 (PST)
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: module needs to know its own path
Message-Id: <d0ec780a-8f0b-46fe-bdc9-953ed4e9d860@s19g2000prg.googlegroups.com>
On Mar 6, 10:11 am, Marten Lehmann <lehmannmap...@cnm.de> wrote:
> Hello,
>
> > You are wrong. It works.
>
> ok, it works as long as perl module and script are separate files. For
> testing, I was putting both in one file and then it didn't work. But
> thats not a problem as I was definetely plannung to separate both.
>
> #!/usr/bin/perl
> package Test;
> use strict;
> use Data::Dumper;
>
> sub new {
> my ($class) = @_;
> my $self = {};
> bless ($self, $class);
>
> print Dumper(%INC);
>
> return $self;
>
> }
>
> my $t = Test->new();
>
If you're trying to create a runnable module,
you can use caller() to get the invoking filename:
my( $pkg, $file, $line ) = caller;
See B.Foy's "modulino" for an example:
http://www252.pair.com/comdog/mastering_perl/Chapters/18.modulinos.html
--
Charles DeRykus
------------------------------
Date: Thu, 06 Mar 2008 21:28:39 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: module needs to know its own path
Message-Id: <otk0t3hmk117pnrvjmg7ec14udb00oeaba@4ax.com>
On Wed, 5 Mar 2008 19:29:01 -0600, Tad J McClellan
<tadmc@seesig.invalid> wrote:
> (my $dir = $INC{'MyModule.pm'}) =~ s#/MyModule.pm$##;
(my $dir = $INC{'MyModule.pm'}) =~ s#/MyModule\.pm$##;
^
^
(Just to be *very* fussy!)
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 6 Mar 2008 21:48:11 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: module needs to know its own path
Message-Id: <pan.2008.03.06.20.48.11@rtij.nl.invlalid>
On Thu, 06 Mar 2008 19:21:53 +0100, Gunnar Hjalmarsson wrote:
> Marten Lehmann wrote:
>> Frank Seitz wrote:
>>> You are wrong. It works.
>>
>> ok, it works as long as perl module and script are separate files.
>
> Aren't they always?
Oh, heavens no. Although problems like this indicate why it *is* a good
idea to separate them.
M4
------------------------------
Date: Thu, 6 Mar 2008 18:48:44 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Notes on unicode/utf8, CGI, DBI, mysql
Message-Id: <fqpaqe$19n6$1@ns.felk.cvut.cz>
kbin wrote:
> I've written a small tutorial/guide on some of the issues I've come
> across when trying to use unicode/utf8 in my LAMP stack and thought
> I'd share them.
>
> http://kbinstuff.googlepages.com/perl%2Cunicodeutf8%2Ccgi.pm%2Capache%2Cmod_perla
>
> I hope you will find it useful and please provide me with feedback.
>
Good idea to sumarize possible problems - good page.
I can mention only that you can use this too
my $dbh = DBI->connect( <parameters>);
$dbh->do( "SET NAMES utf8");
In other word is not needed to use UTF8DBI. On most webhosting servers user
cannot to install his/her own modules and this module is not installed. In
addition MySQL server (daemon) is running in default configuration (collate
Swedish, charset latin-1) :-)
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
------------------------------
Date: Thu, 06 Mar 2008 19:35:15 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Notes on unicode/utf8, CGI, DBI, mysql
Message-Id: <871w6n7lb0.fsf@zeekat.nl>
"Petr Vileta" <stoupa@practisoft.cz> writes:
> Good idea to sumarize possible problems - good page.
> I can mention only that you can use this too
>
> my $dbh = DBI->connect( <parameters>);
> $dbh->do( "SET NAMES utf8");
That by itself won't guarantee that your data will be correctly
handled. DBD::mysql provides the mysql_enable_utf8 option for a
reason. You do need at least DBD::mysql 4.004 for it to work more or
less correctly, though.
To the original poster: don't worry too much about the experimental
status of the option. It might some day go away (IMO not very likely,
though) but it's the best method today for getting reasonable unicode
behaviour out of DBD::mysql. At worst, you may have to remove the option
some time in the future, but the behaviour it enables is likely to stay.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Thu, 06 Mar 2008 19:49:14 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Notes on unicode/utf8, CGI, DBI, mysql
Message-Id: <87wsof6639.fsf@zeekat.nl>
kbin <kalle.bingel@gmail.com> writes:
> I've written a small tutorial/guide on some of the issues I've come
> across when trying to use unicode/utf8 in my LAMP stack and thought
> I'd share them.
>
> http://kbinstuff.googlepages.com/perl%2Cunicodeutf8%2Ccgi.pm%2Capache%2Cmod_perla
>
> I hope you will find it useful and please provide me with feedback.
Nice work. There are still some issues with straight DBD::mysql, even
using the lastest versions and using the enable_utf8 option. I've made
some remarks on that in reply to this post on perlmonks:
http://perlmonks.org/?node_id=620803
The most important bug/missing feature still outstanding is:
http://rt.cpan.org/Public/Bug/Display.html?id=25590
Basically, this means that data inserted into UTF8 columns *must* be
utf-8 encoded (note that you *must not* encode non-UTF8 column
data!). See the perlmonks link for more info.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: 06 Mar 2008 16:13:53 GMT
From: xhoster@gmail.com
Subject: Re: Perl functions
Message-Id: <20080306111354.491$NY@newsreader.com>
"Deepan - M.Sc(SE) - 03MW06" <deepan.17@gmail.com> wrote:
> Hi all,
> I am using a file abc.pl which is having a function called
> get().
>
> I am including this perl file inside a cgi script, and also i am
> calling this function inside this script.
What method are you using for doing the including? Shouldn't this be
abc.pm rather than abc.pl?
> Now this function residing
> inside the perl file abc.pl should now look into the URL of the
> calling CGI script
Why? Your CGI script is "in charge". Shouldn't it send abc.pl what it
needs, rather than expecting abc.pl to dig up what it needs on its own? It
seems that you are aiming for the worst of both worlds--you want code
scattered over multiple files, but without having modular designs that
makes the files loosely coupled.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Thu, 6 Mar 2008 18:30:24 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: regexp for s///
Message-Id: <fqp9o0$195n$1@ns.felk.cvut.cz>
I need to write regexp for s/// subtitution but I can't to thinkup it. Can
anybody help me?
I have string with possible 3 values:
$string = "A: aaa B: bbb";
or
$string = "A: aaa";
or
$string = "B: bbb";
Now I want to create 2 variables called $myA and $myB and want to store values
to both variables depend on found or not found A and B in $string.
$string = "A: aaa B: bbb";
$myA="aaa";
$myB="bbb";
or
$string = "A: aaa";
$myA='aaa';
$myB='';
or
$string = "B: bbb";
$myA='';
$myB='bbb';
Till now I use code bellow, but maybe can be writte as regexp.
if($string =~ m/A:\s+([^B]+)\s+B:\s+(.+)/) { $myA = $1; $myB = $2;}
elsif($string =~ m/A:\s+(.+)/) { $myA = $1; $myB = '';}
elseif($string =~ m/B:\s+(.+)/) { $myA = ''; $myB = $1;}
else {$myA = $myB = '';}
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail from
another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
------------------------------
Date: 6 Mar 2008 18:01:44 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: regexp for s///
Message-Id: <slrnft0cc9.46u.glennj@smeagol.ncf.ca>
At 2008-03-06 12:30PM, "Petr Vileta" wrote:
> I need to write regexp for s/// subtitution but I can't to thinkup it. Can
> anybody help me?
>
> I have string with possible 3 values:
>
> $string = "A: aaa B: bbb";
> or
> $string = "A: aaa";
> or
> $string = "B: bbb";
>
> Now I want to create 2 variables called $myA and $myB and want to
> store values to both variables depend on found or not found A and B
> in $string.
How about a hash?
my %my = $string =~ /([AB]): (\w+)/g;
That will be problematic depending what's on the right side of the
colon.
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: Thu, 06 Mar 2008 19:23:22 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: regexp for s///
Message-Id: <63ar4sF26uj5bU8@mid.individual.net>
Petr Vileta wrote:
>
> Till now I use code bellow, but maybe can be writte as regexp.
>
> if($string =~ m/A:\s+([^B]+)\s+B:\s+(.+)/) { $myA = $1; $myB = $2;}
> elsif($string =~ m/A:\s+(.+)/) { $myA = $1; $myB = '';}
> elseif($string =~ m/B:\s+(.+)/) { $myA = ''; $myB = $1;}
> else {$myA = $myB = '';}
my ($myA) = $string =~ /A: (aaa)/;
$myA //= '';
my ($myB) = $string =~ /B: (bbb)/;
$myB //= '';
(//= Perl 5.10)
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
Date: Thu, 06 Mar 2008 19:27:48 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: regexp for s///
Message-Id: <63ard5F26uj5bU10@mid.individual.net>
Petr Vileta wrote:
>
> Till now I use code bellow, but maybe can be writte as regexp.
>
> if($string =~ m/A:\s+([^B]+)\s+B:\s+(.+)/) { $myA = $1; $myB = $2;}
> elsif($string =~ m/A:\s+(.+)/) { $myA = $1; $myB = '';}
> elseif($string =~ m/B:\s+(.+)/) { $myA = ''; $myB = $1;}
> else {$myA = $myB = '';}
my ($myA) = $string =~ /A:\s+(\S+)/;
$myA //= '';
my ($myB) = $string =~ /B:\s+(\S+)/;
$myB //= '';
(//= Perl 5.10)
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
Date: 06 Mar 2008 19:02:06 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: regexp for s///
Message-Id: <slrnft0fte.q8.abigail@alexandra.abigail.be>
_
Petr Vileta (stoupa@practisoft.cz) wrote on VCCCI September MCMXCIII in
<URL:news:fqp9o0$195n$1@ns.felk.cvut.cz>:
][ I need to write regexp for s/// subtitution but I can't to thinkup it. Can
][ anybody help me?
Well, yeah. It seems you want to put something in $myA and $myB depending
on the content of $sting, without changing the latter. Why bother with s///?
][ I have string with possible 3 values:
Then why bother with a regexp?
][ $string = "A: aaa B: bbb";
][ or
][ $string = "A: aaa";
][ or
][ $string = "B: bbb";
][
][ Now I want to create 2 variables called $myA and $myB and want to store values
][ to both variables depend on found or not found A and B in $string.
][
][ $string = "A: aaa B: bbb";
][ $myA="aaa";
][ $myB="bbb";
][ or
][ $string = "A: aaa";
][ $myA='aaa';
][ $myB='';
][ or
][ $string = "B: bbb";
][ $myA='';
][ $myB='bbb';
][
][ Till now I use code bellow, but maybe can be writte as regexp.
The code below *USES* regexes. So, keep it if you want to have it using
a regexp.
][ if($string =~ m/A:\s+([^B]+)\s+B:\s+(.+)/) { $myA = $1; $myB = $2;}
][ elsif($string =~ m/A:\s+(.+)/) { $myA = $1; $myB = '';}
][ elseif($string =~ m/B:\s+(.+)/) { $myA = ''; $myB = $1;}
][ else {$myA = $myB = '';}
But I wouldn't use a regexp. I'd write (untested):
give ($string) {
when ("A: aaa B: bbb") {
$myA = "aaa";
$myB = "bbb";
}
when ("A: aaa") {
$myA = "aaa";
$myB = "";
}
when ("B: bbb") {
$myA = "";
$myB = "bbb";
}
}
And if I were to insist on using a regexp, I'd use (untested):
if ($string =~ /^(?:A: (?<a>aaa))? ?(?:B: (?<b>bbb))?$/) {
$myA = $+ {a} // "";
$myB = $+ {b} // "";
}
But I find the given/when much clearer.
Abigail
--
#!/opt/perl/bin/perl -w
$\ = $"; $; = $$; END {$: and print $:} $SIG {TERM} = sub {$ := $_}; kill 15 =>
fork and ($; == getppid and exit or wait) foreach qw /Just another Perl Hacker/
------------------------------
Date: Thu, 06 Mar 2008 20:09:12 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: regexp for s///
Message-Id: <IbYzj.64819$FO1.2282@edtnps82>
Petr Vileta wrote:
> I need to write regexp for s/// subtitution but I can't to thinkup it.
> Can anybody help me?
>
> I have string with possible 3 values:
>
> $string = "A: aaa B: bbb";
> or
> $string = "A: aaa";
> or
> $string = "B: bbb";
>
> Now I want to create 2 variables called $myA and $myB and want to store
> values to both variables depend on found or not found A and B in $string.
>
> $string = "A: aaa B: bbb";
> $myA="aaa";
> $myB="bbb";
> or
> $string = "A: aaa";
> $myA='aaa';
> $myB='';
> or
> $string = "B: bbb";
> $myA='';
> $myB='bbb';
>
> Till now I use code bellow, but maybe can be writte as regexp.
>
> if($string =~ m/A:\s+([^B]+)\s+B:\s+(.+)/) { $myA = $1; $myB = $2;}
> elsif($string =~ m/A:\s+(.+)/) { $myA = $1; $myB = '';}
> elseif($string =~ m/B:\s+(.+)/) { $myA = ''; $myB = $1;}
> else {$myA = $myB = '';}
$ perl -le'
for my $string ( "A: aaa B: bbb", "A: aaa", "B: bbb", "B: bbb A: aaa" ) {
my ( $myA, $myB ) = $string =~ /(?=.*A:\s*(\S+))?(?=.*B:\s*(\S+))?/;
print qq[\$string = "$string" \$myA = "$myA" \$myB = "$myB"];
}
'
$string = "A: aaa B: bbb" $myA = "aaa" $myB = "bbb"
$string = "A: aaa" $myA = "aaa" $myB = ""
$string = "B: bbb" $myA = "" $myB = "bbb"
$string = "B: bbb A: aaa" $myA = "aaa" $myB = "bbb"
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Thu, 6 Mar 2008 08:10:08 -0800 (PST)
From: fvdmarkt@gmail.com
Subject: scalar context for testing arguments
Message-Id: <6a211bb5-0909-447f-9196-d691c5e8eeb0@13g2000hsb.googlegroups.com>
Hi,
Is this the right way to test for existence of arguments?
if (@ARGV > 0) {
}
or should I use the index of the last argument?
if ($#ARGV >= 0) {
}
Who has a better suggestion?
------------------------------
Date: 06 Mar 2008 16:16:51 GMT
From: xhoster@gmail.com
Subject: Re: scalar context for testing arguments
Message-Id: <20080306111653.174$xx@newsreader.com>
fvdmarkt@gmail.com wrote:
> Hi,
>
> Is this the right way to test for existence of arguments?
>
> if (@ARGV > 0) {
> }
>
> or should I use the index of the last argument?
>
> if ($#ARGV >= 0) {
> }
>
> Who has a better suggestion?
I prefer:
if (@ARGV) {
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1338
***************************************