Re: unit messages

2007-05-01 Thread oryann9

 #!/usr/bin/perl
 
 use strict;
 use warnings;
 
 my @a = qw(abc def ghi);
 
 for my $s (@a) {
 $s =~ /(b)|(e)|(h)/;
 print 1 = [$1] 2 = [$2] 3 = [$3]\n;
 }
 

Thank you for the kind replies. I understand now and
have modified the code to:

use strict;
use warnings;

my $jfsFile =
qq(/home/dbsmith/onlinJFS_4_license_exp.txt);
my $CvsFile =
qq(/home/dbsmith/onlinJFS_4_license_exp.cvs);
my $regexp  = qr/(host:\w+)/is;
my $regexp1 = qr/(onlinejfs.*)/is;
my $regexp2 = qr/(jfs\sversion.*)/is;

open (JFS, +$jfsFile) or die file '$jfsFile' was
not opened $!;

while (JFS) {
s/^\s+|\s+$//g; ## rid of newlines at
begin and end
next if ! length $_;## skip line of length
undef

if (/$regexp/) {
print \n$1\n,
'-' x length $1;
}
elsif (/$regexp1/) {
print \n\t$1\n;
}
elsif (/$regexp2/) {
print \n\t$1\n;
}
}



__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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




Re: unit messages

2007-05-01 Thread Chas Owens

On 5/1/07, oryann9 [EMAIL PROTECTED] wrote:
snip

my $regexp  = qr/(host:\w+)/is;
my $regexp1 = qr/(onlinejfs.*)/is;
my $regexp2 = qr/(jfs\sversion.*)/is;

snip

Why are you creating these regexes so far from where they are used?
If you are going to do this at least give them meaningful names.

snip

open (JFS, +$jfsFile) or die file '$jfsFile' was not opened $!;

snip

use the three argument version of open, if you don't you will
eventually be bitten by a file name that contains information that
open thinks is part of the mode:

open JFS, +, $jfsFile or die file '$jfsFile' was not opened $!;

Also, you may consider using lexical varaibles instead of bareword file handles:

open my $jfs, , $jfsFile or die file '$jfsFile' was not opened $!;
while ($jfs) {

The benefit is $jfs is much easier to pass around (well, there are
others as well like auto-closing when the variable goes out of scope).

snip

next if ! length $_;## skip line of length

snip

it is easy to misread if ! so use unless instead.  Also length works
on $_ if no argument is passed to it.

next unless length;

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




Re: unit messages

2007-05-01 Thread oryann9
  Why are you creating these regexes so far from
 where
  they are used?
  If you are going to do this at least give them
  meaningful names.


I dont have a good reason Chas other than I like the
ability to easily change the variable in one spot in
case of future use.
If this is not a good reason, then guess it is
style.
:)
 
  
  use the three argument version of open, if you
 don't
  you will
  eventually be bitten by a file name that contains
  information that
  open thinks is part of the mode:
  
  open JFS, +, $jfsFile or die file '$jfsFile'
 was
  not opened $!;
  
  Also, you may consider using lexical varaibles
  instead of bareword file handles:
  
  open my $jfs, , $jfsFile or die file
 '$jfsFile'
  was not opened $!;
 
  it is easy to misread if ! so use unless
 instead. 
  Also length works
  on $_ if no argument is passed to it.
  
  next unless length;
 
 
All is understood and well taken. 
thx 

 pu  

Oryan the Cat [[derek]] .
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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




unit messages

2007-04-30 Thread oryann9
Please advise on the small amount of code b/c I am
getting the message as below, but the code is working
and output how I want it, just trying to rid of
messages.

thank you!


