RE: Sudoers Regex

2002-04-19 Thread Jason Larson

> -Original Message-
> From: Blackburn, David W [mailto:[EMAIL PROTECTED]]
> Subject: Sudoers Regex
> 
> Hi

Hello.
> 
> I am trying to parse a string of text from a sudoers file, 
> what I am trying
> to get out is the HOSTCLUSTER name and the hosts.
> 
> Host_Alias  HOSTCLUSTER =   host1, host2, \
> host3, host4, \
> host5, host6 
> 
> The first problem is I split using "=" so $hostAlias[0] contains
> "Host_Alias  HOSTCLUSTER" and I just need to return the 
> HOSTCLUSTER part
> and disgard Host_Alias so I will need a regex for that.
> 
> And the second bit needs to return the hosts
> 
> I know there are no examples but I have tried numerous ways 
> and cannot solve
> this..
> 
 

I assume you need all 6 hosts for each hostcluster.  Following is a program
that does that.  If you have questions about exactly what is happening,
please send me a message and I'll be happy to go through it line by line for
you...

Hope this helps...
Jason

use warnings;
use strict;

my %clusters = ();
my $sudoer_file = "sudoers.current";
open (FH, "<$sudoer_file") || die "Couldn't open $sudoer_file: $!";
while (defined (my $line = )) {
next unless ($line =~ /^Host_Alias/);
my ($discard, $cluster_name, @hosts) = split(/\W+/, $line);
while ($line =~ m#\\$#) {
my $new_line = ;
$new_line = Trim($new_line);
push (@hosts, (split (/\W+/, $new_line)));
$line = $new_line;
}
$clusters{$cluster_name}{Hosts} = \@hosts;
}
foreach my $cluster (sort keys %clusters) {
print "\n$cluster contains:\n";
my $hosts = $clusters{$cluster}{Hosts};
foreach my $host (@$hosts) {
print "  $host\n";
}
}
close (FH) || die "Can't close $sudoer_file: $!";

#this subroutine trims leading and trailing white space from a variable
#it accepts either a variable or an array as its only argument
sub Trim {
my @out = @_;
for (@out) {
s/^\s+//;
s/\s+$//;
}
return wantarray ? @out : $out[0];
}


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: problem with directory listing

2002-04-11 Thread Jason Larson

> -Original Message-
> From: richard noel fell [mailto:[EMAIL PROTECTED]]
> Subject: problem with directory listing
> 
> Below is sample code that does not work as I intend, the 
> intention being
> to list all the sub-directories in a given directory.
> 
> #!/usr/local/ActivePerl-5.6/bin/perl5.6.1 -w
> 
> use strict;
> my $mw;
> my $menubar;
> my $algebra;
> my @file_array;
> 
> my $dir_to_process = "/home/rfell/mathprogram";
> opendir DH, $dir_to_process or die "cannot open $dir_to_process: $!";
> foreach my $file (@file_array=readdir DH){
> if( -d $file){
> print "$file is a sub-directory of $dir_to_process \n";
> }
> }
> closedir DH;
> 
> The  problem is that only . and .. are listed. No other 
> sub-directories,
> which are in fact there, are listed. I surely am missing something
> simple here. Can anyone enlighten me?
> Thanks, 
> Dick Fell

I tested this on Win2k, ActiveState Perl 5.6.1, build 631, and had a similar
problem.  I did some further testing and got some interesting results.  Here
is what I found:

When run from c:\home\rfell\mathprogram, it showed all the directories.

When run from the root of C:\, it showed ., .., and the first subdirectory I
created.

When run from c:\home, it showed only . and .. as directories.

When run from a network drive, it showed only . and .. as directories.

All the subdirectories ARE listed in the array, but somehow the file test
descriptor is not being applied correctly or something.  I haven't looked on
ActiveState's site to see if this has been reported previously, but it seems
as though it definitely merits further investigation (or a better
explanation of why this is happening).

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.



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




RE: regular expression to get a file extension

2002-04-09 Thread Jason Larson

> -Original Message-
> From: Ahmed Moustafa [mailto:[EMAIL PROTECTED]]
> Subject: regular expression to get a file extension
> 
> I had the following regular expression to get the extension 
> from a file 
> name:
> 
> 
> $extension = $filename;
> $extension =~ s/(^.+\.)([^\.]+)$/$2/;
> 
> 
> But it didn't work (in case the $filename didn't have an 
> extension); so 
> I had to add the following line:
> 
> 
> $extension = "" if (!$1);
> 
> 
> What is wrong with my regular expression?
> How can it be done in a single regular expression?
> 
> -- 
> Ahmed Moustafa
> http://pobox.com/~amoustafa
> 

Try this:
  $extension =~ s/(^.+\.?)([^\.]*)$/$2/;

Your regex will fail for a couple of different reasons:
1) if there is no extension, there (probably) won't be a dot, so you need to
take that into account (\.?).
2) if there is no extension, you're going to fail because you are matching
"one or more non-period characters.  You need "zero or more non-period
characters", so change the final '+' to a '*'.  That should take care of
your problem.

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.



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




RE: regex excluding \w.\w\w\w.\w

2002-04-02 Thread Jason Larson

