Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-14 Thread Owen
On Sat, 13 Dec 2003 18:12:17 +0100
Jerry Rocteur <[EMAIL PROTECTED]> wrote:

> I'm trying to be a good boy and use strict and warnings ..
> 
> The more I do, the more I feel I'm wasting so much time and should 
> become productive, my code looks full of 'my'


Because so many people in c.l.p.m said "use strict;" I decided to take the plunge and 
use it.

Until I worked out what was going on, I, like you, thought it was a waste of time.

That and warnings are a great pair in getting programs to run and I suppose "Use of 
unitialized..." is the most common warning. There is always a bit of pleasure in 
tracking down the reason for that one.

See http://perl.abigail.nl/Musings/coding_guidelines.html suggested perl coding 
practices
 
Hang on in there, it's worth it. 




-- 
Owen


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-14 Thread Bakken, Luke
> uninitialized value in 
> pattern match (m//) at ./getopt.pl line 14.'
 
Use the standard Getopt::Std module to process options. Don't do it
yourself.

> Line 14 is the while line..
> 
> I've tried all sorts of stuff with defined but keep getting syntax 
> errors. I've tried perldoc warnings and perldoc perllexwarn .. In any 
> case, unless I'm really missing something, I can't see what could be 
> problematic with the while statement below, of course this shows my 
> ignorance but as I've decided to use warnings and strict, I 
> want to do 
> it right..
> 
> How would a pedant code the following to avoid this warning.. Your 
> answers will help me in the future.
> 
> #if ($#ARGV >= 0) { # What I've tried
>  while ($_ = $ARGV[0], /^-/) {
>  shift;
>  last if /^--$/;
>  if (/^-d(.*)/) { $debug++ }
>  elsif (/^-v(.*)/) { $verbose++ }
>  else { print "$_ unknown option\n";
>  Usage;
>  }
>  }
> #}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-14 Thread Jerry Rocteur
On Saturday, Dec 13, 2003, at 18:12 Europe/Brussels, Jerry Rocteur 
wrote:

Hi,

I'm trying to be a good boy and use strict and warnings ..

The more I do, the more I feel I'm wasting so much time and should 
become productive, my code looks full of 'my', I could understand the 
requirement inside a sub routing but in the main code it gives me the 
willies. My DBI Perl is even more of a headache ;-((

Anyway, enough whining, now I've going through code that is working 
and thought I'd see the big difference if I change it to use warnings 
and strict and this little routing gives me  'Use of uninitialized 
value in pattern match (m//) at ./getopt.pl line 14.'

Line 14 is the while line..

I've tried all sorts of stuff with defined but keep getting syntax 
errors. I've tried perldoc warnings and perldoc perllexwarn .. In any 
case, unless I'm really missing something, I can't see what could be 
problematic with the while statement below, of course this shows my 
ignorance but as I've decided to use warnings and strict, I want to do 
it right..

How would a pedant code the following to avoid this warning.. Your 
answers will help me in the future.

#if ($#ARGV >= 0) { # What I've tried
while ($_ = $ARGV[0], /^-/) {
shift;
last if /^--$/;
if (/^-d(.*)/) { $debug++ }
elsif (/^-v(.*)/) { $verbose++ }
else { print "$_ unknown option\n";
Usage;
}
}
#}
Thanks in advance, I really want to put, Perl with warnings and strict 
in my CV ;-

Jerry




Sorry for the double post, my first post I had done with an email 
address that is not subscribed to the list, thinking it would not go 
through I reposted. I didn't realize you accepted posts from non 
subscribed addresses.

I thank all those that replied on and off list, great replies. Of 
course my question was more than answered.  Thanks to Wigins d'Anconia, 
Rob Dixon, R. Joseph Newton and drieux! Food for thought.  I'm still 
reviewing your replies..

Best Regards,

Jerry Rocteur

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-14 Thread Jerry Rocteur
Hi,

I'm trying to be a good boy and use strict and warnings ..

The more I do, the more I feel I'm wasting so much time and should 
become productive, my code looks full of 'my', I could understand the 
requirement inside a sub routing but in the main code it gives me the 
willies. My DBI Perl is even more of a headache ;-((

Anyway, enough whining, now I've going through code that is working and 
thought I'd see the big difference if I change it to use warnings and 
strict and this little routing gives me  'Use of uninitialized value in 
pattern match (m//) at ./getopt.pl line 14.'

Line 14 is the while line..

I've tried all sorts of stuff with defined but keep getting syntax 
errors. I've tried perldoc warnings and perldoc perllexwarn .. In any 
case, unless I'm really missing something, I can't see what could be 
problematic with the while statement below, of course this shows my 
ignorance but as I've decided to use warnings and strict, I want to do 
it right..

How would a pedant code the following to avoid this warning.. Your 
answers will help me in the future.

#if ($#ARGV >= 0) { # What I've tried
while ($_ = $ARGV[0], /^-/) {
shift;
last if /^--$/;
if (/^-d(.*)/) { $debug++ }
elsif (/^-v(.*)/) { $verbose++ }
else { print "$_ unknown option\n";
Usage;
}
}
#}
Thanks in advance, I really want to put, Perl with warnings and strict 
in my CV ;-

Jerry

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-13 Thread drieux
On Dec 13, 2003, at 10:01 AM, Wiggins d'Anconia wrote:
[..
A decent template, any gurus have improvements?
[..]

my stock gag, looks like:

my $opt = parse_cmd_line_options();
...
#---
# These are the Subs for the parse_cmd_line_options.
#---
# The Usage Command so that we can use a common interface to
# handle both the cases where we want to show some basic detailed
# information with a '--help' query, as well as to exit out of
# the parse_cmd_line_options wrapper for Getopt::Long if we have
# problems with user generated commands.
#---
sub Usage
{
my($msg, $retval, @list) = @_;
print "$msg\n" if ($msg);

print "Usage: $0 [-i|-x|-c|--kadb] [-f ] [-d 
]\n";
if ( @list ) {
print "  the full optins list is:\n";
print "\t$_\n" foreach (@list);
}
exit($retval);
}

#
# where we wrap the Getopt::Long and resolve which arguments
# work and play well with other command line arguments.
#
# 
$ref->{'delete'} = [];
#
# more editorializing
#
$ref->{'add'} = [] ;
#
# this also doubles as the flash guide. in Usage
#
my @list = qw/
file|f=s
import|init|i
installdb
export|x|e
compact|c
delete|d=s
add|a=s
fsck
nup
kadb
help|h|?/;
   my @config_args = qw/bundling/;
Getopt::Long::Configure(@config_args);
my $results = GetOptions($ref, @list) ;

Usage('Problem with Input Arguments',1,@list) unless ($results);

Usage('The General Help',0,@list) if ($ref->{'help'});

#
# now to create the action station section
#
#sort out other gory details about the which arguments
#should or should not be dealt with
$ref ;

} # end of parse_cmd_line_options

This dog has soldiered on in one variant or another...

vladimir: 41:] ./db_tool.plx --kadb
option: help
we have the following options:
add  [sysname config_host] -> add sysname and config_host to db
delete [sysname ]  -> delete sysname from db
show_sysnames  -> list current sysnames in db
config_host-> get config_host for sysname in db
export -> export db to file
import -> import file to db
q|exit|quit-> exit kadb
option: q
exiting
vladimir: 42:]
the '--kadb' started out as a bad JOKE, I whined at
myMostGloriousLeader that just for him, I would offer
up a 'kryptic command line interface with short and
arcane syntax, you know, just like kadb' IT
HURTS when one stops laughing and has to implement
it in a rush because, well, one just needs it down and dirty,
but it has to work...
I went with the 'bundling' approach so that the
'oldGuy' *nix freaks would be 'happy' while the
gnuSters would be able to wander the plains with
their --help and the like...
ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-13 Thread R. Joseph Newton
Wiggins d'Anconia wrote:

> More code showing specifically why I have been rambling about $_ in the
> last couple of days.  If you are going to shift off the argument list
> why not just do it in the while loop when you are setting $_?

Thanks, Wiggins, and keep on rambling.  The point needs reiteration.  Aside from
the needle-in-a-haystack problems, I'd say that it's a good rule of thumb:

If you have to specifically assign $_, don't bother.  Perl already assigns it in
the contexts in which it is appropriate

> And Perl
> is very nice and lets you leave the semi-colons off in the above, to me
> it is a bad style to get into and will likely lead to errors later when
> you (or someone else) decides to add additional statements to those
> blocks.  While you are a beginner code *exactly* what you mean, use lots
> of names, avoid the shortcuts, later when you don't need to ask these
> kinds of questions, then sign up for a golf tournament...

Yes and yes.

>
>
> > #}
> >
> > Thanks in advance, I really want to put, Perl with warnings and strict
> > in my CV ;-
> >
>
> I have wondered about this for a while, putting that you use warnings
> and strict into a CV is a tough choice, to me I wouldn't likely talk to
> a candidate unless they used them, but I am not sure I would put them on
> a CV because to an advanced person it would seem overally obvious.
> Though I think it is something good to bring up in an interview, and I
> have had several interviewers ask about them... what does the group
> think (about including it in a CV)? (Obviously I know what the thoughts
> are about including them in the code)And naturally code samples
> would reflect their use.
>

I think about the only place it would be appropriate is in notes describing
coding samples available for interview or included.  If sufficiently understated,
it may reassure an interviewer or screener that they are not wasting time:

Codes samples included  [all compiled using strict compilation option and
pre-tested]

Which at least indicates to the reader that they are looking at something which
has run successfully.  Definitely not something to wave a big flag over,
though--it would be like listing:
Have mastered ABCs
...at the top of a resume for an English professorship.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-13 Thread Rob Dixon
Jerry Rocteur wrote:
>
> I'm trying to be a good boy and use strict and warnings ..

Well done!

> The more I do, the more I feel I'm wasting so much time and should
> become productive, my code looks full of 'my', I could understand the
> requirement inside a sub routing but in the main code it gives me the
> willies. My DBI Perl is even more of a headache ;-((

Your problem is more than likely because you're expecting Perl to be
like another language. The usual ones are C and shell script. Perl's
syntax is often quite like C's, and the built-in functions are a fair
match, but unless you're used to declaring variables locally to their
scope of use as in C++ you will end up with a long preamble declaring
everything, which can be less than useful.

> Anyway, enough whining, now I've going through code that is working and
> thought I'd see the big difference if I change it to use warnings and
> strict and this little routing gives me  'Use of uninitialized value in
> pattern match (m//) at ./getopt.pl line 14.'
>
> Line 14 is the while line..

'use warnings' will moan at you if a variable's value is 'undefined'.
It's left this way straight after either

  my $var

or

  $var = undef

If you define stuff like:

  my $var = 0

then you won't get this problem. But don't go around initialising
all variables in their declarations. It's just a warning and is useful
as such, and anyway Perl will let you concatenate or increment an
undefined value. i.e.

  my $var;

followed by
  $var++;
or
  $var .= '>>'

will work fine without any warnings.

> I've tried all sorts of stuff with defined but keep getting syntax
> errors. I've tried perldoc warnings and perldoc perllexwarn .. In any
> case, unless I'm really missing something, I can't see what could be
> problematic with the while statement below, of course this shows my
> ignorance but as I've decided to use warnings and strict, I want to do
> it right..
>
> How would a pedant code the following to avoid this warning.. Your
> answers will help me in the future.

You need to get to understand Perl idioms. I've started by reducing your
indents from 8 chars to 2 because that makes it more visible for me.

> if ($#ARGV >= 0) {

This says 'if the index of the last array element is zero or more'.
You don't mean that, because an array with a single element will
have a last element with an index of zero. Try

  if (@ARGV) {
:
  }

>   while ($_ = $ARGV[0], /^-/) {
>
> shift;

OK, these lines together pull the next argument from @ARGV and
quit the loop unless it begins with a hyphen. The reason you're
getting a warning is that once your 'shift' statement below has
finally emptied the array, $_ = $ARGV[0] will set $_ to 'undef'
so the pattern match is comparing against an undefined value.

This does the same:

  foreach (@ARGV) {

last unless /^-/;

except that the parameters are left in @ARGV instead of being
shifted off, and the loop is executed just once for each
element of @ARGV.

> last if /^--$/;

Break out if the element is just two hyphens. That's fine.

> if (/^-d(.*)/) {
>   $debug++
> }

Again, that'll do. But unless you need to capture whatever follows
the '-d' then you want just

 if (/^-d/) {
   $debug++
 }

> elsif (/^-v(.*)/) {
>   $verbose++
> }

Same here:

  elsif (/^-v/) {
$verbose++
  }

> else {
>   print "$_ unknown option\n";
>   Usage;
> }
>   }
> }

And the rest's OK. But I'd write it something like this. (Actually I would
probably never write this, but my code depends on the context of the
code and what exactly you need to do with the results :)

  foreach (@ARGV) {

next unless /^-/;

last if $_ eq '--';

if ( /^-(d|v)/ ) {
  $debug++ if $1 eq 'd';
  $verbose++ if $1 eq 'v';
}
else {
  print "$_ unknown option\n";
  Usage;
}
  }

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-13 Thread Wiggins d'Anconia
Jerry Rocteur wrote:
Hi,

I'm trying to be a good boy and use strict and warnings ..

The more I do, the more I feel I'm wasting so much time and should 
become productive, my code looks full of 'my', I could understand the 
requirement inside a sub routing but in the main code it gives me the 
willies. My DBI Perl is even more of a headache ;-((

Right now you probably are.  In the future the loads of time it saves 
will repay you greatly.  Stick with it, it will help... this comes from 
someone that switched "cold turkey" from not using them to using them 
after coding in Perl for 3+ years...

Anyway, enough whining, now I've going through code that is working and 
thought I'd see the big difference if I change it to use warnings and 
strict and this little routing gives me  'Use of uninitialized value in 
pattern match (m//) at ./getopt.pl line 14.'

The above is just a warning so your code is running, granted it doesn't 
do much...

Line 14 is the while line..

I've tried all sorts of stuff with defined but keep getting syntax 
errors. I've tried perldoc warnings and perldoc perllexwarn .. In any 
case, unless I'm really missing something, I can't see what could be 
problematic with the while statement below, of course this shows my 
ignorance but as I've decided to use warnings and strict, I want to do 
it right..

How would a pedant code the following to avoid this warning.. Your 
answers will help me in the future.

They wouldn't. They would use Getopt::Std or Getopt::Long...

perldoc Getopt::Std
perldoc Getopt::Long
Now

#if ($#ARGV >= 0) { # What I've tried
To test if an array has length simply take it in scalar context,

if (@ARGV) {

while ($_ = $ARGV[0], /^-/) {
I believe the issue is that the $_ is not set by the time you hit the 
pattern match, there is probably a way to make it, but to me it is 
simpler to just add a line after the initial test such as:

next unless (/^-/);

Inside the loop and drop the test inside the conditional.

shift;
last if /^--$/;
if (/^-d(.*)/) { $debug++ }
elsif (/^-v(.*)/) { $verbose++ }
I assume that $debug and $verbose have been pre-declared and that you 
have Usage prototyped or something, as it is a bare word...

else { print "$_ unknown option\n";
Usage;
}
}
More code showing specifically why I have been rambling about $_ in the 
last couple of days.  If you are going to shift off the argument list 
why not just do it in the while loop when you are setting $_?  And Perl 
is very nice and lets you leave the semi-colons off in the above, to me 
it is a bad style to get into and will likely lead to errors later when 
you (or someone else) decides to add additional statements to those 
blocks.  While you are a beginner code *exactly* what you mean, use lots 
of names, avoid the shortcuts, later when you don't need to ask these 
kinds of questions, then sign up for a golf tournament...

#}

Thanks in advance, I really want to put, Perl with warnings and strict 
in my CV ;-

I have wondered about this for a while, putting that you use warnings 
and strict into a CV is a tough choice, to me I wouldn't likely talk to 
a candidate unless they used them, but I am not sure I would put them on 
a CV because to an advanced person it would seem overally obvious. 
Though I think it is something good to bring up in an interview, and I 
have had several interviewers ask about them... what does the group 
think (about including it in a CV)? (Obviously I know what the thoughts 
are about including them in the code)And naturally code samples 
would reflect their use.

I would also check out:

perldoc Pod::Usage

http://danconia.org

A decent template, any gurus have improvements?

UNTESTED---

#!/usr/local/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
pod2usage("No options specified\n") unless (@ARGV);



# configure GetOptions with some standard gnu options
my $opt_parser = new Getopt::Long::Parser ('config' => 
['gnu_compat','bundling','permute','no_getopt_compat'] );

# init configuration
my $cmdopts = {};
# get configuration
$opt_parser->getoptions($cmdopts,
'help|h',
'debug|d',
'verbose|v',
) or pod2usage(2);
# print the help message if they asked just for it
pod2usage(1) if (defined($cmdopts->{'help'}));
if ($cmdopts->{'verbose'}) {
print "Verbose Mode\n";
}
if ($cmdopts->{'debug'}) {
print "Debugging Mode\n";
}


#
__END__
=head1 NAME

getopt - A program

Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-13 Thread Jerry Rocteur
Hi,

I'm trying to be a good boy and use strict and warnings ..

The more I do, the more I feel I'm wasting so much time and should 
become productive, my code looks full of 'my', I could understand the 
requirement inside a sub routing but in the main code it gives me the 
willies. My DBI Perl is even more of a headache ;-((

Anyway, enough whining, now I've going through code that is working and 
thought I'd see the big difference if I change it to use warnings and 
strict and this little routing gives me  'Use of uninitialized value in 
pattern match (m//) at ./getopt.pl line 14.'

Line 14 is the while line..

I've tried all sorts of stuff with defined but keep getting syntax 
errors. I've tried perldoc warnings and perldoc perllexwarn .. In any 
case, unless I'm really missing something, I can't see what could be 
problematic with the while statement below, of course this shows my 
ignorance but as I've decided to use warnings and strict, I want to do 
it right..

How would a pedant code the following to avoid this warning.. Your 
answers will help me in the future.

#if ($#ARGV >= 0) { # What I've tried
while ($_ = $ARGV[0], /^-/) {
shift;
last if /^--$/;
if (/^-d(.*)/) { $debug++ }
elsif (/^-v(.*)/) { $verbose++ }
else { print "$_ unknown option\n";
Usage;
}
}
#}
Thanks in advance, I really want to put, Perl with warnings and strict 
in my CV ;-

Jerry

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Use of uninitialized value in pattern match (m//) at ...

2003-06-26 Thread Singing Banzo
Perfect! It works great. Thank you very much!

Thanks Steve also, but I WANT warnings and all errors I can get as early as
posible!  =)

Regards,
SB.
- Original Message - 
From: "John W. Krahn" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 26, 2003 6:29 PM
Subject: Re: Use of uninitialized value in pattern match (m//) at ...


> Singing Banzo wrote:
> >
> > I think this is a very basic warning, but I coudn't find the way to
avoid it
> > (tried google, faq, and archive):
> >
> > Use of uninitialized value in pattern match (m//) at poComen.cgi line
138.
> >
> > line 138:
> > if ($q->param('template') =~ /^[1234]$/) {  # trying to find out if the
> > value of a form parameter is a digit between 1 and 4
>
> The warning means that the value of $q->param('template') is undef.
>
>
> > This only happens with "use strict".
> >
> > How can I get rid of it?
>
> if ( defined $q->param('template') and $q->param('template') =~
/^[1234]$/ ) {
>
>
> John
> -- 
> use Perl;
> program
> fulfillment
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>

- Original Message - 
From: "Steve Grazzini" <[EMAIL PROTECTED]>
To: "Singing Banzo" <[EMAIL PROTECTED]>
Sent: Thursday, June 26, 2003 6:06 PM
Subject: Re: Use of uninitialized value in pattern match (m//) at ...


> On Thu, Jun 26, 2003 at 04:28:49PM -0300, Singing Banzo wrote:
> >
> > Use of uninitialized value in pattern match (m//) at poComen.cgi line
138.
> >
> > line 138:
> > if ($q->param('template') =~ /^[1234]$/) {
> >
> > This only happens with "use strict".
>
> Are you sure?  :-)
>
> It would make more sense if it only happened with "use warnings".
>
> > How can I get rid of it?
>
> You could make sure $q->param('template') is defined before using
> it in the pattern-match.
>
> OTOH, if you don't care whether it's defined (and I think it's safe
> to say that you don't care *here* whether it's defined) then you can
> locally turn off the "uninitialized" warnings:
>
> {
> no warnings 'uninitialized';
> if ($q->param('template') =~ /$pattern/) {
> ...
> }
> }
>
> -- 
> Steve
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Use of uninitialized value in pattern match (m//) at ...

2003-06-26 Thread John W. Krahn
Singing Banzo wrote:
> 
> I think this is a very basic warning, but I coudn't find the way to avoid it
> (tried google, faq, and archive):
> 
> Use of uninitialized value in pattern match (m//) at poComen.cgi line 138.
> 
> line 138:
> if ($q->param('template') =~ /^[1234]$/) {  # trying to find out if the
> value of a form parameter is a digit between 1 and 4

The warning means that the value of $q->param('template') is undef.


> This only happens with "use strict".
> 
> How can I get rid of it?

if ( defined $q->param('template') and $q->param('template') =~ /^[1234]$/ ) {


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Use of uninitialized value in pattern match (m//) at ...

2003-06-26 Thread Singing Banzo
I think this is a very basic warning, but I coudn't find the way to avoid it
(tried google, faq, and archive):

Use of uninitialized value in pattern match (m//) at poComen.cgi line 138.

line 138:
if ($q->param('template') =~ /^[1234]$/) {  # trying to find out if the
value of a form parameter is a digit between 1 and 4

This only happens with "use strict".

How can I get rid of it?

Thanks in advance.

Regards,
SB.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-03 Thread Paul Johnson
On Mon, Feb 03, 2003 at 11:08:37AM -, Rob Dixon wrote:
> Paul Johnson wrote:
> > But 5.10 will (probably) introducde the // operator which will allow
> > you to say:
> >
> >   $var //= 10;
> 
> Where do you get this insider information Paul?

Keeping up with development :-)

> And what's this operator
> going to do? Presumably there's an operator $c = $a // $b as well. I'm
> surprised if it's just (defined $a ? $a : $b).

This from the version of perlop in bleadperl (the current development
sources):

Although it has no direct equivalent in C, Perl's "//" operator is
related to its C-style or. In fact, it's exactly the same as "||",
except that it tests the left hand side's definedness instead of its
truth. Thus, "$a // $b" is similar to "defined($a) || $b" (except that
it returns the value of $a rather than the value of "defined($a)") and
is exactly equivalent to "defined($a) ? $a : $b". This is very useful
for providing default values for variables. If you actually want to test
if at least one of $a and $b is defined, use "defined($a // $b)".

The "||", "//" and "&&" operators differ from C's in that, rather than
returning 0 or 1, they return the last value evaluated. Thus, a
reasonably portable way to find out the home directory might be:

$home = $ENV{'HOME'} // $ENV{'LOGDIR'} //
(getpwuid($<))[7] // die "You're homeless!\n";

> Interested, of Tunbridge Wells.

Dear Points of View,

The testcard - another winner!

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-03 Thread Rob Dixon
Paul Johnson wrote:
> It probably sits better with something like:
>
>   $var = 10 unless defined $var;
>
> But 5.10 will (probably) introducde the // operator which will allow
> you to say:
>
>   $var //= 10;

Where do you get this insider information Paul? And what's this operator
going to do? Presumably there's an operator $c = $a // $b as well. I'm
surprised if it's just (defined $a ? $a : $b).

Interested, of Tunbridge Wells.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-02 Thread Paul Johnson
On Mon, Feb 03, 2003 at 11:57:29AM +1100, simran wrote:
> On Mon, 2003-02-03 at 09:37, Rob Dixon wrote:
> > "John W. Krahn" <[EMAIL PROTECTED]> wrote in message
> > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > > [EMAIL PROTECTED] wrote:
> > > >
> > > > $var|=10; # like that if u want to set the variable to a default
> > value--
> > > >   # if the $var is not defined it assigns a value of 10  to
> > it.
> > >
> > > You need to use the ||= operator not the |= operator for that.
> > 
> > ... and it will change $var to ten if it is already set to zero.
>
> perhaps such a statement would suit:
> 
> $var = defined $var ? $var : 10;

It probably sits better with something like:

  $var = 10 unless defined $var;

But 5.10 will (probably) introducde the // operator which will allow you
to say:

  $var //= 10;

just like Perl 6 (will).

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-02 Thread simran
perhaps such a statement would suit:

$var = defined $var ? $var : 10;


On Mon, 2003-02-03 at 09:37, Rob Dixon wrote:
> "John W. Krahn" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > [EMAIL PROTECTED] wrote:
> > >
> > > $var|=10; # like that if u want to set the variable to a default
> value--
> > >   # if the $var is not defined it assigns a value of 10  to
> it.
> >
> > You need to use the ||= operator not the |= operator for that.
> 
> ... and it will change $var to ten if it is already set to zero.
> 
> Rob
> 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-02 Thread Rob Dixon

"John W. Krahn" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> [EMAIL PROTECTED] wrote:
> >
> > $var|=10; # like that if u want to set the variable to a default
value--
> >   # if the $var is not defined it assigns a value of 10  to
it.
>
> You need to use the ||= operator not the |= operator for that.

... and it will change $var to ten if it is already set to zero.

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-02 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
> 
> $var|=10; # like that if u want to set the variable to a default value--
>   # if the $var is not defined it assigns a value of 10  to it.

You need to use the ||= operator not the |= operator for that.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-02 Thread km

hi,
u can do :

$var|=10; # like that if u want to set the variable to a default value--
  # if the $var is not defined it assigns a value of 10  to it.
KM

--
On Sat, 1 Feb 2003, Rob Dixon wrote:

> Chad Kellerman wrote:
> > Hi guys,
> >
> >How can I get around this "warning"
> >
> > Use of uninitialized value in pattern match (m//) at test.pl line 85.
> >
> > For some reason I always get driveNum=2.
> >
> > I am using warinig and strict in my code..
> >
> [snip code]
> >
> > >>>>Line 86 below<<<<
>
> I presume you mean line 85?
>
> >  if (defined $out =~ /\/home2/ ) {
>
> I'm not sure what you mean here. It's wrong anyway! This
> expression means:
>
> defined ($out =~ m[/home2]);
>
> which is the same as:
>
> defined (1) # if the match succeeds
> or
> defined (0) # if it doesn't
>
> Either way, both 1 and 0 are defined and the
> entire expression is true. Perhaps what you
> wanted was:
>
> if ( defined $out and $out =~ m[/home] )
>
> >  my $driveNum = "2";
> >  #MysqlIt($server,$driveNum,%mslRef);
> >  TestIt($server,$driveNum,%mslRef);
> >  }else{
> >  my $driveNum = "1";
> >  #MysqlIt($server,$driveNum,%mslRef);
> >  TestIt($server,$driveNum,%mslRef);
> >  }
> >
> > If /home2 is not returned from the ssh commnd I get the warning
>
> HTH,
>
> Rob
>
>
>
>
>
>

-- 






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-01 Thread R. Joseph Newton
chad kellerman wrote:

> Hi guys,
>
>How can I get around this "warning"
>
> Use of uninitialized value in pattern match (m//) at test.pl line 85.

Hi Chad,

Please send your code again with line 85 marked.  You have that information in front 
of you, while we are at a disadvantage.

Thanks,

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-01 Thread Rob Dixon
Chad Kellerman wrote:
> Hi guys,
>
>How can I get around this "warning"
>
> Use of uninitialized value in pattern match (m//) at test.pl line 85.
>
> For some reason I always get driveNum=2.
>
> I am using warinig and strict in my code..
>
[snip code]
>
> >>>>Line 86 below<<<<

I presume you mean line 85?

>  if (defined $out =~ /\/home2/ ) {

I'm not sure what you mean here. It's wrong anyway! This
expression means:

defined ($out =~ m[/home2]);

which is the same as:

defined (1) # if the match succeeds
or
defined (0) # if it doesn't

Either way, both 1 and 0 are defined and the
entire expression is true. Perhaps what you
wanted was:

if ( defined $out and $out =~ m[/home] )

>  my $driveNum = "2";
>  #MysqlIt($server,$driveNum,%mslRef);
>  TestIt($server,$driveNum,%mslRef);
>  }else{
>  my $driveNum = "1";
>  #MysqlIt($server,$driveNum,%mslRef);
>  TestIt($server,$driveNum,%mslRef);
>  }
>
> If /home2 is not returned from the ssh commnd I get the warning

HTH,

Rob





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-01 Thread NYIMI Jose (BMB)


> -Original Message-
> From: chad kellerman [mailto:[EMAIL PROTECTED]] 
> Sent: Saturday, February 01, 2003 6:38 PM
> To: [EMAIL PROTECTED]
> Subject: Use of uninitialized value in pattern match (m//) at 
> test.pl line 85.
> 
> 
> Hi guys,
> 
>How can I get around this "warning"
> 
> Use of uninitialized value in pattern match (m//) at test.pl line 85.
> 
> For some reason I always get driveNum=2.
> 
> I am using warinig and strict in my code..
> 
> 
> 
> if ($pong->ping($mslRef{$server}{ip})) {
> 
>   #check for 2 drives
> my $cmd = "grep /home2 /etc/fstab|awk \'{print \$2}\'";
> 
>   my ($out, $err, $exit);
>   eval {
>  my $ssh = 
> Net::SSH::Perl->new($mslRef{$server}{ip},identity_files=>["/ro
> ot/.ssh/identity"]);
> $ssh->login("$user");
>  ($out, $err, $exit) = $ssh->cmd($cmd); 
> };
> if ($@) {
> LogIt("Error from eval in Net::SSH::Perl\-> 
> $@:$mslRef{$server}{hostname}:$mslRef{$server}{ip}");
> }elsif ($err) {
>   LogIt("Error in command sent thru Net::SSH::Perl\-> 
> $err:$mslRef{$server}{hostname}:$mslRef{$server}{ip}");
>   }
> >>>>Line 86 below<<<<

However, my opinion is that "temporarily turn off warnings"
is not a good programming practice.
You should may be make an other check on $out, before matching :

if(!defined $out){
#do
}
elsif($out =~/\/home2/){
#do
}
else{
#do
}

But, this is just an idea.
Somebody has probably a best solution ...

HTH,

José.

>   if (defined $out =~ /\/home2/ ) {
>   my $driveNum = "2";
>   #MysqlIt($server,$driveNum,%mslRef);
>   TestIt($server,$driveNum,%mslRef);
>   }else{
>   my $driveNum = "1";
>   #MysqlIt($server,$driveNum,%mslRef);
>   TestIt($server,$driveNum,%mslRef);
>   }
> 
> 
> 
> If /home2 is not returned from the ssh commnd I get the warning
> 
> thanks in advance for the help.
> 
> chad
> -- 
> chad kellerman <[EMAIL PROTECTED]>
> 


 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-01 Thread NYIMI Jose (BMB)
C:\WINNT>perldoc -q warnings
Found in C:\Perl\lib\pod\perlfaq7.pod
  How do I temporarily block warnings?

If you are running Perl 5.6.0 or better, the "use warnings"
pragma allows fine control of what warning are produced. See the
perllexwarn manpage for more details.

{
no warnings;  # temporarily turn off warnings
$a = $b + $c; # I know these might be undef
}

If you have an older version of Perl, the "$^W" variable
(documented in the perlvar manpage) controls runtime warnings
for a block:

{
local $^W = 0;# temporarily turn off warnings
$a = $b + $c; # I know these might be undef
}

Note that like all the punctuation variables, you cannot
currently use my() on "$^W", only local().


HTH,

José.

> -Original Message-
> From: chad kellerman [mailto:[EMAIL PROTECTED]] 
> Sent: Saturday, February 01, 2003 6:38 PM
> To: [EMAIL PROTECTED]
> Subject: Use of uninitialized value in pattern match (m//) at 
> test.pl line 85.
> 
> 
> Hi guys,
> 
>How can I get around this "warning"
> 
> Use of uninitialized value in pattern match (m//) at test.pl line 85.
> 
> For some reason I always get driveNum=2.
> 
> I am using warinig and strict in my code..
> 
> 
> 
> if ($pong->ping($mslRef{$server}{ip})) {
> 
>   #check for 2 drives
> my $cmd = "grep /home2 /etc/fstab|awk \'{print \$2}\'";
> 
>   my ($out, $err, $exit);
>   eval {
>  my $ssh = 
> Net::SSH::Perl->new($mslRef{$server}{ip},identity_files=>["/ro
> ot/.ssh/identity"]);
> $ssh->login("$user");
>  ($out, $err, $exit) = $ssh->cmd($cmd); 
> };
> if ($@) {
> LogIt("Error from eval in Net::SSH::Perl\-> 
> $@:$mslRef{$server}{hostname}:$mslRef{$server}{ip}");
> }elsif ($err) {
>   LogIt("Error in command sent thru Net::SSH::Perl\-> 
> $err:$mslRef{$server}{hostname}:$mslRef{$server}{ip}");
>   }
> >>>>Line 86 below<<<<
>   if (defined $out =~ /\/home2/ ) {
>   my $driveNum = "2";
>   #MysqlIt($server,$driveNum,%mslRef);
>   TestIt($server,$driveNum,%mslRef);
>   }else{
>   my $driveNum = "1";
>   #MysqlIt($server,$driveNum,%mslRef);
>   TestIt($server,$driveNum,%mslRef);
>   }
> 
> 
> 
> If /home2 is not returned from the ssh commnd I get the warning
> 
> thanks in advance for the help.
> 
> chad
> -- 
> chad kellerman <[EMAIL PROTECTED]>
> 


 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Use of uninitialized value in pattern match (m//) at test.pl line 85.

2003-02-01 Thread chad kellerman
Hi guys,

   How can I get around this "warning"

Use of uninitialized value in pattern match (m//) at test.pl line 85.

For some reason I always get driveNum=2.

I am using warinig and strict in my code..



if ($pong->ping($mslRef{$server}{ip})) {

#check for 2 drives
my $cmd = "grep /home2 /etc/fstab|awk \'{print \$2}\'";

my ($out, $err, $exit);
eval {
 my $ssh =
Net::SSH::Perl->new($mslRef{$server}{ip},identity_files=>["/root/.ssh/identity"]);
$ssh->login("$user");
 ($out, $err, $exit) = $ssh->cmd($cmd); 
};
if ($@) {
LogIt("Error from eval in Net::SSH::Perl\->
$@:$mslRef{$server}{hostname}:$mslRef{$server}{ip}");
}elsif ($err) {
LogIt("Error in command sent thru Net::SSH::Perl\->
$err:$mslRef{$server}{hostname}:$mslRef{$server}{ip}");
}
>>>>Line 86 below<<<<
if (defined $out =~ /\/home2/ ) {
my $driveNum = "2";
#MysqlIt($server,$driveNum,%mslRef);
TestIt($server,$driveNum,%mslRef);
}else{
my $driveNum = "1";
#MysqlIt($server,$driveNum,%mslRef);
TestIt($server,$driveNum,%mslRef);
}



If /home2 is not returned from the ssh commnd I get the warning

thanks in advance for the help.

chad
-- 
chad kellerman <[EMAIL PROTECTED]>



signature.asc
Description: This is a digitally signed message part