Use of uninitialized value in concatenation (.) or
string at
JFS_version_parser.pl line 20, JFS line 952 (#1)

Use of uninitialized value in concatenation (.) or
string at
JFS_version_parser.pl line 21, JFS line 952 (#1)

Use of uninitialized value in concatenation (.) or
string at
JFS_version_parser.pl line 21, JFS line 956 (#1)

Use of uninitialized value in concatenation (.) or
string at
JFS_version_parser.pl line 22, JFS line 956 (#1)


use strict;
use warnings;
use diagnostics;

my $jfsFile = qq(/tmp/onlinJFS_4_license_exp.txt);
my $CvsFile = qq(/tmp/onlinJFS_4_license_exp.cvs);
my $regexp  =
qr/(host:\w+)|(onlinejfs.*)|(jfs\sversion.*)/is;
my ($host,$swlist,$kernel) = 0;

open (JFS, +$jfsFile) or die file '$jfsFile' was
not opened $!;

while (JFS) {
s/^\s+|\s+$//g;
next if ! length $_;

if (/$regexp/) {
($host,$swlist,$kernel) = ($1, $2, $3);
print \n$1;
print \t$2;
print $3\n;
}
}

__DATA__

---
HOST:axyz
---

You have mail.
logout

# OnlineJFS B.11.11   
Online features of the VxFS File System
  OnlineJFS.VXFS-ADV-RUNB.11.11   
VXFS-ADV-RUN
# PHCO_258311.0   
SCSI Ultra160 driver Online Addition script
  SW-DIST.SD-JPN-E-HELP B.11.11.0212  
Japanese EUC Online Help for SD
  SW-DIST.SD-JPN-S-HELP B.11.11.0212  
Japanese SJIS Online Help for SD
  X11.X11-RUN-CL-MANB.11.11   
Online manual pages for X11 clients
  X11.X11-RUN-CT-MANB.11.11   
Online manual pages for X11 contrib clients
  X11.X11-RUN-MAN   B.11.11   
Online manual pages for X11 clients


  OnlineDiagB.11.11.09.11  HPUX
11.11 Support Tools Bundle, Dec 2002


JFS version loaded in Kernel: $Revision: libvxfs.a:
CUPI80_BL2000_1108_2 Wed Nov 8 10:59:22 PST 2000 $
Connection to closed.

---
HOST:xyxxx
---

__DesiredOutput__

HOST:xyzzz

OnlineJFS B.11.11 Online features of the VxFS File
System

OnlineJFS.VXFS-ADV-RUN  B.11.11 VXFS-ADV-RUN

JFS version loaded in Kernel: $Revision: libvxfs.a:
CUPI80_BL2000_1108_2 Wed Nov 8 10:59:22 PST 20
00 $


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


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




Re: unit messages

2007-04-30 Thread Tom Phoenix

On 4/30/07, oryann9 [EMAIL PROTECTED] wrote:


Use of uninitialized value in concatenation (.) or
string at
JFS_version_parser.pl line 20, JFS line 952 (#1)


This message happens because some value was undef instead of a string.

From the message, it seems likely that it's a variable being

interpolated into a string. Once you find out which variable, and why
it's undef, and that it doesn't matter whether it's undef or an empty
string, you could fix it something like this:

   # avoid messages about uninitialized $whatever
   $whatever =  unless defined $whatever;


use strict;
use warnings;
use diagnostics;


The first two are great. The third one is not intended for production
code; you should 'use diagnostics' only when you're developing code
and expecting error messages. I say this in part because 'diagnostics'
has a significant overhead of both time and memory. Be sure to disable
it when your code goes into production.


You have mail.


Don't we all?

Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




Re: unit messages

2007-04-30 Thread Chas Owens

On 4/30/07, oryann9 [EMAIL PROTECTED] wrote:
snip

my $regexp  =
qr/(host:\w+)|(onlinejfs.*)|(jfs\sversion.*)/is;

snip

Why are you creating this regex so far from where it is being used?
Why are you using three captures when this expression can only return one?

snip

if (/$regexp/) {
($host,$swlist,$kernel) = ($1, $2, $3);
print \n$1;
print \t$2;
print $3\n;
}

snip

Why are you using three prints instead of one (print \n$1\t$2$3\n)?

The three print lines are where your warnings are coming from.  Only
one of $1, $2, $3 is set at a time (since they are all alternatives).

This script demonstrates what is going on:

#!/usr/bin/perl

use strict;
use warnings;

my @a = qw(abc def ghi);

for my $s (@a) {
   $s =~ /(b)|(e)|(h)/;
   print 1 = [$1] 2 = [$2] 3 = [$3]\n;
}

I would rewrite your code:

#!/usr/bin/perl

use strict;
use warnings;

while (DATA) {
   s/^\s+|\s+$//g;
   next unless length;
   if (/(host:\w+)/is) {
  print \n$1;
   } elsif (/(onlinejfs.*)/is) {
   print \t$1;
   } elsif (/(jfs\sversion.*)/is) {
   print $1\n;
   }
}

__DATA__

---
HOST:axyz
---

You have mail.
logout

# OnlineJFS B.11.11
Online features of the VxFS File System
OnlineJFS.VXFS-ADV-RUNB.11.11
VXFS-ADV-RUN
# PHCO_258311.0
SCSI Ultra160 driver Online Addition script
SW-DIST.SD-JPN-E-HELP B.11.11.0212
Japanese EUC Online Help for SD
SW-DIST.SD-JPN-S-HELP B.11.11.0212
Japanese SJIS Online Help for SD
X11.X11-RUN-CL-MANB.11.11
Online manual pages for X11 clients
X11.X11-RUN-CT-MANB.11.11
Online manual pages for X11 contrib clients
X11.X11-RUN-MAN   B.11.11
Online manual pages for X11 clients


OnlineDiagB.11.11.09.11  HPUX
11.11 Support Tools Bundle, Dec 2002


JFS version loaded in Kernel: $Revision: libvxfs.a:
CUPI80_BL2000_1108_2 Wed Nov 8 10:59:22 PST 2000 $
Connection to closed.

---
HOST:xyxxx
---

__DesiredOutput__

HOST:xyzzz

OnlineJFS B.11.11 Online features of the VxFS File
System

OnlineJFS.VXFS-ADV-RUN  B.11.11 VXFS-ADV-RUN

JFS version loaded in Kernel: $Revision: libvxfs.a:
CUPI80_BL2000_1108_2 Wed Nov 8 10:59:22 PST 20
00 $

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




Re: unit messages

2007-04-30 Thread John W. Krahn
oryann9 wrote:
 Please advise on the small amount of code b/c I am
 getting the message as below, but the code is working
 and output how I want it, just trying to rid of
 messages.
 
 thank you!
 
 
 Use of uninitialized value in concatenation (.) or
 string at
 JFS_version_parser.pl line 20, JFS line 952 (#1)
 
 Use of uninitialized value in concatenation (.) or
 string at
 JFS_version_parser.pl line 21, JFS line 952 (#1)
 
 Use of uninitialized value in concatenation (.) or
 string at
 JFS_version_parser.pl line 21, JFS line 956 (#1)
 
 Use of uninitialized value in concatenation (.) or
 string at
 JFS_version_parser.pl line 22, JFS line 956 (#1)
 
 
 use strict;
 use warnings;
 use diagnostics;
 
 my $jfsFile = qq(/tmp/onlinJFS_4_license_exp.txt);
 my $CvsFile = qq(/tmp/onlinJFS_4_license_exp.cvs);
 my $regexp  =
 qr/(host:\w+)|(onlinejfs.*)|(jfs\sversion.*)/is;

You are using three sets of capturing parentheses so either $1 will match and
$2 and $3 will be undef or $2 will match and $1 and $3 will be undef or $3
will match and $1 and $2 will be undef.  You should change that to one set of
capturing parentheses:

my $regexp = qr/(host:\w+|onlinejfs.*|jfs\sversion.*)/is;


 my ($host,$swlist,$kernel) = 0;
 
 open (JFS, +$jfsFile) or die file '$jfsFile' was
 not opened $!;
 
 while (JFS) {
 s/^\s+|\s+$//g;
 next if ! length $_;
 
 if (/$regexp/) {
 ($host,$swlist,$kernel) = ($1, $2, $3);
 print \n$1;
 print \t$2;
 print $3\n;
 }

With only one set of capturing parentheses change that to:

  if (/$regexp/) {
  print \n$1\n;
  }


 }



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

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