> -Original Message-
> From: Teresa Raymond [mailto:[EMAIL PROTECTED]]
> Subject: regex excluding \w.\w\w\w.\w
> 
> I'm trying to figure out how to exclude upload files with 2 periods 
> at the end (b/c of that virus which I forgot the name of, maybe 
> nimba?)  Anyhow, this is what I have but it doesn't work.  When I try 
> to submit with the double periods the test always results in false 
> and never gives the error msg.
> 
> if ($filename=~/(\w.\w\w\w.\w)$/)
> {error($q, "Invalid file name; files must only contain one period.
> Please push the back button on your browser and try again.");
> }

What are you using for $filename?  With that regex, you will get an error
for almost any filename that is at least 7 characters.  In addition, you
will not get a match if your filename has more than one character after the
second '.' The '.' is only working for you by accident because it is really
matching any character (except \n).  It needs to be escaped.
Try something like this:
  if ($filename =~ /\.\w+\.\w+$/){error...}

What this regex says is:
  Match a period followed by one or more word characters [a-zA-Z0-9_],
followed by a period, followed by one or more word characters at the end of
the string.  This will produce the error for the following values of
$filename, to give just a few examples:
  $filename = 'test.com.exe';
  $filename = 'test.c.com';
  $filename = 'test.exe.c';
  $filename = 'test.exe.co';

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.



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




RE: regex help

2002-04-02 Thread Jason Larson

> -Original Message-
> From: Gabby Dizon [mailto:[EMAIL PROTECTED]]
> Subject: regex help
> 
> hello list friends,

Hello.
> 
> hope you can help me with my problem. here it is:
> 
> i have a date string formatted this way:  $date = "Apr. 02, 2002"
> i want to capture the "Apr" (without the period) into $1, 
> "02" into $2, and "2002" into $3.
> note that some months may not be abbreviated (such as May), 
> and therefore might not have a period.
> my regex skills are still sadly inferior (though i'm learning =)

  $date =~ /(\w+)\.? (\d+), (\d+)/;

Bear in mind that this solution assumes that the format is always the same
(meaning exactly one space between each value you want to store.  Also be
aware that $1, $2, $3, etc. are read-only variables, so it would (probably)
be better to assign the values to another variable right away.

  my ($Month, $Date, $Year) = $date =~ /(\w+)\.? (\d+), (\d+)/;

> 
> my second (and optional) problem for you to solve: i want to 
> transform this
> into mysql date format (-mm-dd). this is easy enough to 
> do, but i was
> wondering if there are any modules there that can date 
> manipulation a lot
> easier. if you know any, just let me know.
> 
> thanks a lot!
> 
> Gabby Dizon
> Web Developer
> Inq7 Interactive, Inc.

Your best option is to check CPAN for date manipulation modules.

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.



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




RE: Creating variables of a string

2002-04-02 Thread Jason Larson

> -Original Message-
> From: Michael Stearman [mailto:[EMAIL PROTECTED]]
> Subject: Re: Creating variables of a string
> 
> Right now it is not working and I was wondering if I sent the 
> code maybe 
> someone with more experience with this will see the problem.  
> I am very new 
> to this.  The line I am trying to create the variables from is
> 
> C6xxxSimulator(TI)61  1
> 
> and the code is
> 
> $word = ; #Assign the next line to the $word variable
> chomp $word;
> print "$word\n";
> my ($target, $count, $num) = $word = ~ 
> /^\s*(\S+)\s+(\S+)\s+(\S+)\s*$/;
> print "Target = $target \n";
> print "Count = $count \n";
> 
> and the output is
> 
> C6xxxSimulator(TI)61  1
> Target = 4294967295
> Count =
> 
> Does anyone have any ideas?  I'm lost.

I agree with Japhy that a split is probably the best solution, but to answer
your question, you have a space between '=' and '~', which is causing the
pattern match to not bind to the $word variable.
  my ($target, $count, $num) = $word = ~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s*$/;
should be
  my ($target, $count, $num) = $word =~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s*$/;

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.



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




RE: get full name of $user in NT?

2002-03-25 Thread Jason Larson

> -Original Message-
> From: David Samuelsson (PAC) [mailto:[EMAIL PROTECTED]]
> Subject: get full name of $user in NT?
> 
> 
> Is there anyway off getting the full name from an remote 
> user? that is, i know the persons log on sign, say "ROMI"
> 
> full name is "Robert Mitchum" accordin to NT. Is there any 
> Perl code , that you know off? i have checked the 
> Win32::AdminMisc functions, and that seems to return, nothing 
> or numbers =/ when i have tried it.
> //Dave

I don't know if there's a better/faster/easier way to do this, but this is
one way to accomplish what you want:

use warnings;
use strict;
use Win32::NetAdmin qw(GetUsers GetDomainController);
my %UserHash;
my $Domain = "yourdomain";
my $UserID = "ROMI";
GetDomainController("","$Domain", my $Server);
GetUsers($Server, 0, \%UserHash) or die "GetUsers() failed: $^E";
foreach my $key(keys %UserHash) {
  if (lc($key) eq lc($UserID)) {
print "$key is: $UserHash{$key}\n";
  }
}
__END__

Should return:
ROMI is: Robert Mitchum

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.



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




RE: callin subs

2002-03-22 Thread Jason Larson

> -Original Message-
> From: Matthew Harrison [mailto:[EMAIL PROTECTED]]
> Subject: callin subs
> 
> i have defined a sub using
> 
> sub mysubname{
>   code here
> }
> 
> but how do i call it? i have tried just having the name but 
> that doesn't 
> work.
> 
> -- 
> Matthew Harrison

mysubname();

If your sub has a return value that you need to assign to a variable:

my $returnvar = mysubname();

If you need to pass parameters into the sub:

mysubname($param1, $param2);

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.



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




RE: perl infant stage..

2002-03-21 Thread Jason Larson

> -Original Message-
> From: Perl CosmicVoid [mailto:[EMAIL PROTECTED]]
> Subject: RE: perl infant stage..
> 
> Hi!
> 
> Ive got two different Perl icons now.
> One Big Perl and another a small perl against a paper
> backdrop.. 
> 
> the MSDOS program does run, However its a split second
> thing its zips in front of the eye and disappears..
> 
> Please Advise.
> MaLs..

You have 2 options...

1) Run your program from a command prompt.  This is generally the preferred
way to do it, but I'm like you, so I usually double-click mine, which brings
me to option 2...

2) Create a pause at the end of your program.  You can put in a pause that
waits till you hit enter by adding these two lines to the end of your
script:
  print "Press Enter to continue...";
  my waitvar = ;

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: "Use of uninitialized value" error message

2002-03-14 Thread Jason Larson

> -Original Message-
> From: John W. Krahn [mailto:[EMAIL PROTECTED]]
> Subject: Re: "Use of uninitialized value" error message
> 
> Jason Larson wrote:
> > 
> > I'm still new to Perl myself, so I can't tell you exactly 
> what's happening,
> > but it looks like $result_value1 is undef when it gets to 
> the if statement.
> > I think a better way to accomplish what you're trying to do 
> is simply:
> > 
> >   my $result_value1;
> >   if ($result_value) { #$result_value1 is defined
> ^^  ^^^
> This is _NOT_ testing whether $result_value1 is defined or 
> not (in fact
> it is not testing $result_value1 at all :-), it is testing whether
> $result_value1 is true or false which is not the same thing.
> 
>if ( defined $result_value1 ) { #$result_value1 is defined
> 
Doh!  My bad...  You are, of course, correct.  Thanks for pointing out my
error.
(for any beginners reading this that may not understand the difference, let
me give a quick example...)
 use warnings;
 use strict;
 my $result_value = "0";
 if ($result_value) {
   print "\$result_value is defined and is: $result_value";
 } else {
   print "\$result_value is undefined"
 }
 __END__

This prints out "$result_value is undefined", which is obviously not true.
If we change the if statement as John pointed out, we get a better result

 if (defined $result_value) {

This prints out "$result_value is defined and is: 0", which is a better
evaluation of the variable.

Sorry about the confusion, and I hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Problem with EXE created by PerlApp

2002-03-14 Thread Jason Larson

**The following information is primarily just an FYI**
> -Original Message-
> From: Jenda Krynicky [mailto:[EMAIL PROTECTED]]
> Subject: RE: Problem with EXE created by PerlApp
> 
> From:         Jason Larson <[EMAIL PROTECTED]>
> > > Sorry I don't understand why this happens. Just a wild guess ... 
> > > could you try to name your variable something else than $Registry?
> > 
> >   Didn't even dawn on me to try something like that... was 
> following the
> > example listed in the docs... That took care of the 
> problem!  Thanks!
> 
> Ack ... but when you run the script directly, without compiling it 
> everything works, right ?
> 
> Please send a bug report to ActiveStates via 
> http://bugs.activestate.com/enter_bug.cgi
> 
> 'Cause it looks that the $Registry that you declared lexical in your 
> script leaked into the import() function in Win32::TieRegistry.
> 
Thanks for the suggestion.  I looked through the bug database before
submitting the bug and didn't find anything, but when I submitted it, they
said it was a duplicate of 11031 (guess I didn't look for the right thing).
Their comments on 11031 state:

"This problem happens because of a bug in Perl itself, where lexical
variables are leaking out of their lexical scope. The following program
demonstrates this bug, where the lexical $foo leaks into the safe_eval() sub
defined above it.

  sub safe_eval { eval shift }
  my $foo = "a";
  BEGIN { safe_eval('BEGIN { $foo = "b" }') }
  warn $::foo;
  warn $foo;

This problem is still present in PerlApp 4.0 with ActivePerl 631."

> I can't replicate this with my version of PerlApp.

hmmm... Does that mean they should have said "This problem happens because
of a bug in ActivePerl itself"...?

Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: the scope of BEGIN {}

2002-03-13 Thread Jason Larson

> -Original Message-
> From: Nikola Janceski [mailto:[EMAIL PROTECTED]]
> Subject: the scope of BEGIN {}
> 
> 
> BEGIN {
>   if ($^O =~ /^(ms)?(win|dos)(32|nt)?$/i){
>   eval q{ 
>   use lib "N:/xxx/perl_lib";
>   use Win32::Process;
>   use Win32::Event 1.00 qw(wait_any);
> 
>   $follow = 0; # used in find command
>   $follow_skip = 0; # used in find command
>   }
> 
>   } else {
>   eval q{ 
>   use lib "/xxx/perl_lib";
> 
>   $follow = 1; # used in find command
>   $follow_skip = 2; # used in find command
>   }
>   }
> }
> 
> Here is my question, $follow and $follow_skip I want to be a 
> global variable
> in the scope of the perl script I am running.
> If I put a my in front of the declaration wouldn't it only be 
> in the scope
> of BEGIN or would it be in the scope of the entire script? 
> How can I declare
> it so that use strict; and use warnings; won't complain?
> 
> (This has to be a global variable for I use it several 
> subroutines and is OS
> dependent).

I think you can do:
 use warnings;
 use strict;
 use vars qw($follow $follow_skip);

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: "Use of uninitialized value" error message

2002-03-13 Thread Jason Larson

  Original Message-
From: Ho, Tony [mailto:[EMAIL PROTECTED]]
Subject: RE: "Use of uninitialized value" error message

Hi Nikola/Jason 
Thanks for the help. 
The variable $result_value1 is declared within the subroutine and is never
used outside the subroutine. 
I originally had the following piece of code (which I forgot to show you
guys in the previous email): 
 
 $result_value1 = $database1{$input_key1}  
 
 But I changed the above code to the following and it worked ("Use of
uninitialized value" error message" did not appear):
 
 $result_value1 = $database1{$input_key1} || " ";  
 

ahh... that would do it, though I don't think that's the preferred way to
solve your problem.
 
You are getting the "Use of uninitialized value" warning message because
$database1{$input_key1} is undef.  You are simply bypassing that by making
$result_value1 a " " if it would otherwise return undef.  By using your
original code ( $result_value1 = $database1{$input_key1}; ) with "if
($result_value1);" you do what you want and avoid the warning because you
are now checking to see if $result_value1 is defined.  I know that Nikola
says you will still get the warning, but it always works for me...  :)
 
Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: getOpt::long?

2002-03-13 Thread Jason Larson

> -Original Message-
> From: michael [mailto:[EMAIL PROTECTED]]
> Subject: Re: getOpt::long?
> >
> > > I am a true perl newbie.
> >
> > If you continue like this you will stay one.
> >
> :-) Thanks for all the feedback. I had intended to send the 
> assignment as an
> attachment and ask about:
> 1) Configuring my win2k box so that I could use the command 
> line to run a
> perl program without having to type 'perl' before the name of 
> the program in
> order to execute it, and

All the information you should need about the AS install of Perl should be
on your start menu as: Start | Programs | ActiveState ActivePerl 5.6 |
Documentation.  To answer your specific question, you can open the html
file: file:///C:/Perl/html/faq/Windows/ActivePerl-Winfaq4.html and select
"How do I associate Perl scripts with perl?"  I'd detail the answer for you,
but it's already been done, so it'll be easier for both of us if you read
the documentation.

> 2) How to access perl documentation.

a) Start | Programs | ActiveState ActivePerl 5.6 | Documentation
b) You can also go to C:\Perl\bin, and run perldoc from there (it is a batch
file that emulates perldoc on Unix)
c) http://www.perldoc.com
d) Install cygwin

> 
> C:\>cd perl
> 
> C:\Perl>perldoc -f getopt
> 'perldoc' is not recognized as an internal or external command,
> operable program or batch file.

Need to be in C:\Perl\bin directory

> 
> C:\Perl>perl -v
> 'perl' is not recognized as an internal or external command,
> operable program or batch file.

Need to be in C:\Perl\bin directory

> 
> I have installed ActiveState Perl 5.6.1 build 631 on this 
> machine, some time
> ago, and have previously written perl scripts on it ( small ones!).
> 
> I also have this problem on my laptop.

The aforementioned answers should resolve the issue on your laptop as well.

> 
> So I installed Mandrake Linux 8.2 last night, and am even 
> able to find the
> info on the getopt module.
> 
> Now I just have to buy a supported printer so I can print it out!
> 
> Sorry to have bothered.

Understand that we are here to help.  The feedback you got was based on the
information that was sent.  It was not meant to be degrading, but you have
to look at it from our perspective.  Now that you've re-posted, I hope this
answers your questions, though running perldoc -f getopt didn't return
anything for me, so you might have to check some of the other sources.

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: "Use of uninitialized value" error message

2002-03-13 Thread Jason Larson

> -Original Message-
> From: Ho, Tony [mailto:[EMAIL PROTECTED]]
> Subject: "Use of uninitialized value" error message
> 
> Hi guys
> I was wondering if you could help me with the following problem.
>  
> I am getting the following error message:
>  
> Use of uninitialized value in string ne at 
> format_imsi_msisdn.pl line 257.
> 
> line 257 and beyond consist of the following:
>  
> if ($result_value1 ne " ") {
>   $a= substr($result_value1, 0, 8);
>   $b= substr($result_value1, 8, 2);
>   $c= substr($result_value1, 10, 2);
>   return ($a, $b, $c);
> }
> else {
>   return (" ", " ", " ");
> }
>  
> I declare the variable result_value1 at the begining of the method as
> follows
>  
> my $result_value1 =" ";
>  
> Any ideas why ?

I'm still new to Perl myself, so I can't tell you exactly what's happening,
but it looks like $result_value1 is undef when it gets to the if statement.
I think a better way to accomplish what you're trying to do is simply:

  my $result_value1;
  if ($result_value) { #$result_value1 is defined
 $a= substr($result_value1, 0, 8);
 $b= substr($result_value1, 8, 2);
 $c= substr($result_value1, 10, 2);
  } else { #$result_value1 is still undef
 return (" ", " ", " ");
  }

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Multiline searching -

2002-03-12 Thread Jason Larson

> -Original Message-
> From: Steven M. Klass [mailto:[EMAIL PROTECTED]]
> Subject: Multiline searching - 
> 
> 
> Hi all,
> 
>   I have a text that broken into sections.  Each section 
> has comments(;) and 
> can be placed anywhere,  Each section ends with "*ENDS" .  
> Each section 
> begins with a *KEYWORD, where keyword is any word like DESCRIPTION, 
> OPERATION, FOO, AND BAR.  I want to read in this one section 
> at a time.  I 
> then want to work exclusively on one section(DESCRIPTION).  
> Can someone 
> enlighten me a bit.  I want to know how to read this in by 
> section (as oposed 
> to line) that ends with (*ENDS).  Then I want to know how to 
> tell what 
> section I'm in (*DESCRIPTION), and then I want to know where 
> to do my search 
> and replace (s/INFILE/TEST/).  I hope someone can help me 
> out.  Thanks so 
> much for your continued patience!
> 
> Example Text
> 
> ; Test 
> ; Test
> *DESCRIPTION
> ; More comments
> INFILE = blach
> OUTFILE = test
> ;
> 
> ;
> *ENDS
> ;
> ;
> *LAYERS
> LAYER=1
> ;
> *ENDS
> ;
> 

I'm assuming this text is in a file... Here is some code to read in the
records and find the sections and keyword for each section (assuming that
each section only has one keyword, and that it starts with '*').

use warnings;
use strict;

$/ = "*ENDS\n"; #change the record separator
open (FILE, "test1.txt") || die "Can't open test1.";
while (defined(my $Section = )) {
  my ($KeyWord) = $Section =~ /\*(.*)\n/;
  print "Information for $KeyWord section:\n" if ($KeyWord);
  print "$Section\n\n";
}

I'm not sure what you mean when you say "and then I want to know where to do
my search and replace (s/INFILE/TEST/)."
If you just want to replace INFILE with TEST in this section, you would
simply use the regex you have, binding it to (in this case) $Section.
  $Section =~ s/INFILE/TEST/;

On the other hand, if you want to know what lines are not comments, and each
non-comment line contains "TEXT = info" you could look for the '='.
  my (@TextToReplace) = $Section =~ /(.*)\s*=/g;

This regex could be modified if you wanted to store both the TEXT and the
info, giving a final code of something like this...

use warnings;
use strict;

$/ = "*ENDS\n";
open (FILE, "test1.txt") || die "Can't open test1.";
while (defined(my $Section = )) {
  my ($KeyWord) = $Section =~ /\*(.*)\n/;
  print "Information for $KeyWord section:\n" if ($KeyWord);
  my (@TextToReplace) = $Section =~ /(.*)\s*=\s*(.*)/g;
  my %RTHash;
  my $x=0;
  while ($x<=@TextToReplace) {
$RTHash{$TextToReplace[$x]} = $TextToReplace[$x+1] if
($TextToReplace[$x]);
$x+=2;
  }
  foreach my $key (keys %RTHash) {
print "replacement text is: $key, which has a value of: $RTHash{$key}\n"
if ($key);
  }
  print "$Section\n\n";
}

You may want to break up parts of this into subroutines, but this should get
you started.

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Problem with EXE created by PerlApp

2002-03-11 Thread Jason Larson

> -Original Message-
> From: Jenda Krynicky [mailto:[EMAIL PROTECTED]]
> Subject: Re: Problem with EXE created by PerlApp
> 
> From: Jason Larson <[EMAIL PROTECTED]>
> 
> Sorry I don't understand why this happens. Just a wild guess ... 
> could you try to name your variable something else than $Registry?

  Didn't even dawn on me to try something like that... was following the
example listed in the docs... That took care of the problem!  Thanks!

> 
> If you install the Win32::Registry2 patch you'll get more functions, 
> better docs and the "obsolete" remark will go away as well ;-)

  Ok, so does that mean that Win32::Registry2 is the preferred module to use
when working with the registry?  Win32::TieRegistry seemed to be easier to
work with than Win32::Registry, but I want to use the preferred method, as I
don't want to be going back and fixing all my scripts 6 months from now.

Thanks again,
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Stripping everything after words found

2002-03-11 Thread Jason Larson

Looks like you that almost works, Tanton.  I think what he wants is:

  $string =~ s/^(.*?)Call Distance:.*/$1/;

Hope this helps...
Jason

> -Original Message-
> From: Tanton Gibbs [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, March 10, 2002 11:29 PM
> To: Daniel Falkenberg; bob ackerman
> Cc: [EMAIL PROTECTED]
> Subject: Re: Stripping everything after words found
> 
> 
> You want to extract the LEAST possible...use
> 
> $string =~ s/^(.*?)Call Distance/$1/;
> 
> Tanton
> - Original Message - 
> From: "Daniel Falkenberg" <[EMAIL PROTECTED]>
> To: "bob ackerman" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Monday, March 11, 2002 12:26 AM
> Subject: RE: Stripping everything after words found
> 
> 
> > Bob,
> > 
> > This is what I had in the first place (($test) = $string =~ 
> /(.*)Call
> > Distance/;).  All I want to do is extract EVERYTHING before 
> the first
> > instance of Call Distance:.  From there using the same regular
> > expression I need to remove EVERYTHING after Call 
> Distance:. Including
> > Call Distance:.  So if I had the string...
> > 
> > $string = "Kind Crud Call Distance: hell world Crud Call Distance:";
> > 
> > Using a regex.  I should end up with only *Kind Crud* and 
> that is all.
> > 
> > Any ideas?
> > 
> > Kind regards,
> > 
> > Dan
> > 
> > -Original Message-
> > From: bob ackerman [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, 11 March 2002 3:47 PM
> > To: Daniel Falkenberg
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: Stripping everything after words found
> > 
> > 
> > oh - you didn't want to include 'Call Distance'? 
> > then: 
> > ($test) = $string =~ /(.*)Call Distance/; 
> > 
> > 
> > would only capture text up to 'Call Distance'. Needn't 
> worry about rest
> > of string. 
> > 
> > 
> > On Sunday, March 10, 2002, at 08:54 PM, bob ackerman wrote: 
> > 
> > 
> > how about: 
> > ($test) = $string =~ /(.*Call Distance)/; 
> > 
> > 
> > On Sunday, March 10, 2002, at 08:27 PM, Daniel Falkenberg wrote: 
> > 
> > 
> > $string = "Crud I want Call Distance more crud skdafj 
> 343sad55434 "; 
> > 
> > 
> > How would I go about getting rid of everything after the 
> Call distance 
> > and including the Call Distance? 
> > 
> > -- 
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: help with my parser program?

2002-03-11 Thread Jason Larson

> -Original Message-
> From: M z [mailto:[EMAIL PROTECTED]]
> Subject: help with my parser program?
> 
> could someone please help me make this bit of code
> more efficient?  I am trying to break really long
> lines, say up to 600 characters into manageable sizes
> (78 or less characters) but I do not want to break
> cleanly at position 78.  If that is in the middle of a
> word, my program back steps to the first whitepace.
> 
> but I think I am overdoing it here, although it seems
> to give me the results I want.
> 
> I would not like to use a module for this, but rather
> have it hard coded myself.  Please help me without
> module advice if possible


It's ridiculous that this is being re-posted, but this is Japhy's response
to YOUR question from a few days ago...
  s/(.{1,78})\s/$1\n/g;


open(X, ") {
  s/(.{1,78})\s/$1\n/g;
  print;
}


The really bad part about this is is that *I* posted this response (from the
original message) to another user just a couple of days after the original
message, so this answer is out there twice already.


Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





Problem with EXE created by PerlApp

2002-03-08 Thread Jason Larson

__Disclaimer__ ***Sorry about the giant company disclaimer at the end***
I have a script (script follows signature) that works just fine when
executed at the command line (i.e. perl.exe fixnetrcname.pl).  I want to
make this an executable to distribute to systems that don't have Perl
installed, but when I run the compiled EXE, I get the error:
--
 Can't call method "Clone" on an undefined value at Win32/TieRegistry.pm
line 146
 .
 BEGIN failed--compilation aborted at c:\temp\fixnetrcname.pl line 4.
--
Here is the command line I used for PerlApp, along with the verbose output:
--
 c:\perl\bin\perlapp.exe -s=c:\temp\fixnetrcname.pl -f
-e=fixnetrcname.exe -v -r
--
 Input script name: c:\temp\fixnetrcname.pl
 Output exe name: fixnetrcname.exe
 Exe Mode: Freestanding
 Building Console mode exe
 Temp files will be kept on exit
 Failed 'use's will be reported
 Adding Module: c:/Perl/lib/Exporter.pm
 Adding Module: c:/Perl/lib/Carp.pm
 Adding Module: c:/Perl/site/lib/Win32/WinError.pm
 Adding Module: c:/Perl/lib/strict.pm
 Adding Module: c:/Perl/lib/vars.pm
 Adding Module: c:/Perl/lib/Config.pm
 Adding Module: c:/Perl/lib/warnings/register.pm
 Adding Module: c:/Perl/lib/warnings.pm
 Adding Module: c:/Perl/lib/DynaLoader.pm
 Adding Module: c:/Perl/lib/auto/DynaLoader/dl_expandspec.al
 Adding Module: c:/Perl/lib/auto/DynaLoader/dl_findfile.al
 Adding Module: c:/Perl/lib/auto/DynaLoader/dl_find_symbol_anywhere.al
 Adding Module: c:/Perl/lib/auto/DynaLoader/autosplit.ix
 Adding Module: c:/Perl/lib/Carp/Heavy.pm
 Adding Module: c:/Perl/site/lib/Win32API/Registry.pm
 Adding Module: c:/Perl/lib/Exporter/Heavy.pm
 Adding Module: c:/Perl/site/lib/Win32/TieRegistry.pm
 Adding Module: c:/Perl/lib/AutoLoader.pm
 Adding Module: c:/Perl/lib/Tie/Hash.pm
 Adding Module: c:/Perl/site/lib/Win32API/Registry/cRegistry.pc
 Adding Binary: c:/Perl/site/lib/auto/Win32API/Registry/Registry.dll
 Adding Binary: c:/Perl/site/lib/auto/Win32/WinError/WinError.dll
--
I know I can just write the script with use Win32::Registry (instead of
Win32::TieRegistry), but the documentation from AS says that Win32::Registry
is obsolete, and that I should use Win32::TieRegistry.

Can somebody please help me out and let me know what I'm doing wrong, or
what I can do to fix this (other than re-writing it with use Win32::Registry
(which does work, btw).

Thanks,
Jason
--
use warnings;
use strict;
my $Registry;
use Win32::TieRegistry (TiedRef => \$Registry, Delimiter=>"\\");

my $ComputerName =
$Registry->{"LMachine\\System\\CurrentControlSet\\Control\\ComputerName\\Com
puterNameComputerName"};
my $NetrcNameKey = $Registry->{"LMachine\\Software\\Funk Software,
Inc.\\Proxy Host\\Settings\\"};
my $NetrcName = $NetrcNameKey->{"Name"};

if ($NetrcName ne $ComputerName) {
  $NetrcNameKey->{"\\Name"} = $ComputerName;
} #end if
exit (0);
--


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Finding words between words...

2002-03-08 Thread Jason Larson

> -Original Message-
> From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
> Cc: 'Daniel Falkenberg '; [EMAIL PROTECTED]
> Subject: RE: Finding words between words...
> 
> 
> On Mar 7, Timothy Johnson said:
> 
> >From: Jeff 'japhy' Pinyan
> >
> >>  ($btwn) = $str =~ /In:(.*)Your/;
> >
> >Out of curiosity, what happens if you leave off the 
> parentheses on $btwn?
> 
> You try it. ;)  I suggest you read "'List' is a Four-Letter 
> Word", which
> you can find at
> 
>   http://www.pobox.com/~japhy/articles/pm/2000-02.html
> 

For those of us who have ridiculous firewall filterings and are unable to
read the article right now, I'll give a short answer...
If you leave off the parentheses, $btwn is in scalar mode, and returns 1 to
denote that the match succeeded (I think).  With the parentheses, $btwn is
then in list mode, so it is assigned the first value in the assignment
(which also happens to be $1).  At least that is the way I understand it.

Hope this helps...
Jason

P.S. I only know this because I asked Japhy nearly the exact same question
on an answer he once gave me.  :)


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: text editors

2002-03-08 Thread Jason Larson

> -Original Message-
> From: michael [mailto:[EMAIL PROTECTED]]
> Subject: text editors
> 
> Speaking of text editors, anyone know of a good one that has
> line #ing 
> for W2K? Free, of course (I am a student).

I'm still testing a number of them myself, but so far I like ConTEXT for
PERL editing.  It's freeware, and has some nice features, including
customizable execution keys (I use one to run my script in a console, and
another to capture information in the output window).  You can get it at:
http://www.fixedsys.com/context.

> 
> BTW - this is a list that is really worth reading. You guys
> (and you know who you are) are fantastic. Some of the
> explanations offered here are so clear that even I can
> understand them!

I completely agree with you on that!

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: File substitutions??

2002-03-07 Thread Jason Larson

> -Original Message-
> From: Patrick Bateman [mailto:[EMAIL PROTECTED]]
> Subject: File substitutions??
> 
> Hi everyone

 Hi!  I'm still pretty new myself, so forgive me for not doing this the
"Perl way".
> 
> Need help with this please, pretty please!!
> 
> I open a file containing this:
> e.g.
> John:111:0
> Peter:222:0
> Jane:333:0
> 
> Now I select a particular name from an input.
> Now comes the part I'm having trouble with.  For that name 
> I've selected how
> do I increment the count value.
> e.g.
> If I select Peter then file is modified to this:
> John:111:0
> Peter:222:1
> Jane:333:0
> 
> and so on
> Heres the sub routine that needs to be fixed

 

> 
> sub FIND {
>   open (FIND, "prac1.txt") or die "$! file error";
>   while () {
> ($name, $phone, $count) = split(/:/, $_);
> if ($name =~ $compare[1]) {

>   print "$phone\n";
>   close FIND;
>   open (APPEND, ">>prac1.txt") or die "$! file error";
>   $count++;
>   substitute APPEND $count;
>   close APPEND;
> }
>   }
> }
> 
> Thanks heaps
> Patrick Bateman


use warnings;
use strict;

print "What name are you looking for? ";
my $find_name = ;
chomp ($find_name);
FIND ($find_name);

sub FIND {
  my $f_name = $_[0];
  open (FIND, "prac1.txt") or die "$! file error";
  open (TMPFIND, ">prac1.txt.tmp") or die "$! file error";
  while () {
chomp;
my ($name, $phone, $count) = split (/:/);
if ($name =~ /\Q$f_name\E/i) {
  $count++;
  print "\nPhone number for \u$name is $phone\n";
}
print TMPFIND join (':', $name, $phone, $count), "\n";
  }
  close FIND || die "Can't close FIND";
  close TMPFIND || die "Can't close TMPFIND";
  rename ("prac1.txt", "prac1.txt.old");
  rename ("prac1.txt.tmp", "prac1.txt");
}

This uses the old "output to a new file and rename at the end" procedure,
but I'm still too new to know how to do it any other way...

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: simple file reading question

2002-03-06 Thread Jason Larson

> -Original Message-
> From: siren jones [mailto:[EMAIL PROTECTED]]
> Subject: simple file reading question
> 
> I have a file containing a list of names, for example:
> 
> S2000123456.met
> S2000123457.ozone
> S2000123458.hdr
> S2000234569.met
>.
>. etc.
> 
> I'm looking for a short way to read these filenames onto an array.
> 
> I tried:
> 
> my @fils = <$indir/filename>;
> 
> . but this just gives me the name of my input file
> 
> I can do this, but it seems cumbersome.
> 
>  open LF or die "Can not find file: \n $infile $!\n";
>   sysread LF, $filename, 5;
>   @imgs = split(/\n/,$filename);
>   close (LF);
> 
> Thank you in advance.
> 
> -s

You're right, that does seem cumbersome.  This solution isn't as nice and
neat as what you'd like, but maybe it'll seem less cumbersome that what you
mentioned:

my ($file, @files);
while (defined($file = <>)) {
  chomp ($file);
  push (@files, "$indir/$file");
}

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Request from Beginner

2002-03-05 Thread Jason Larson

> -Original Message-
> From: Raja Gopal [mailto:[EMAIL PROTECTED]]
> Subject: Request from Beginner
> 
> Hello All,
> 
>   I would like to learn PERL for handling files. 
> (Open, edit, close, write,  delete some lines, pattern
> matching..etc). I did search in the net (using
> Google.com).But I couldn't find the tutorial/e-book
> which helps beginner (like me) to learn the basics,
> becoz there are so many websites. Since I am working
> in IC design, I don't have much exposure in Software
> /Scripting. Kindly give me some pointers for
> e-book/tutorials which helps me.
> 
>  Your co-operation/help would be highly appreciated.
> 
> Thanks and Regards,
>   Raja Gopal

The most basic syntax for opening files is:
  open (FILEHANDLE, "path/to/file");  OR
  open (FILEHANDLE, "path/to/file") || die "Couldn't open path/to/file";
This will create a new file if it does not exist, or if the file does exist,
it will clear all the contents of the file and start writing at the
beginning of the file.

To open a file for appending:
  open (FILEHANDLE, ">>path/to/file") || die "Couldn't open path/to/file";
This will open a file, and put the pointer at the end of the file to begin
your writing.

To actually write to the file:
  print (FILEHANDLE, "stuff to print");

To close a file:
  close (FILEHANDLE) || die "Couldn't close file";

Probably the best options for books are the O'Reilly books (Particularly
"Learning Perl", "Programming Perl", and "The Perl Cookbook").  These books
should give you all the information you need to get started, and of course
this list is here for any questions that arise.

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Regexp needed

2002-03-05 Thread Jason Larson

> -Original Message-
> From: Jorge Goncalvez [mailto:[EMAIL PROTECTED]]
> Subject: re:Regexp needed
> 
> 
> hi, i have this:
> my ($Path) = $MountsPath =~ /(.+?)cygwin/;
> but I wanted to get rid of the "/".
> because $MountsPath could be c:/cygwin or c:/xyz/cygwin or 
> c:/xyz/zyx/cygwin and 
> i wanted $Path = c: or c:/xyz or c:/xyz/zyx .
> And now $Path= c:/ or c:/xyz or c:/xyz/zyx.
> How can I do ?
> thanks.

Just add the "/" to your match outside the grouping, like so:
  my ($Path) = $MountsPath =~ /(.+?)\/cygwin/;

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: reading one character at a time

2002-03-04 Thread Jason Larson

> -Original Message-
> From: Timothy Johnson [mailto:[EMAIL PROTECTED]]
> Subject: RE: reading one character at a time
> 
> I can't check this right now, but I believe you can do it like this:
> 
> $Line = "some string";
> @array = split //,$Line;  #split on null
> foreach(@array){
>$char = read_char($_);
> }

Actually, this will generate an error on the read_char because perl will see
that as a subroutine.  This is almost the same, but will do what you want
without giving errors:

use strict;
my $Line = "some string";
my @array = split (//,$Line);  #split on null
foreach my $char (@array){
  print "$char\n";
}

would return:
s
o
m
e

s
t
r
i
n
g


Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Comparing to many possibles

2002-03-04 Thread Jason Larson

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Subject: Comparing to many possibles
>
> Greetings;
> 
> Is there some perl shorthand that will make it easier to say
> 
>   if ( $x eq 'X' || $x eq 'Y' || $x eq 'Z' )
> 

This should do what you want:
 if ($x =~ /^[XYZ]$/)

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Using strict and getting return values

2002-03-04 Thread Jason Larson

> -Original Message-
> From: Dermot Paikkos [mailto:[EMAIL PROTECTED]]
> Subject: Using strict and getting return values
> 
> Hi Gurus,

Well, I'm definitely not a guru, but I think I might be able to help... :)
> 
> I am trying to get tidy with my scripts and want to use Strict but am 
> having difficulty with return values from subroutines. I have the 
> following snippet:
> 
>   while (defined(my $i =<$fh>)) {
> chomp($i);
> my @a = split(/|/,$i);
> my $last = $a[1];
> my $first = $a[0];
> if ( $name =~ /$last/i ) {
>   return($first,$last);
> }
>  and get the error:
> Global symbol "$last" requires explicit package name at 
> /var/www/perl/reply.pl line 16.

Where is line 16?  Can you post the whole code?  How did you call the sub
before getting the error?  Without knowing that, I'm going to make an
assumption that you did not assign values to the return from the sub.

> 
> When I later:  print "Hello $first $last\n";
> 
> I know it is out of the scope but I thought I could pass the 
> results of 
> a sub to main.
> 
> What am I doing wrong??
> Dp.

Assuming the name of your subroutine is SomeSub, the piece of your code that
calls the sub should look something like:

my ($FName, $LName) = SomeSub();

Then you can do:
print "Hello $FName $LName\n";


Hope this helps
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: strip first space

2002-03-01 Thread Jason Larson

> If I have a string and the first character is a space,
> may not always be a space.
> Example:  John
>   Tommy
> Beth
> 
> John and Beth have a space, Tommy does not.
> How do I strip that. I do not want to use the global
> command because a want the space between First
> and Last name. Any suggestions?
> 
> Susan

I got this subroutine from a friend (who originally got it from the
cookbook, I think).

#this subroutine trims leading and trailing white space from a variable
#it accepts either a variable or an array as its only argument
sub Trim{
  my @out = @_;
  for (@out){
s/^\s*(.*?)\s*$/$1/;
  } #end for
  return wantarray ? @out : $out[0];
} #end sub

$name = "John Doe";
$name = Trim($name);
print ("$name\n");

would return:
John Doe

So, in your case, the script would return:
John
Tommy
Beth

This routine strips the leading and trailing spaces, so it would allow you
to maintain the space between the first and last name that you were worried
about.

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: pattern matching question

2002-02-28 Thread Jason Larson

-Original Message-
From: bob ackerman [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 28, 2002 11:32 AM
To: richard noel fell
Cc: [EMAIL PROTECTED]
Subject: Re: pattern matching question

On Thursday, February 28, 2002, at 08:37  AM, richard noel fell wrote:

> while (defined($Line=)){
>   if($Line=~/(\(D\d+\))\s*(\w*)/){
> print "==> $2\n";
> };
> };
>

disclaimer: i am a rank newbot
if i replace '/w*' with '.*$'
i get desired text.
looks like \w* doesn't do what we expect.
problems with \t in lines?
--
I'm also new to Perl, so I won't correct your typo, but I will point out a
problem in your statement: "looks like \w* doesn't do what we expect."  I'm
not sure who "we" is, but this does exactly what is expected.  '\w*' matches
zero or more word characters.  The problem with the match is that the white
space in the lines was followed by non-word characters ('-' and '/').  A
word character is any letter, number, or underscore.  Your match with '.*'
works because that matches zero or more of ANY character.
As for the question: "problems with \t in lines?", that should not make any
difference to the match, because '\s*' would match the tabs, as tabs are
considered whitespace characters.

HTH!
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: pattern matching question

2002-02-28 Thread Jason Larson

-Original Message-
From: richard noel fell [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 28, 2002 10:38 AM
To: [EMAIL PROTECTED]
Subject: pattern matching question

I have the following bit of code:
#!/usr/bin/perl -w
open In2,"/home/rfell/tutoring/beaven/webproject/tmp/maxima_log" or die
"Cannot open maxima_log:$!";
my $Line; 
while (defined($Line=)){
  if($Line=~/(\(D\d+\))\s*(\w*)/){
print "==> $2\n";
};
};
#close In2;


maxima_log is the following
(C1) 
  2335
(D1)- 
   24
(C2) 
(D2)   0
(C3) 
(D3)   /home/rfell/tutoring/beaven/webproject/tmp/maxima_results
(C4) 

I want to match the D lines, so my match pattern is as above. It seems
that I have the following construct:
(D followed by a digit(s)) followed by white space followed by some
characters. I want to capture the last characters. In the above example,
for line (D2), I want to get the "0", which is stored, I hope, in $2.
However, I get no match. If I replace $2 with $1, I do get the (D1), etc
to print.

Another question
1) If I change the match pattern to /(\(D\d+\))\s+(\w*)/, that is, one
or more occurences of white space, I get no match at all. $1 does not
print out now. Do I not really have white space?

Has anyone any idea what I am doing wrong? Thanks for your help to a
perl newcomer.
Dick Fell
-
Your pattern match /(\(D\d+\))\s*(\w*)/ is not correct.  You stated :"It
seems that I have the following construct: (D followed by a digit(s))
followed by white space followed by some characters."  That is not quite
right.
  Your construct is: (D followed by one or more digits) followed by zero or
more white space characters followed by zero or more **WORD** characters.
Word characters are defined as any letter, number, or the Underscore
character (and possibly additional alphabetic characters defined a specific
locales).  So, your hyphens don't get matched, nor do your slashes.  That is
why your match returns unexpected results.  You should change the last
portion to include other characters.  One option is /(\(D\d+\))\s*(.+)/
which would then match $1 to one or more characters of ANY type.

HTH!
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: windows perl just doesn't seem to work

2002-02-13 Thread Jason Larson

># this is a script to clean
> 
>open(IN,"fileToClean.asc") || die "can't open!";
> 
>while() {
>s/Good/Bad/;
>print;
>}
> 
>On the screen I can see that this is working, but when I open the file,
>guess what? Nothing has changed!  ...can anybody figure out what I am
doing 
>wrong?

I'm still very new to PERL, so please don't flame me if this answer is
wrong, but from the looks of this, you've got 2 problems.

1) You never print this to the file.  You read in the information from
"fileToClean.asc", match the information, then print it to the screen (not
the file).  Why would you expect the file to change?

2) Assuming your print statement was print (IN);, you'd still have a problem
because you opened  for reading, not writing.  Again, I'm new to all
this, but I thought the question has been asked "Can I open a file for read
and write?", and the answer was "No".  In that case, you'd have to open a
second file to redirect your output to, and if you then needed it to be the
same name, you could delete the original file and rename the new file.

open(IN,"fileToClean.asc") || die "can't open!";
open(OUT, ">cleanfile.asc") || die "can't open OUT";
while() {
  s/Good/Bad/;
  print(OUT) || die "Can't write to file";
}

HTH
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Can't take stdout in w98 xcopy

2002-02-13 Thread Jason Larson

Triyng 

$x=qx(xcopy a:\\1*.* c:\\tmp);
print"\n after \n$x \n before \n";

this is how it looks my dos session

C:\WINDOWS\Escritorio>perl -w kk.pl
13feb.zip
1 archivos copiados

 after

 before


I think xcopy (and other dos commands, Nbtstat.exe, ...) do not send data to
stdout 
¿how could i do to catch that data?

To capture the output of , use backticks "`".
$x =`xcopy a:\\1*.* c:\\tmp`;
print "\n after \n$x \n before \n";


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: regexp for validating DOS 8.3 filename

2002-02-12 Thread Jason Larson

> I'm sure this is simple but I'm getting more and more confused:

Don't feel bad - I stay that way! :)

> I want to validate input so that it is either:
>a valid dos filename (we still use it)
>up to 12 alphanumeric characters (inc spaces)
>nothing (in which case 'none' would be entered by default
> 
> Here's my snippet:
> #!/usr/bin/perl
> use strict;
> my $file;
> print "\nType filename [8.3] or [enter] for none: ";
> while (){
> chomp;
> # last if ((/^\S{1,8}\.\S{0,3}/)or(/^\w{1,12}/));
> last if (/\w{1,12}/);
> print "try again: "
> }
> print "approved";
> 
> Testing the above I realised that (/\w{1,12}) was allowing more than
> 12 alphanumeric characters (I've commented out the first
> 'last if' to test on it's own) and I'm not sure why.

I'm still very new to PERL myself, but I'll give this a shot...
/\w{1,12}/ matches at least 1, but not more than 12 characters in a series
of word characters (letters, numbers, or underscores).  This does not mean
that the series itself cannot be more than 12 characters, only that the
match can't be more.
For example:
$str = 1234567890123456789;
$str =~ /(\w{1,12})/;
print $1;
-- would print out 123456789012 because that is what matched.  You still
have to take into account the rest of the string.

> I've been stuck on this for a considerable time so I'd really appreciate
> someone's insight into my errors.

I'm sure there is a better way to do this, but like I said, I'm still new,
so this is one way you could accomplish it:

#use strict;
my $file;
print "\nType filename [8.3] or [enter] for none: ";
while (){
chomp;
/[\w ]{1,12}/;
last if ((/^\S{1,8}\.\S{0,3}/)or($' eq ""));
print "try again: "
}
print "approved";

What this does is that it performs the match, similar to what you had before
(I used character classes to include the space), but this time it checks to
see if there's anything left over (leftover pieces of the string that follow
the match go into the variable "$'").  If it sees that you entered 1-12
characters (alpha/number/underscore or a space) it will then check to see if
"$'" is blank (indicating that the series was 1-12 characters).

Bear in mind that your other match may not return results you necessarily
want.  For example, based on a match of "a string of 1-8 non-whitespace
characters followed by a "." and 1-3 non-whitespace characters" you could
get filenames such as x.x, 1.1, x.xx, x.12, or 1.23, just to name a few.

HTH!
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





RE: Add remove programs windows ??

2002-01-09 Thread Jason Larson

Jenda is correct - it's not OT, and yes, you will need to filter the
subkeys.  You want to look for the values of the "DisplayName" strings.
These are the values that show up in Add/Remove Programs.

-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 09, 2002 1:42 PM
To: [EMAIL PROTECTED]
Subject: Re: Add remove programs windows ??


Steve Maroney <[EMAIL PROTECTED]> wrote:
> That is way OT!!

in response to:
> > I would like to be able to retrieve the same list that pops up in a
> > window
> > when (on 95 & NT4) you click the 'Add Remove/ programs' applet in
> > Control
> > Panel.  Anybody got any ideas?
> >
> >
> > Mike

Sorry Steve, but it's NOT.

If he wants to get the list from a Perl script than the question is 
perfectly valid for this list.

Mike you may want to look into the registry at 
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

I believe you will need to filter the keys below a bit since I seem to 
have keys for programs I already deleted as well as keys that are 
either empty or contain value "SystemComponent":DWORD=1.

I'm not 100% this is the list you want but I think so.

Jenda

=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
--- me

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


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.