Re: writing to a text file --> permission denied

2001-05-30 Thread Nichole Bialczyk

that's what i thought, too. but i already did that.
- Original Message - 
From: "Asim Memon" <[EMAIL PROTECTED]>
To: "Nichole Bialczyk" <[EMAIL PROTECTED]>
Sent: Thursday, May 31, 2001 2:07 AM
Subject: Re: writing to a text file --> permission denied


> are you sure the permissions are set...as in if the browser is
> writing then you have to make sure the file is writable by
> everyone...
> just to make sure so a 
> chmod 777 filename
> 
> this will let everyone write to your file.
> -asim
> 
> --- Nichole Bialczyk <[EMAIL PROTECTED]> wrote:
> > when i put in the $! i get the error message Permission denied. i
> > also tried
> > to do it the standard way with the open...or die... statement, but
> > then i
> > got an internal server error 500. sometimes i think it's better to
> > write
> > your own code than to modify existing code. gr
> > 
> > i really appreciate everyone's help. maybe one day i can aspire to
> > be a
> > guru! :)
> > - Original Message -
> > From: "Michael Fowler" <[EMAIL PROTECTED]>
> > To: "Nichole Bialczyk" <[EMAIL PROTECTED]>
> > Cc: <[EMAIL PROTECTED]>
> > Sent: Thursday, May 31, 2001 1:17 AM
> > Subject: Re: writing to a text file
> > 
> > 
> > > On Thu, May 31, 2001 at 01:00:49AM -0500, Nichole Bialczyk wrote:
> > > > i'm trying to write a log file and i can't seem to open it to
> > write to.
> > the file does exist. here is the code for opening the file:
> > > >
> > > > if(! open(LOG, ">xxx.txt)) {
> > > >print "Content-type: text/html\n\n";
> > > >print "Can't open xxx.txt\n";
> > > >exit;
> > > > }
> > > > print LOG "At $date, $ENV{'REMOTE_HOST'} etc., etc.
> > >
> > > I'd suggest putting $! in your output, to better figure out why
> > you can't
> > > open the file.
> > >
> > > For example:
> > >
> > > if (! open(LOG, ">xxx.txt")) {
> > > print "Content-type: text/html\n\n";
> > > print "Can't open xxx.txt: \l$!.\n";
> > > exit;# 
> > > }
> > >
> > >
> > > Michael
> > > --
> > > Administrator  www.shoebox.net
> > > Programmer, System Administrator   www.gallanttech.com
> > > --
> > >
> > 
> 
> 
> __
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail - only $35 
> a year!  http://personal.mail.yahoo.com/
> 




writing to a text file --> permission denied

2001-05-30 Thread Nichole Bialczyk

when i put in the $! i get the error message Permission denied. i also tried
to do it the standard way with the open...or die... statement, but then i
got an internal server error 500. sometimes i think it's better to write
your own code than to modify existing code. gr

i really appreciate everyone's help. maybe one day i can aspire to be a
guru! :)
- Original Message -
From: "Michael Fowler" <[EMAIL PROTECTED]>
To: "Nichole Bialczyk" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, May 31, 2001 1:17 AM
Subject: Re: writing to a text file


> On Thu, May 31, 2001 at 01:00:49AM -0500, Nichole Bialczyk wrote:
> > i'm trying to write a log file and i can't seem to open it to write to.
the file does exist. here is the code for opening the file:
> >
> > if(! open(LOG, ">xxx.txt)) {
> >print "Content-type: text/html\n\n";
> >print "Can't open xxx.txt\n";
> >exit;
> > }
> > print LOG "At $date, $ENV{'REMOTE_HOST'} etc., etc.
>
> I'd suggest putting $! in your output, to better figure out why you can't
> open the file.
>
> For example:
>
> if (! open(LOG, ">xxx.txt")) {
> print "Content-type: text/html\n\n";
> print "Can't open xxx.txt: \l$!.\n";
> exit;# 
> }
>
>
> Michael
> --
> Administrator  www.shoebox.net
> Programmer, System Administrator   www.gallanttech.com
> --
>




Re: writing to a text file

2001-05-30 Thread Hasanuddin Tamir

On Thu, 31 May 2001, Nichole Bialczyk <[EMAIL PROTECTED]> wrote,

> Date: Thu, 31 May 2001 01:00:49 -0500
> From: Nichole Bialczyk <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: writing to a text file
> 
> i'm trying to write a log file and i can't seem to open it to write to. the file 
>does exist. here is the code for opening the file:
> 
> if(! open(LOG, ">xxx.txt)) {
>print "Content-type: text/html\n\n";
>print "Can't open xxx.txt\n";
>exit;
> }

If you put $! in the line, you'll find out why,

print "Can't open xxx.txt: $!\n";


hth
s.a.n
-- 
Hasanuddin Tamir: [EMAIL PROTECTED] - Trabas: www.trabas.com




Re: writing to a text file

2001-05-30 Thread Michael Fowler

On Thu, May 31, 2001 at 01:00:49AM -0500, Nichole Bialczyk wrote:
> i'm trying to write a log file and i can't seem to open it to write to. the file 
>does exist. here is the code for opening the file:
> 
> if(! open(LOG, ">xxx.txt)) {
>print "Content-type: text/html\n\n";
>print "Can't open xxx.txt\n";
>exit;
> }
> print LOG "At $date, $ENV{'REMOTE_HOST'} etc., etc.

I'd suggest putting $! in your output, to better figure out why you can't
open the file.

For example:

if (! open(LOG, ">xxx.txt")) {
print "Content-type: text/html\n\n";
print "Can't open xxx.txt: \l$!.\n";
exit;# 
}


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--



writing to a text file

2001-05-30 Thread Nichole Bialczyk

i'm trying to write a log file and i can't seem to open it to write to. the file does 
exist. here is the code for opening the file:

if(! open(LOG, ">xxx.txt)) {
   print "Content-type: text/html\n\n";
   print "Can't open xxx.txt\n";
   exit;
}
print LOG "At $date, $ENV{'REMOTE_HOST'} etc., etc.

any comments/suggestions would be most helpful.
thanks, nichole



Re: test for real number

2001-05-30 Thread Morten Sickel

Hi Mike,

You wrote:

>How do I test an input to see if it is a real number?  I have a situation
>something like:

(slightly snipped)

>if (input equals a real number) {
>xx
>}
>else {
>
>}

Do you mean 'if it really is a number' or 'a real number' in the matematical
sense? If you have some advanced matematical things going on, please forget
this message, but if what you want to do is to check a value before
inserting it into a database or something similar to that, a quick and dirty
way of converting is just to say:

$value=;
$value*=1; # ie $value=$value*1;
if ($value){
   print "$value is a number\n"
}
else{
   print "This is not a number\n"
}

Divided by 1 or plus / minus 0 would do the same, force perl to think about
the value as a number. As a semi-beginner, I can see two problems with this
approach:
1: if $value=0 it will be counted as false
2: For a value that starts with a number, such as 123ABC, the numerical part
will be retained as a number, and everything including the first letter to
the end of the string will be thrown away:
i.e:
input  : ABCDE
output : This is not a number
input  : 0   <- Zero
output : This is not a number
input  : 1.2345
output : 1.2345 is a number
input  : 123ABC
output : 123 is a number
input  : ABC123
output : This is not a number 

This may, or may not be, what you want. I am using that conversion/check
quite often, but in those cases, I know that my value cannot be zero.

Regards

Morten Sickel
Norwegian Radiation Protection Authority



Re: how to copy a hash ?

2001-05-30 Thread ___cliff rayman___

that will only copy a shallow hash.  that is, one that does not
contain references to other hashes or arrays.  if you want to
copy all elements (a deep copy), here is a suggestion:

use Storable qw(freeze thaw);

%arr1=qw(key1 data1 key2 data2);
$arr1{key3}=[qw(arrdata1 arrdata2)];

%arr2=%{thaw freeze \%arr1};

now all the elements of %arr1 are copies into %arr2.  %arr2 has
its own copy of an array with the same elements.  if you
don't make a deep copy, then %arr2 will point to the same
array as %arr1 and changing $arr2{key3}->[0] will also
change $arr1{key3}->[0].  sometimes this is what you want,
other times it is a disaster.

hth,

--
___cliff [EMAIL PROTECTED]http://www.genwax.com/

baby lakshmi wrote:

> hi
> what abt this??
> %arr1=qw(this 1 is 2 a 3 sample 4 program 5);
> %arr2=%arr1;
> print $arr2{this};
>
>






Re: how to copy a hash ?

2001-05-30 Thread baby lakshmi

hi
what abt this??
%arr1=qw(this 1 is 2 a 3 sample 4 program 5);
%arr2=%arr1;
print $arr2{this};


>From: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED]
>Subject: how to copy a hash ?
>Date: Wed, 30 May 2001 18:05:32 +0800
>
>hello,
>
>I have a question :
>
>how to copy a hash?
>
>example: $h is   reference  of a hash struct.
>i want to copy this hash struct.
>
>how to do that?
>
>thanks.
>
>
>
>Legend Software Business
>Linux   Zhangxinj
>Tel£º62986638-6555
>E-mail:[EMAIL PROTECTED]
>

_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.




Re: 'while' confusion

2001-05-30 Thread ___cliff rayman___


"E. Alan Hogue" wrote:

>
>
> foreach $field (@fld_vals) {
> while ($field = '') {

i think u want an 'if' here. when you use a 'while', the
program continues to loop if the condition is true. this
usually implies you will do something to change the
condition within the loop.  since you are not changing
$field within the loop, if $field does = "" then this program
will loop until the system runs out of power..

>
> push (@nulls,$id);
> }
> }
>
> My idea was that $id would be, for instance, the
> primary key value so that I could go look at the
> record later.
>
> Well, it didn't do what I wanted, but what really
> confuses me is what it actually did. When I went
> through the program in the debugger, it looked like my
> while statement was actually _assigning_ '' to each
> element of @fld_vals, thereby erasing the data in that
> array.
>
> Can anyone tell me why it did this?

'fo'r loops alias the index variable (default is $_, in this case it is $field) to
the elements in the array.  this is a feature of 'for' loops.

check out:
perldoc perlsyn
/foreach


--
___cliff [EMAIL PROTECTED]http://www.genwax.com/





Re: 'while' confusion

2001-05-30 Thread Me

> foreach $field (@fld_vals) {

Means, iterate through @fld_vals. For each
cell, make $field be an alias to that cell, then
do the bracketed code that follows.

So, if you assign to $field in the code that
follows, you assign to the cell in the array too.

The code gets done once for each cell.

> while ($field = '') {

The bit in brackets assigns null to $field,
and hence to that cell of the @fld_vals array.

The 'while' would start another loop within the
foreach loop (clearly not what you intended)
only it doesn't do anything because the value
of an assignment:

$foo = 3;

is the value of $foo after the assignment is
done, which is 3 (true) in the above case but
is '' (false) in your case.

hth.




Re: 'while' confusion

2001-05-30 Thread Tony Cook

On Wed, 30 May 2001, E. Alan Hogue wrote:
...
> foreach $field (@fld_vals) {
>   while ($field = '') {
>   push (@nulls,$id);
>   }
> }
> 
> My idea was that $id would be, for instance, the
> primary key value so that I could go look at the
> record later. 
> 
> Well, it didn't do what I wanted, but what really
> confuses me is what it actually did. When I went
> through the program in the debugger, it looked like my
> while statement was actually _assigning_ '' to each
> element of @fld_vals, thereby erasing the data in that
> array.
> 
> Can anyone tell me why it did this?

It does that because = is the assignment operator.

If you want to compare strings you want to use the eq operator, eg:

 foreach $field (@fld_vals) {
if ($field eq '') {
# I assume these are defined somewhere else
push (@nulls,$id);
}
 }

For a complete description of perls operators, see perldoc perlop.

-- 
Tony




'while' confusion

2001-05-30 Thread E. Alan Hogue

Hello,

I'm new to this list and pretty much an absolute perl
beginner. I'm really enjoying the list and would
appreciate a little insight into the true meaning of
'while'. For some reason I'm having trouble using it.

I was working on something today to help me find bad
data in a text file. Among other things, I wanted the
program to make a list of empty fields (This is easy
to do with the database, but I wanted the program to
look for other warning signs, like phone nubmers that
contain all zeroes, so I thought it would be nice to
make it find the nulls too). I tried something like
this (note: I didn't finish this program, and I don't
think it entirely makes sense):

foreach $field (@fld_vals) {
while ($field = '') {
push (@nulls,$id);
}
}

My idea was that $id would be, for instance, the
primary key value so that I could go look at the
record later. 

Well, it didn't do what I wanted, but what really
confuses me is what it actually did. When I went
through the program in the debugger, it looked like my
while statement was actually _assigning_ '' to each
element of @fld_vals, thereby erasing the data in that
array.

Can anyone tell me why it did this?

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: Why 'and' not '&&' ? (was Cleaning up 'uninitialized value')

2001-05-30 Thread Paul Johnson

On Wed, May 30, 2001 at 11:42:15AM -0700, Paul wrote:
> 
> --- Peter Cornelius <[EMAIL PROTECTED]> wrote:
> > > Use:
> > >   if (@ARGV and -T $ARGV[0]) { ... }
> > 
> > Just wondering if there is a reason for using the lower precedence
> > 'and' here instead of '&&'?  I haven't been finding many uses for
> > 'and' which tells me I might not fully understand it.
> 
> I've almost never written code that used && in perl.

Whereas I rarely use "and".

> 'and' has a lower precedence, which is usually what you want with
> boolean expressions. It lets you write the same syntax with less line
> noise.

> Also, while a lot of C programmers tend to try doing things in the
> familiar fashion, I believe 'and' is a lot more readable than '&&',

But I think && and || stand out better.

> which is a plus, and it also helps you remember this is Perl, not C.
> The same mentality that hangs onto && will write
> 
>   for(my $i=0; $i<10; $i++) { print $i }

Hmmm.

> Why the different structures?
> Because everyone does it differently.
> Perl doesn't make you abandon one for another, but each has its
> advantages

 and disadvantages.

I dabbled with "and" and "or" when they were added to the language, but
decided that in general I preferred && and ||, "if" and "unless".  Of
course the lower precedence operators have their place, but there is no
need to banish the higher precedence operators.

So, learn the precedence and use them as you see fit, or choose what
you're happy with and use parentheses as appropriate.

http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-05/msg01072.html

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



RE: doubt about do/until

2001-05-30 Thread Peter Scott

At 11:32 AM 5/31/01 +1000, King, Jason wrote:
>I notice that the copyright notice is 1996 .. so perhaps my memory is
>failing me and that there was a version of Perl where  did NOT grab
>the line-ending character as well .. otherwise Tom really is human and has
>made a mistake :)

I would peg it as a mistake... but just for the edification of the list, if 
you use the -l option to perl, this code *will* work, because the \n will 
be autochomped.  So we could charitably say that it depended on the shebang 
line... except that that should have been noted.  Anyway, if you haven't 
heard of the -l option yet, do a perldoc perlrun and look it up, it's very 
handy.

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




RE: Perl script not running

2001-05-30 Thread King, Jason

David Olbersen wrote ..

>On Thu, 31 May 2001, Henk Klos wrote:
>
>> I have just downloaded and installed the latest version of Perl for
>> WinNT. Followed all the instructions, associated .pl with perl.exe,
>> etc etc. However, not one sample htm file from the "eg" directory is
>> working. What did I forget???
>
>Did you forget that .htm files are HTML and not Perl files?

there are a number of HTML examples included with Perl

  perl/eg/IEExamples client-side PerlScript examples
  perl/eg/aspSamples server-side Perl/ASP examples
  perl/eg/Core/cgi   server-side standard CGI examples

the two server-side sets of examples require a web server to be running on
the machine and for the user to run them via a http:// URL .. the
client-side samples can be run straight from Windows Explorer

-- 
  jason king

  In Spearfish, South Dakota, if three or more Indians are walking down
  the street together, they can be considered a war party and fired
  upon. - http://dumblaws.com/



RE: doubt about do/until

2001-05-30 Thread King, Jason

[EMAIL PROTECTED] wrote ..

>In http://www.cpan.org/doc/FMTEYEWTK/is_numeric.html, 
>( Is it a number? ), Tom Christiansen writes:
>---
>If you do care about getting 0's, then do this: 
>  do { 
>   print "Number, please: ";
>   $answer = ;
>   if ($answer == 0 && $answer ne '0') {
> print "Bad number\n";
>   }
> } until $answer;
>---
>
>I tried this with ActiveState perl version 5.005_03. I entered 0 and
>got a bad number. After thinking awhile, I chomped the $answer. This
>works for 0, ( i.e. No "Bad number message" and the loop repeats ). I
>think we need a chomp there ( so instead of '0\n' ne '0', it is '0' ne
>'0' ). Is it so or am I missing something?

you haven't missed anything .. the code should definitely have a chomp in
there

I notice that the copyright notice is 1996 .. so perhaps my memory is
failing me and that there was a version of Perl where  did NOT grab
the line-ending character as well .. otherwise Tom really is human and has
made a mistake :)

basically any of the samples where a string comparison is done should be
chomping STDIN before the comparison because while the numeric comparison
will ditch the trailing garbage (which in this case is LF) the string
comparison obviously will not

-- 
  jason king

  In Spearfish, South Dakota, if three or more Indians are walking down
  the street together, they can be considered a war party and fired
  upon. - http://dumblaws.com/



Re: Perl script not running

2001-05-30 Thread David Olbersen

On Thu, 31 May 2001, Henk Klos wrote:

> I have just downloaded and installed the latest version of Perl for WinNT.
> Followed all the instructions, associated .pl with perl.exe, etc etc.
> However, not one sample htm file from the "eg" directory is working.
> What did I forget???

Did you forget that .htm files are HTML and not Perl files?

-- Dave




Perl script not running

2001-05-30 Thread Henk Klos

Hi,

I have just downloaded and installed the latest version of Perl for WinNT.
Followed all the instructions, associated .pl with perl.exe, etc etc.
However, not one sample htm file from the "eg" directory is working.
What did I forget???

Thanks

henk



RE: Can't locate loadable object for module ...

2001-05-30 Thread King, Jason

Margit Brunder wrote ..

>I've written a cgi script and when Apache (version 1.3.6) tries to call
>it, I get the error message "can't locate loadable object for module
>HTML::Parser in @INC at ./HTML/entities.pm line 79" although the
>module Parser.pm IS in the same directory as entities.pm The path where
>Parser.pm is located is included in @INC !!

because the module name is HTML::Parser then the Parser.pm module has to be
in the HTML subdirectory of one of the @INC directories

so if you're 'use'ing the HTML::Parser module from within
'/some/directory/HTML/entities.pm' then the directory '/some/directory'
would have to be in @INC

you say that '/some/directory/HTML' is in @INC .. in that case when you type

  use HTML::Parser;

then Perl is looking for '/some/directory/HTML/HTML/Parser.pm' and will
obviously not find it

hope that's clear - it can be a little confusing at first

references:

  perldoc perlmod
  perldoc -f require
  perldoc -f use

-- 
  jason king

  In Spearfish, South Dakota, if three or more Indians are walking down
  the street together, they can be considered a war party and fired
  upon. - http://dumblaws.com/



Re: Help recursing directories and java mod question

2001-05-30 Thread Michael Fowler

On Wed, May 30, 2001 at 04:41:13PM -0700, John Milardovic wrote:
> for $var (@files)
> {
> print "$count++\t$var\n";
> }

I hope you weren't expecting $count to be incremented there.  ++ is not
interpolated.

Did you mean:

for $var (@files)
{
print $count++, "\t$var\n";
}



Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--



Re: Help recursing directories and java mod question

2001-05-30 Thread John Milardovic

Or ...

for $var (@files)
{
print "$count++\t$var\n";
}

HTH
John


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



doubt about do/until

2001-05-30 Thread Atul_Khot

Hi gurus,
In http://www.cpan.org/doc/FMTEYEWTK/is_numeric.html, ( Is it a 
number? ), Tom Christiansen writes:
--
If you do care about getting 0's, then do this: 
do { 
 print "Number, please: ";
 $answer = ;
 if ($answer == 0 && $answer ne '0') {
 print "Bad number\n";
 }
} until $answer;
--

I tried this with ActiveState perl version 5.005_03. I entered 0 and got a 
bad number. After thinking awhile, I chomped the $answer. This works for 
0,
( i.e. No "Bad number message"  and  the loop repeats ). I think we need a 
chomp there ( so instead of '0\n' ne '0', it is '0' ne '0' ). Is it so or 
am I missing something? 
 Thanks in advance,
Atul



Re: Why 'and' not '&&' ? (was Cleaning up 'uninitialized value')

2001-05-30 Thread Peter Scott

At 11:18 AM 5/30/01 -0700, Peter Cornelius wrote:
> > Use:
> >
> >   if (@ARGV and -T $ARGV[0]) { ... }
>
>Just wondering if there is a reason for using the lower precedence 'and'
>here instead of '&&'?  I haven't been finding many uses for 'and' which
>tells me I might not fully understand it.

The way I teach it is, I use && in expressions, and 'and' for (lazy ways 
of) changing the flow of control.  Yeah, I know there's no difference, but 
it reads nicer to me and the different precedences happen to minimize 
parenthesization for these usages.

So

 $user = $ENV{USER} || $ENV{USERNAME} || $ENV{LOGNAME};
 if ($flirting && $flouncing) { ... }

but

 open GRIMBLE, $plugh or die "open $plug: $!\n";
 $found = 1 and next if /$pattern/;

YMMV.

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Re: help with script

2001-05-30 Thread Michael Fowler

On Wed, May 30, 2001 at 03:57:44PM -0700, Peter Lemus wrote:
> Hi guys, I keep getting errors on the followin script.
> I need the script to logout all users other then root
> or ipl.
> 
>  1  #!/usr/bin/perl

As mentioned by John Joseph Trammell:
  #!/usr/bin/perl -w
  use strict

>  2  #
>  3  #Purpose: To logout users off the system during after hours.
>  4  #
>  5  open(STDERR,">/tmp/userlog.log") || die $!;
>  6  select (STDERR);
>  7  open(USERS, "/tmp/usersin") || die "can't open the USERS file: $!\n";

Good error checking, though that first die message could use some
elaboration.  E.g. die("Unable to open \"/tmp/userlog.log\": \l$!.\n");


>  8while () {
>  9  $user=split(//);
> 10   #  chomp $user;
> 11  print "$user\n";
> 12  # @user="root","ipl";
> 13if ($user eq root || $user > eq ipl) {

This should be:
if ($user eq 'root' || $user eq 'ipl') {

> 14   # chomp $user;
> 15print "user will NOT be logged out \n";
> 16}
> 17elseif

And here's the killer:
elsif {


> 18  # chomp $user;
> 19  @PIDS=`ps -ef | grep $user | grep -v grep | cut -b 10-14`;
> 20while (<@PIDS>){
> 21`kill $PIDS`;
> 22`kill -9, $PIDS`;
> 23 }
> 24   close (USERS);
> 25   close (STDERR);


> root@kerouac/export/shareux 372 >perl -w logout.pl
> "root" may clash with future reserved word at
> logout.pl line 13.
> "ipl" may clash with future reserved word at logout.pl
> line 13.
> "elseif" may clash with future reserved word at
> logout.pl line 17.
> syntax error in file logout.pl at line 19, next token
> "@PIDS"
> syntax error in file logout.pl at line 26, at EOF
> Execution of logout.pl aborted due to compilation
> errors.

Given the above diagnosis of your code, these errors should now make sense.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--



Re: Help recursing directories and java mod question

2001-05-30 Thread Michael Fowler

On Wed, May 30, 2001 at 04:00:53PM -0700, Steve Best wrote:
> But when I went to go print the elements of the array:
> 
> sub print_array {
>my($count) = 0;
>print "Printing array...\n";
>while (@files) {
> print "$count\t$files[$count]\n";
> $count++;
>};
> };
>
> It got stuck in an infinite loop.

That's because you're waiting for the number of elements in @files to be
zero, but doing nothing to remove elements.  It looks like you were trying
to do some iteration (with $count), but aren't checking $count.

You probably wanted:

while ($count < @files) {
print ...
$count++;
}

or perhaps

for (my $count = 0; $count < @files; $count++) {
print ...
}

or maybe

for (my $count = 0; @files; $count++) {
my $file = shift(@files);
print "$count\t$file\n";
}


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--



RE: Help recursing directories and java mod question

2001-05-30 Thread Steve Best

Yeah, I have these pages burned into my pupils by now, but I have been
unable to modify them to my needs.  I was able to get a little farther with
this:

sub find_class {
   use File::Find;
   sub finder {
return unless -f;
push (@files, $File::Find::name);
   };
   find (\&finder, $module);
};

But when I went to go print the elements of the array:

sub print_array {
   my($count) = 0;
   print "Printing array...\n";
   while (@files) {
print "$count\t$files[$count]\n";
$count++;
   };
};

It got stuck in an infinite loop.

Steve

-Original Message-
From: Peter Scott [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 30, 2001 3:53 PM
To: Steve Best; [EMAIL PROTECTED]
Subject: Re: Help recursing directories and java mod question


At 03:44 PM 5/30/01 -0700, Steve Best wrote:
>Howdy, I used to do a bit of Perl programming but its all washed away
>through disuse.  Sooo, I need to write a subroutine that will recurse from
a
>parent directory through all children directories, performing an action on
>files that match a pattern, in this case *.class.  I have the Perl
cookbook,
>but its not really helping me out right now.

Pages 318-324, recipes 9.5 thru 9.7 :-)
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com





Re: help with script

2001-05-30 Thread John Joseph Trammell

On Wed, May 30, 2001 at 03:57:44PM -0700, Peter Lemus wrote:
> Hi guys, I keep getting errors on the followin script.
> I need the script to logout all users other then root
> or ipl.
> 
>  1  #!/usr/bin/perl
>  2  #
>  3  #Purpose: To logout users off the system
> during after hours.
>  4  #
>  5  open(STDERR,">/tmp/userlog.log") || die $!;

This should start:

  #!/usr/bin/perl -w
  use strict;

J

-- 
IAAMOAC.



help with script

2001-05-30 Thread Peter Lemus

Hi guys, I keep getting errors on the followin script.
I need the script to logout all users other then root
or ipl.

 1  #!/usr/bin/perl
 2  #
 3  #Purpose: To logout users off the system
during after hours.
 4  #
 5  open(STDERR,">/tmp/userlog.log") || die $!;
 6  select (STDERR);
 7  open(USERS, "/tmp/usersin") || die "can't open
the USERS file: $!\n";
 8while () {
 9  $user=split(//);
10   #  chomp $user;
11  print "$user\n";
12  # @user="root","ipl";
13if ($user eq root || $user
eq ipl) {
14   # chomp $user;
15print "user will NOT be
logged out \n";
16
   }
17elseif
18  # chomp $user;
19  @PIDS=`ps -ef | grep $user | grep -v grep |
cut -b 10-14`;
20while (<@PIDS>){
21`kill $PIDS`;
22`kill -9, $PIDS`;
23 }
24   close (USERS);
25   close (STDERR);
"logout.pl" 25 lines, 798 characters 
root@kerouac/export/shareux 372 >perl -w logout.pl
"root" may clash with future reserved word at
logout.pl line 13.
"ipl" may clash with future reserved word at logout.pl
line 13.
"elseif" may clash with future reserved word at
logout.pl line 17.
syntax error in file logout.pl at line 19, next token
"@PIDS"
syntax error in file logout.pl at line 26, at EOF
Execution of logout.pl aborted due to compilation
errors.



=
Peter Lemus
UNIX/NT Networks Engineer
[EMAIL PROTECTED]

--This world is too big for us to be alone.
--A wise man will be master of his mind a fool will be its slave.

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: Help recursing directories and java mod question

2001-05-30 Thread Peter Scott

At 03:44 PM 5/30/01 -0700, Steve Best wrote:
>Howdy, I used to do a bit of Perl programming but its all washed away
>through disuse.  Sooo, I need to write a subroutine that will recurse from a
>parent directory through all children directories, performing an action on
>files that match a pattern, in this case *.class.  I have the Perl cookbook,
>but its not really helping me out right now.

Pages 318-324, recipes 9.5 thru 9.7 :-)
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Re: [meta] RE: On Beginners' Mindsets, Part II

2001-05-30 Thread Peter Scott

At 02:29 PM 5/30/01 -0400, Jeff Pinyan wrote:
> >I've given my share of one-liner answers, but based on this particular
> >thread, I personally am going to endeavor to inform others, as much as I
> >am able, rather than just "answer questions".
>
>I am all for enlightening and sharing knowledge.  Sometimes, that means
>pointing out the FAQ answer right in front of the poster's nose, if only
>to inform the poster that such magical and wondrous documentation exists
>and is easily accessible.

I could be wrong, but I think we're all in violent agreement 
here.  Certainly I didn't start the thread (which I do *not* want to turn 
into a flame war) for any reason other than to help newcomers learn Perl as 
easily and quickly as possible.

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Help recursing directories and java mod question

2001-05-30 Thread Steve Best

Howdy, I used to do a bit of Perl programming but its all washed away
through disuse.  Sooo, I need to write a subroutine that will recurse from a
parent directory through all children directories, performing an action on
files that match a pattern, in this case *.class.  I have the Perl cookbook,
but its not really helping me out right now.

Also, once it finds these files I will have my script run the java compiler
on them (javac).  Does anyone know if there is a perl java module that will
do this?

Thanks
Steve

IMPORTANT: This email is intended for the use of the individual addressee(s)
named above and may contain information that is confidential, privileged or
unsuitable for overly sensitive persons with low self-esteem, no sense of
humour or irrational religious beliefs. If you are not the intended
recipient, any dissemination, distribution or copying of this email is not
authorised (either explicitly or implicitly) and constitutes an irritating
social faux pas.

Unless the word absquatulation has been used in its correct context
somewhere other than in this warning, it does not have any legal or no
grammatical use and may be ignored. No animals were harmed in the
transmission of this email, although the kelpie next door is living on
borrowed time, let me tell you. Those of you with an overwhelming fear of
the unknown will be gratified to learn that there is no hidden message
revealed by reading this warning backwards, so just ignore that Alert Notice
from Microsoft.

However, by pouring a complete circle of salt around yourself and your
computer you can ensure that no harm befalls you and your pets. If you have
received this email in error, please add some nutmeg and egg whites, whisk
and place in a warm oven for 40 minutes.





Re: Problems with Net::SSLeay

2001-05-30 Thread Peter Scott

At 03:37 PM 5/30/01 -0700, I wrote:
>At 01:25 PM 5/30/01 -0500, you wrote:
>>Peter,
>>
>>I did what you suggested and here are the results.  I'm going to upgrade 
>>to OpenSSL-0.9.6a and then try it again.
>>
>>Any other suggestions?
>
>Fraid not.  This kind of thing is a bear.  I'd be checking whether my 
>OpenSSL passed all *its* tests at this point.  Upgrading is a good bet.  I 
>recently built this combo successfully on RH Linux 6.2 and Solaris 2.5.1 
>and 2.6, FWIW.
>
>>Kevin

Just got a message from Kevin that the OpenSSL upgrade fixed it, so never mind.

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Re: Problems with Net::SSLeay

2001-05-30 Thread Peter Scott

At 01:25 PM 5/30/01 -0500, you wrote:
>Peter,
>
>I did what you suggested and here are the results.  I'm going to upgrade 
>to OpenSSL-0.9.6a and then try it again.
>
>Any other suggestions?

Fraid not.  This kind of thing is a bear.  I'd be checking whether my 
OpenSSL passed all *its* tests at this point.  Upgrading is a good bet.  I 
recently built this combo successfully on RH Linux 6.2 and Solaris 2.5.1 
and 2.6, FWIW.

>Kevin
>
>
>  CPAN.pm: Going to build S/SA/SAMPO/Net_SSLeay.pm-1.07.tar.gz
>
>Checking for OpenSSL-0.9.6a or newer...
>You have OpenSSL-0.9.3a installed in /usr/local/ssl
>Checking if your kit is complete...
>Looks good
>Writing Makefile for Net::SSLeay
>mkdir blib
>mkdir blib/lib
>mkdir blib/lib/Net
>mkdir blib/arch
>mkdir blib/arch/auto
>mkdir blib/arch/auto/Net
>mkdir blib/arch/auto/Net/SSLeay
>mkdir blib/lib/auto
>mkdir blib/lib/auto/Net
>mkdir blib/lib/auto/Net/SSLeay
>mkdir blib/man3
>cp SSLeay.pm blib/lib/Net/SSLeay.pm
>AutoSplitting blib/lib/Net/SSLeay.pm (blib/lib/auto/Net/SSLeay)
>blib/lib/Net/SSLeay.pm: some names are not unique when truncated to 8 
>characters:
>directory blib/lib/auto/Net/SSLeay:
>  ssl_read_all.al, ssl_read_until.al, ssl_read_CRLF.al truncate to ssl_read
>  ssl_write_all.al, ssl_write_CRLF.al truncate to ssl_writ
>/usr/local/bin/perl -I/usr/local/lib/perl5/5.6.0/i686-linux 
>-I/usr/local/lib/perl5/5.6.0 /usr/local/lib/perl5/5.6.0/ExtUtils/xsubpp
>-typemap /usr/local/lib/perl5/5.6.0/ExtUtils/typemap -typemap typemap 
>SSLeay.xs > SSLeay.xsc && mv SSLeay.xsc SSLeay.c
>cc -c -I/usr/local/ssl/include -fno-strict-aliasing -D_LARGEFILE_SOURCE 
>-D_FILE_OFFSET_BITS=64 -O2 -DVERSION=\"1.07\" -DXS_VERSION=\"1.07\" 
>-fpic -I/usr/local/lib/perl5/5.6.0/i686-linux/CORE  SSLeay.c
>Running Mkbootstrap for Net::SSLeay ()
>chmod 644 SSLeay.bs
>LD_RUN_PATH="/usr/local/ssl/lib" cc -o blib/arch/auto/Net/SSLeay/SSLeay.so
>-shared -L/usr/local/lib SSLeay.o-L/usr/local/ssl -L/usr/local/ssl/lib 
>-lssl -lcrypto
>chmod 755 blib/arch/auto/Net/SSLeay/SSLeay.so
>cp SSLeay.bs blib/arch/auto/Net/SSLeay/SSLeay.bs
>chmod 644 blib/arch/auto/Net/SSLeay/SSLeay.bs
>Manifying blib/man3/Net::SSLeay.3
>  /usr/bin/make  -- OK
>Running make test
>PERL_DL_NONLAZY=1 /usr/local/bin/perl -Iblib/arch -Iblib/lib 
>-I/usr/local/lib/perl5/5.6.0/i686-linux -I/usr/local/lib/perl5/5.6.0 test.pl
>1..16
>Can't load 'blib/arch/auto/Net/SSLeay/SSLeay.so' for module Net::SSLeay: 
>blib/arch/auto/Net/SSLeay/SSLeay.so: undefined symbol: md5_block_x86 at 
>/usr/local/lib/perl5/5.6.0/i686-linux/DynaLoader.pm line 200.
>at test.pl line 19
>Compilation failed in require at test.pl line 19.
>BEGIN failed--compilation aborted at test.pl line 19.
>make: *** [test_dynamic] Error 255
>  /usr/bin/make test -- NOT OK
>
>
>
>>From: Peter Scott <[EMAIL PROTECTED]>
>>To: "K Old" <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
>>Subject: Re: Problems with Net::SSLeay
>>Date: Tue, 29 May 2001 10:47:25 -0700
>>
>>At 11:39 AM 5/29/01 -0500, K Old wrote:
>>
>>>Can't load
>>>'/usr/local/lib/perl5/site_perl/5.6.0/i686-linux/auto/Net/SSLeay/SSLeay.so'
>> > for module Net::SSLeay:
>>>/usr/local/lib/perl5/site_perl/5.6.0/i686-linux/auto/Net/SSLeay/SSLeay.so:
>>>undefined symbol: md5_block_x86 at
>>>/usr/local/lib/perl5/5.6.0/i686-linux/DynaLoader.pm line 200.
>>>at ./bill.pl line 168
>>>Compilation failed in require at ./bill.pl line 168.
>>>BEGIN failed--compilation aborted at ./bill.pl line 168.
>>>
>>>Any ideas what I'm to do now?
>>>
>>>I installed Net::SSLeay using CPAN so I don't think the installation is bad.
>>
>>I do.  I suggest you build it again; do a "force test Net::SSLeay" and see
>>if there are any warnings or errors, show them to us.  Are you building
>>against the latest OpenSSL?
>>--
>>Peter Scott
>>Pacific Systems Design Technologies
>>http://www.perldebugged.com
>
>_
>Get your FREE download of MSN Explorer at http://explorer.msn.com

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




RE: On Beginners' Mindsets, Part II

2001-05-30 Thread Peter Scott

A private correspondent wrote:
>BUT... when the
>code is posted for all to see, it gives the rest of us ideas of how to
>handle such problems.

Ah, that reminds me of a mini pearl of wisdom I wanted to put out there 
:-)  Maybe it should go in the FAQ...

Several people have replied to just me when I send a response to the 
list.  Folks, it's better to copy the list on everything except obviously 
personal correspondence.  Other people can benefit from the exchange or 
should have a chance to contribute.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Hash with multiple values per key

2001-05-30 Thread Ravi Channavajhala

Hi,

Does anyone have a nifty way to do a sort and comparison
of two or more hash keys with multiple values per key?

I am building a hash with

push (@{$a{$b}},$c);

$b keeps changing, lets say in first instance it is "1" and
"2" in second instance, and each instance has multiple values,
e.g, instance "1" has "c1 c2 c3" and instance "2" has "c1 c2 c3
c4 c5".  What's the easiest way to iterate through the hash and
compare each instance values and print the differences?  Thanks
for any answers.  In the above case, I like to see c4 and c5 as
the values different from instance "1" to instance "2".

-ravi




Re: Hash with multiple values per key

2001-05-30 Thread Paul


--- Ravi Channavajhala <[EMAIL PROTECTED]> wrote:
> Hi,

Howdy.

> Does anyone have a nifty way to do a sort and comparison
> of two or more hash keys with multiple values per key? 
> I am building a hash with
> 
> push (@{$a{$b}},$c);

Okay; %a is the hash, and each entry in the hash is an array, named
with the value of $b at the time of the push(). $c is the value you're
pushing onto the appropriate stack. I'm with you so far.

> $b keeps changing, lets say in first instance it is "1" and
> "2" in second instance, and each instance has multiple values,

So every entry has more than one element, but not a consistent number.

> e.g, instance "1" has "c1 c2 c3" and instance "2" has "c1 c2 c3

No. $a{1} might have ('c1','c2','c3'), or it's first element might be 
"c1 c2 c3", but for clarity's sake, let's say ('c1','c2','c3'). These
three values are the elements of the array stored at $a{1}, right?
The $a{2} is ('c1','c2','c3','c4','c5') ?

> c4 c5".  What's the easiest way to iterate through the hash and
> compare each instance values and print the differences?  Thanks
> for any answers.  In the above case, I like to see c4 and c5 as
> the values different from instance "1" to instance "2".

Hmm.

That sounds pretty specific, though I'd expect that you'd want more
flexibility. Do you just want to walk the limbs of your "tree" and see
which "leaves" differentiate? That could be implemented so many ways,
that are *so* different. You probably need to post more specific
examples, maybe some of the code that you have. There may be a much
easier way to accomplish your end goal. What is it that you're actually
trying to get done in the end?

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: test for real number

2001-05-30 Thread Carl Rogers

Good day;

try:::
if ($input =~ /\d+\.?\d+/){
xxx

}
The intent here is:
 \d+ ##one or more digits
 \.?  ##followed by zero or one "." (there is a dot there)
 \d+ ##followed by one or more digits.

I think this will work. Depending on how your reals will be input, you can 
tweak the \d to suit your needs.
Hope this helps/works.
Carl

At 01:56 PM 5/30/2001 -0700, you wrote:
>Hi,
>I'm new to the group and new to Perl and am very glad to have such a 
>resource available. Hopefully someday I'll be on the giving end of the 
>help list but for now I'm stumped. How do I test an input to see if it is 
>a real number?  I have a situation something like:
>
>  $input = ;
> chomp $input;
>
>if (input equals a real number) {
> xx
>}
>else {
>
>}
>best, michael




Re: Hash with multiple values per key

2001-05-30 Thread Jeff Pinyan

On May 30, Ravi Channavajhala said:

>Does anyone have a nifty way to do a sort and comparison of two or more
>hash keys with multiple values per key?

>push (@{$a{$b}},$c);

>$b keeps changing, lets say in first instance it is "1" and
>"2" in second instance, and each instance has multiple values,
>e.g, instance "1" has "c1 c2 c3" and instance "2" has "c1 c2 c3
>c4 c5".  What's the easiest way to iterate through the hash and
>compare each instance values and print the differences?  Thanks
>for any answers.  In the above case, I like to see c4 and c5 as
>the values different from instance "1" to instance "2".

If you want to compute the difference between two lists, there are some
very nifty ways to do this in Perl.

  perldoc -q intersection

And here's a write-up I did for PerlMonks.org:

  http://www.perlmonks.org/index.pl?node_id=82149

You would use my difference() function like so:

  @diff = difference($a{$key1}, $a{$key2});

where $a{$key1} and $a{$key2} are hash values that hold array
references.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**I no longer need a publisher for my Perl Regex book :)**





Re: test for real number

2001-05-30 Thread Jeff Pinyan

On May 30, [EMAIL PROTECTED] said:

>I'm new to the group and new to Perl and am very glad to have such a 
>resource available. Hopefully someday I'll be on the giving end of the 
>help list but for now I'm stumped. How do I test an input to see if it 
>is a real number?  I have a situation something like:

I suggest you look at the FAQ entry for 'float' (perldoc -q float), and at
Tom Christiansen's "Far More Than You Ever Wanted To Know" (FMTYEWTK) doc
on this same question:

  http://www.cpan.org/doc/FMTEYEWTK/is_numeric.html

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**I no longer need a publisher for my Perl Regex book :)**




Re: test for real number

2001-05-30 Thread Paul


--- [EMAIL PROTECTED] wrote:
> help list but for now I'm stumped. How do I test an input to see if
> it is a real number?  I have a situation something like:

By "real number", exactly what do you mean?
Do you mean a decimal fraction without characters other than
0123456789.+- or do you want to include E for exponentiation? Is
whitespace allowed before or after?

There are several ways to test it, but a lot of them break easily.

You could just say

>   $input = ;
>   chomp $input;
unless ($input =~ /\D/) {

which would allow integers, but whitespace, decimals, commas, or signs
would all fail. More complex patterns could test all that, but is that
what you want?

Can you give us specs for the desired behavior? =o)

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: qw

2001-05-30 Thread Paul


--- Nichole Bialczyk <[EMAIL PROTECTED]> wrote:
> i'm trying to work my way throuh an existing script and it says
> @array = qw("stuff", "more stuff", "even more stuff");

That looks like a typo, though they may have actually wanted the quotes
and commas in the strings if you run that under -w, it'll complain.

By the way, have we mentioned that you should always use strict.pm and
the -w switch? =o) lol
 
> what does the qw do?

qw is the "Quote-Word" operator for perl. c.f. perldoc perlop

qw takes a list of whitespace-delimited strings and quotes them as if
they were each in singleticks. For example:

  @array = qw / a b c d e /;

creates an array of the alphabet's first 5 letters.
The slash isn't magical here; it's just one possible bounding
character. You can use matching pairs () {} <> [] or other things like
/ if those aren't convenient. 

So, to paraphrase the above,
 @array = qw( stuff moreStuff evenMoreStuff );

makes an array of those three elements, but the literal value above
would yield:
  "stuff",
  "more
  stuff",
  "even
  more
  stuff"

Notice that the quotes and commas are part of the strings, and that
"even more stuff" got split into three seperate elements of the array.

Does that help?
Is that the actual code you're looking at?
If not, post it, and let's take it apart! lol



__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: test for real number

2001-05-30 Thread Walt Mankowski

On Wed, May 30, 2001 at 01:56:40PM -0700, [EMAIL PROTECTED] wrote:
> How do I test an input to see if it is a real number?

$ perldoc -q float 

Found in /usr/local/lib/perl5/5.6.1/pod/perlfaq4.pod
 How do I determine whether a scalar is a
 number/whole/integer/float?

 Assuming that you don't care about IEEE notations like "NaN"
 or "Infinity", you probably just want to use a regular
 expression.

if (/\D/){ print "has nondigits\n" }
if (/^\d+$/) { print "is a whole number\n" }
if (/^-?\d+$/)   { print "is an integer\n" }
if (/^[+-]?\d+$/){ print "is a +/- integer\n" }
if (/^-?\d+\.?\d*$/) { print "is a real number\n" }
if (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { print "is a decimal number" }
if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)
 { print "a C float" }

 If you're on a POSIX system, Perl's supports the
 "POSIX::strtod" function.  Its semantics are somewhat
 cumbersome, so here's a "getnum" wrapper function for more
 convenient access.  This function takes a string and returns
 the number it found, or "undef" for input that isn't a C
 float.  The "is_numeric" function is a front end to "getnum"
 if you just want to say, ``Is this a float?''

 sub getnum {
 use POSIX qw(strtod);
 my $str = shift;
 $str =~ s/^\s+//;
 $str =~ s/\s+$//;
 $! = 0;
 my($num, $unparsed) = strtod($str);
 if (($str eq '') || ($unparsed != 0) || $!) {
 return undef;
 } else {
 return $num;
 }
 }

 sub is_numeric { defined getnum($_[0]) }

 Or you could check out the String::Scanf module on CPAN
 instead.  The POSIX module (part of the standard Perl
 distribution) provides the "strtod" and "strtol" for
 converting strings to double and longs, respectively.


-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: qw

2001-05-30 Thread Walt Mankowski

On Wed, May 30, 2001 at 03:38:35PM -0500, Nichole Bialczyk wrote:
> i'm trying to work my way throuh an existing script and it says
> 
> @array = qw("stuff", "more stuff", "even more stuff");
> 
> what does the qw do?

In your example, it's a broken way of trying to say:

$array[0] = "stuff";
$array[1] = "more stuff";
$array[2] = "even more stuff";

I say broken because qw splits on whitespace, so what you really get
here is:

$array[0] = '"stuff";'
$array[1] = '"more';
$array[2] = 'stuff";'
$array[3] = '"even';
$array[4] = 'more';
$array[5] = 'stuff";';

qw is a shorthand way of initializing an array with individual words,
because it saves you the trouble of having to type all the quotes and
commas.  For example,

@array = qw(stuff more stuff even more stuff);

gives you

$array[0] = "stuff";
$array[1] = "more";
$array[2] = "stuff";
$array[3] = "even";
$array[4] = "more";
$array[5] = "stuff";

But if you need to initialize the array with strings that have
embedded whitespace, then you've got to do it the long way with all
the quotes and commas.  In your example, all you have to do is drop
the qw:

@array = ("stuff", "more stuff", "even more stuff");

Walt

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Hash with multiple values per key

2001-05-30 Thread Ravi Channavajhala

Hi,

Does anyone have a nifty way to do a sort and comparison
of two or more hash keys with multiple values per key?

I am building a hash with

push (@{$a{$b}},$c);

$b keeps changing, lets say in first instance it is "1" and
"2" in second instance, and each instance has multiple values,
e.g, instance "1" has "c1 c2 c3" and instance "2" has "c1 c2 c3
c4 c5".  What's the easiest way to iterate through the hash and
compare each instance values and print the differences?  Thanks
for any answers.  In the above case, I like to see c4 and c5 as
the values different from instance "1" to instance "2".

-ravi





RE: qw

2001-05-30 Thread Jeffrey Goff

Yep,caught that myself a few minutes -after- sending email. Apologies.

-Original Message-
From: Jeff Pinyan [mailto:[EMAIL PROTECTED]]
On May 30, Jeffrey  Goff said:

>It's a shortcut for assigning words to an array. That statement would
return
>an array that looks roughly like this:
>
>('"stuff",', '"more stuff",', '"even more stuff"') # Note the double
quotes.

Nope, no matter what you do, qw() really splits on whitespace.



test for real number

2001-05-30 Thread mikemckee

Hi,
I'm new to the group and new to Perl and am very glad to have such a 
resource available. Hopefully someday I'll be on the giving end of the 
help list but for now I'm stumped. How do I test an input to see if it 
is a real number?  I have a situation something like:

  $input = ;
chomp $input;

if (input equals a real number) {
 xx
}
else {

}
best, michael



RE: qw

2001-05-30 Thread Jeff Pinyan

On May 30, Jeffrey  Goff said:

>It's a shortcut for assigning words to an array. That statement would return
>an array that looks roughly like this:
>
>('"stuff",', '"more stuff",', '"even more stuff"') # Note the double quotes.

Nope, no matter what you do, qw() really splits on whitespace.

  friday:~ $ perl -w
  @a = qw( "stuff", "more stuff", "even more stuff" );
  Possible attempt to separate words with commas at - line 1. <-- warning
  for (@a) { print "<$_>\n" }
  __END__

  <"stuff",>
  <"more>
  
  <"even>
  
  

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**I no longer need a publisher for my Perl Regex book :)**




Re: qw

2001-05-30 Thread Michael Fowler

On Wed, May 30, 2001 at 03:38:35PM -0500, Nichole Bialczyk wrote:
> i'm trying to work my way throuh an existing script and it says
> 
> @array = qw("stuff", "more stuff", "even more stuff");
> 
> what does the qw do?

perldoc perlop:
   qw/STRING/
   Returns a list of the words extracted out of
   STRING, using embedded whitespace as the word
   delimiters.  It is exactly equivalent to

   split(' ', q/STRING/);


In this case, qw is being misused.  The code there is equivalent to:

$array[0] = '"stuff",'  ;
$array[1] = '"more' ;
$array[2] = 'stuff",'   ;
$array[3] = '"even' ;
$array[4] = 'more'  ;
$array[5] = 'stuff"';

What was probably intended is the equivalent of:

$array[0] = "stuff"  ;
$array[1] = "more stuff" ;
$array[2] = "even more stuff";

In which case the qw should just be dropped, the quoting is sufficient.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--



RE: qw

2001-05-30 Thread Larry Shatzer

Here is the documentation on it. 
( http://www.perldoc.com/perl5.6/pod/perlop.html#qw%2fSTRING%2f )

qw/STRING/ 
Evaluates to a list of the words extracted out of STRING, using embedded
whitespace as the word delimiters. It can be understood as being roughly
equivalent to:

split(' ', q/STRING/);
the difference being that it generates a real list at compile time. So this
expression:

qw(foo bar baz)
is semantically equivalent to the list:

'foo', 'bar', 'baz'
Some frequently seen examples:

use POSIX qw( setlocale localeconv )
@EXPORT = qw( foo bar baz );
A common mistake is to try to separate the words with comma or to put
comments into a multi-line qw-string. For this reason, the use warnings
pragma and the -w switch (that is, the $^W variable) produces warnings if
the STRING contains the "," or the "#" character.


> -Original Message-
> From: Nichole Bialczyk [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 30, 2001 1:39 PM
> To: [EMAIL PROTECTED]
> Subject: qw
> 
> 
> i'm trying to work my way throuh an existing script and it says
> 
> @array = qw("stuff", "more stuff", "even more stuff");
> 
> what does the qw do?
> 
> thanks, nichole
> 



RE: qw

2001-05-30 Thread Jeffrey Goff

It's a shortcut for assigning words to an array. That statement would return
an array that looks roughly like this:

('"stuff",', '"more stuff",', '"even more stuff"') # Note the double quotes.

Something like ("stuff","more stuff","even more stuff"); # was likely
intended, without qw().

Search for 'qw/STRING/' in perlop perldoc for more information.

-Original Message-
From: Nichole Bialczyk [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 30, 2001 4:39 PM
To: [EMAIL PROTECTED]
Subject: qw


i'm trying to work my way throuh an existing script and it says

@array = qw("stuff", "more stuff", "even more stuff");

what does the qw do?

thanks, nichole



qw

2001-05-30 Thread Nichole Bialczyk

i'm trying to work my way throuh an existing script and it says

@array = qw("stuff", "more stuff", "even more stuff");

what does the qw do?

thanks, nichole



Re: regexp Help

2001-05-30 Thread Craig Moynes/Markham/IBM

from your small code sample everything checks out.
I would be inclined to ensure that the parameter is being read in correctly
with no trailing spaces or strange characters.

If you need more help send a bigger code sample for us to peruse.

-
Craig Moynes
[EMAIL PROTECTED]



   

"Kyrytow,  

Stefan"  To: "Perl (E-mail)" <[EMAIL PROTECTED]>  

   Subject: regexp Help  

   

05/30/01 12:38 

PM 

   

   




If someone could please help me.

I can't figure out how to use a variable in a regexp.

Example.
I am writing a script to parse a web log and report on all the hosts in the
log.
However I have a command line option to exclude a domain from the report.
My problem is that I can't figure out how to use the inputed value in a
regexp.

Log Format
host.domain.com

I want to be able to exclude domain.com

I have tried:
while( $exclude_domain !~ /$host/ ) { ... }

Any help is appreciated.

STEFAN KYRYTOW
EDS CANADA
Leveraged Platform Solution Centre
t 416.814.4911
p 416.517.2252
[EMAIL PROTECTED]








RE: Email question

2001-05-30 Thread Robin Lavallee (LMC)


> -Original Message-
> From: Gross, Stephan [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, May 30, 2001 1:12 PM
> To:   'Beginner Perl'
> Subject:  Email question
> 
> I'd like to a write a program that would tell me, for several specific
> accounts/mailboxes on a Microsoft Exchange server, how many emails are
> there.  I can use either POP3 or IMAP protocols.  Any suggestions or
> pointers?
> 
I had success with the Mail::IMAPClient module.
For the number of emails in a mailbox, look at
the function message_count().

-Robin

>  



Re: regexp Help

2001-05-30 Thread Stephen P. Potter

Lightning flashed, thunder crashed and "Kyrytow, Stefan" <[EMAIL PROTECTED]
m> whispered:
| Example.
| I am writing a script to parse a web log and report on all the hosts in the
| log.
| However I have a command line option to exclude a domain from the report.
| My problem is that I can't figure out how to use the inputed value in a
| regexp.
| 
| Log Format
| host.domain.com
| 
| I want to be able to exclude domain.com
| 
| I have tried:
| while( $exclude_domain !~ /$host/ ) { ... }

Without a better explanation of your exact problem, I think you have this
backwards from what you really want.  Try

while ($host !~ /$exclude_domain/) { ... }

In other words, if the hostname doesn't contain the excluded domain do
whatever.

-spp



Re: Why 'and' not '&&' ? (was Cleaning up 'uninitialized value')

2001-05-30 Thread Stephen P. Potter

Lightning flashed, thunder crashed and Peter Cornelius  whispered:
| > Use:
| > 
| >   if (@ARGV and -T $ARGV[0]) { ... }
| 
| Just wondering if there is a reason for using the lower precedence 'and'
| here instead of '&&'?  I haven't been finding many uses for 'and' which
| tells me I might not fully understand it.

In this particular case, not really.  Other than Jeff prefers to.

Understanding precidence levels and determining which is the best choice is
often a case of individual preference.

-spp



RE: On Beginners' Mindsets, Part II

2001-05-30 Thread Paul


--- "Wilson, Tom" <[EMAIL PROTECTED]> wrote:
> My two cents sometimes getting the answer is more important that
> learning it right away.  There are many times in the various
> languages that I've worked with that I've gotten the answer and later
> on remembered the solution and incorporated it into something new
once
> I understood it.

Absolutely. Often, an elegant 3-line solution is much easier than the
20 lines of code that would be clearer, and doesn't cost the instructor
much to offer. saying "use my" is easy, even though the person with the
problem might not grasp the differences between namespace and scope for
a long time.

The only caveat is that that person *must* make the effort to grasp it.
If they don't learn things like context, scope, namespace, etc.,
they'll never be able to write anything more complex without someone
holding their hand. On the other hand, a real *understanding* of
references and scopes and namespaces is 90% of all you need to make
complicated object modules.

Personally, I think it's important to stroke the ego of the teacher a
little. We ask and offer solutions in hubris, and forget that there is
time required by the person on the other end. If someone asks for an
explanation, I'll spend a half-hour writing example code and explaining
it. If they say "never mind how it works, just build be a thingamahicky
that will make my code do what I want", I'll probably not waste the
time it would take to direct them to a consultant who will do exactly
that for $50/hr. (if they're lucky)

By the same token, if I sit down to explain something, I try to keep in
mind that the person on the other end may not care about what's under
the hood, but even if he doesn't, someone *else* might benefit from the
time. =o) Quite a few of the people on this list aren't exactly
"beginners", though many posters are. I'll say that I've certainly
learned a lot, and had a couple of myths dispelled. ;o]

Anyway, I think (hope? lol...) this thread is winding down.
It keeps producing long posts like this one, that might help someone
ask for help more effectively, but aren't realy helping anyone learn
Perl..

So -- who's up for a discussion of objects? ~chuckle~ 

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



[OT} Re: Sleeping for less than a second

2001-05-30 Thread Jeff Pinyan

On May 30, Walt Mankowski said:

>On Wed, May 30, 2001 at 01:47:55PM -0400, Jeff Pinyan wrote:
>> =head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq8.pod
>
>Looks like you're overdue for an upgrade... :-)

Not my machine, it's just the ISP I used to work at -- I have a shell
account there now.  They've got 5.005 on the production server, and 5.6.0
and another one.

At work, we have 5.005_03 and 5.6.0

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **




[meta] RE: On Beginners' Mindsets, Part II

2001-05-30 Thread Jeff Pinyan

On May 30, Wilson, Tom said:

>My two cents sometimes getting the answer is more important that
>learning it right away.  There are many times in the various languages that
>I've worked with that I've gotten the answer and later on remembered the
>solution and incorporated it into something new once I understood it.  

I don't mind giving answers as long as you know how to apply them if
they're too generic, and you know HOW I'm solving your problem.

Take the common question of "how can I get unique elements from a
list?"  You can do it slowly, by using two arrays:

  ORIG: for my $o (@original) {
for (@unique) {
  next ORIG if $_ eq $o;
}
push @unique, $o;
  }

Or even worse[1], using grep:

  for my $o (@original) {
push @unique, $o unless grep $_ eq $o, @unique;
  }

The idiomatic Perl approach is to use a hash; store the elements
of the list as the keys in the hash, since a hash's keys are unique.
There are several approaches, really:

  # works because $x++ is POST-increment, so it returns $x first, and THEN
  # increments it.  so if !$seen{$_}++ is true, that means $seen{$_}
  # wasn't true (because the key $_ hasn't been seen yet)

  @unique = grep !$seen{$_}++, @original;


  # this is pretty much the same as above, but more drawn out

  for (@original) {
next if $seen{$_};
$seen{$_} = 1;
push @unique, $_;
  }


  # hash slices are nifty-keen, but this approach loses the order of the
  # elements (if that was important to you)

  @seen{@original} = ();
  @unique = keys %seen;

See, I would make sure you knew what I was giving you.  There's nothing
worth than spoonfeeding a baby gruel, if neither the parent nor the child
knows what's inside (and it's better if the baby likes it).

In addition, if you said "no, japhy, I meant, I don't want to keep the
element if it appears more than once," then I would expect you to be able
to craft a working solution from the ones shown.

  @original = (2,5,4,2,6,5,3,7,6);
  # solution...
  @unique = (4,3,7);

If you're curious how to do that, let me give you an hint:  the first
solution I showed for unique-ness can be molded slightly to provide a
count of each element:

  $count{$_}++ for @original;
  
That's all for now.



[1] The grep() method is worse because it doesn't stop after finding a
match, it goes through the entire array.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **




Re: Sleeping for less than a second

2001-05-30 Thread Walt Mankowski

On Wed, May 30, 2001 at 01:47:55PM -0400, Jeff Pinyan wrote:
> =head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq8.pod

Looks like you're overdue for an upgrade... :-)

Walt

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: Why 'and' not '&&' ? (was Cleaning up 'uninitialized value')

2001-05-30 Thread Paul


--- Peter Cornelius <[EMAIL PROTECTED]> wrote:
> > Use:
> >   if (@ARGV and -T $ARGV[0]) { ... }
> 
> Just wondering if there is a reason for using the lower precedence
> 'and' here instead of '&&'?  I haven't been finding many uses for
> 'and' which tells me I might not fully understand it.

I've almost never written code that used && in perl.
'and' has a lower precedence, which is usually what you want with
boolean expressions. It lets you write the same syntax with less line
noise.

  if ($a = func() and $b) { # assigns $a from func(), then checks $b

does something different than

  if ($a = func() && $b) {  # assigns $a from (func() && $b) compare

Not that assignments in if's come highly recommended, but I have used
them

Also, while a lot of C programmers tend to try doing things in the
familiar fashion, I believe 'and' is a lot more readable than '&&',
which is a plus, and it also helps you remember this is Perl, not C.
The same mentality that hangs onto && will write

  for(my $i=0; $i<10; $i++) { print $i }

when it's much cleaner, clearer, and more efficient to write

  for my $i (0..9) { print $i }

and to my mind, even better to say

  print for 0..9;

Why the different structures?
Because everyone does it differently.
Perl doesn't make you abandon one for another, but each has its
advantages



__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: Why 'and' not '&&' ? (was Cleaning up 'uninitialized value')

2001-05-30 Thread Jeff Pinyan

On May 30, Peter Cornelius said:

>>   if (@ARGV and -T $ARGV[0]) { ... }
>
>Just wondering if there is a reason for using the lower precedence 'and'
>here instead of '&&'?  I haven't been finding many uses for 'and' which
>tells me I might not fully understand it.

You must be careful about using operators like '&&' and their
lower-precedence companions like 'and'.  I tend to use the spelled out
ones more often, except where it would require machinations to ensure the
proper execution of code:

  $x = $foo || $bar;  # that's ok
  $x = $foo or $bar;  # like:  ($x = $foo) || $bar

That second case is due to 'or' having lower precedence than '='.  You'd
have to do

  $x = ($foo or $bar);

It is at that point that I would decide not to use 'or'.  On the other
hand, I'd rather do

  open FOO, $file or die "...";

instead of

  open(FOO, $file) || die "...";

or even worse,

  open FOO, $file || die "...";  # like open FOO, ($file || die "...");

I prefer to de-line-noise my programs for readability[1].  As such, I use
parens only where needed.



[1] And yet, I love to use regexes... something for you to discuss among
yourselves, I guess.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **





RE: On Beginners' Mindsets, Part II

2001-05-30 Thread Wilson, Tom
I am a beginning Perl programmer and really enjoy the Perl mail lists.
While I don't understand everything that is written about here, I've saved
notes that I'll understand down the road.

My two cents sometimes getting the answer is more important that
learning it right away.  There are many times in the various languages that
I've worked with that I've gotten the answer and later on remembered the
solution and incorporated it into something new once I understood it.  

To the more experienced, please keep it coming  I know that there isn't
an easy path to learning Perl.

Regards,

Tom Wilson

-Original Message-
From: Scott Thompson [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 30, 2001 2:07 PM
To: [EMAIL PROTECTED]
Subject: RE: On Beginners' Mindsets, Part II


> -Original Message-
> From: Jeff Pinyan [mailto:[EMAIL PROTECTED]]
> Subject: Re: On Beginners' Mindsets, Part II
>
> On May 30, Peter Scott said:
>
> >*Curiosity* is an essential trait for the programmer.  In all
> seriousness,
> >if you don't have a deep desire to find out how things work - in
> >particular, software - this may not be the field for you.  Principally
> >because our tools are rarely so perfect at encapsulation that they
> >completely hide the underlying mechanism, therefore, it is necessary to
> >understand the underlying mechanism and to want to get at it.
>
> Curiosity without motivation is a bane, as I am sure those of us who have
> been sitting in IRC channels and on mailing lists, for the purposes of
> ANSWERING questions, are well aware.  People that ask questions because
> they need the answer, not because they want to learn the answer, are not
> helpful programmers in the long run -- they know only what they've been
> spoonfed, and have trouble formulating code or applying algorithms
> themselves.  They also have trouble explaining the code they cut and paste
> from Joe Coder's program.
>

While I couldn't agree more with both statements, I think it is the
unfortunate reality that, with the recent (last 2 years... ) boom and
subsequent bust of the Internet economy at large, there is a growing
majority of beginning programmers who will fall into the "grab and go"
mindset.
Now, let me assure recent posters to this list that I am in no way
targeting anyone in particular with that statement.  Rather, I am speaking
from my own experience in the local job market.  I certainly do not -- and
never WILL -- claim to be any kind of "expert" in Perl or any other
language.  As Peter pointed out, I am always learning so, in that regard, I
don't think there ARE any Perl "experts" -- just someone who has learned
more about something you have not. :)
And that brings me back around to my point.  With the recent need
for Perl
hackers (among other related disciplines... ), a budding programmer didn't
need to be an "expert" to land a high-paying, high-profile web development
job.  The demand far exceeded the supply.  So, suddenly, you have relatively
inexperienced beginners needing to produce results within a start-up's time
frame.  So instead of seeking knowledge for the sake of knowledge, you have
an inordinate number of "greenhorns" looking for just enough information to
get the job done.
I even saw evidence of this attitude in the sudden addition of
Internet-related IT degrees at local colleges.  Here was this sudden demand
for "trained IT professionals," so schools started putting together
curricula willy-nilly to fill that demand.  I knew of one student, a junior
in high school, who became Cisco Certified as part of an Advanced Placement
IT curriculum a year ago.  That's great for her -- but based on what she
told me about the "class" she was taking, they were studying from material
designed to pass the exam, not material covering the core technologies
involved.  I personally worked 1.5 years for a local consulting firm whose
clients are now having to go back and hire other consultants to come in and
fix the mess left behind by the previous consultants.  Again, because those
original consultants lacked enough in depth knowledge to fully realize the
entirety of the project and all the development nuances necessary.
Other than to vent my own frustrations :), my point is this.
Because of
the influx of "new blood" there are quite a few beginning programmers who
have not had the opportunity to REALLY learn the language they were hired to
code in.  And, because of the subsequent economic curve ball thrown to the
IT industry at large, many of those budding JAPH's have a decision -- stay
in the game or leave.  Rather than complain about those who just "ask
questions because they need the answer, not because they want to learn the
answer," we as seasoned Perl programmers have the opportunity to pass on our
love and enthusiasm for Perl and programming in general to those willing to
embrace it.
I've given my share of one-liner answers, but based on this
particular
thread, I 

[meta] RE: On Beginners' Mindsets, Part II

2001-05-30 Thread Jeff Pinyan

On May 30, Scott Thompson said:

>While I couldn't agree more with both statements, I think it is the
>unfortunate reality that, with the recent (last 2 years... ) boom and
>subsequent bust of the Internet economy at large, there is a growing
>majority of beginning programmers who will fall into the "grab and go"
>mindset.

But surely you don't mean that this mentality is validated by its
following.

>And that brings me back around to my point.  With the recent need for
>Perl hackers (among other related disciplines... ), a budding programmer
>didn't need to be an "expert" to land a high-paying, high-profile web
>development job.  The demand far exceeded the supply.  So, suddenly, you
>have relatively inexperienced beginners needing to produce results
>within a start-up's time frame.  So instead of seeking knowledge for the
>sake of knowledge, you have an inordinate number of "greenhorns" looking
>for just enough information to get the job done.

And in that situation, one probably assumes that it's ok.  Looking back,
I'd hope those people realize Perl needn't be a burden, but a tool.

The sad thing is that there arises a great rift:  the many who use Perl
because they "have to" and "need to get that code" left and right, and the
few who study and appreciate the language, and are forced to interject,
lest the many inexperienced start tossing broken code back and forth.

If the learned programmers left comp.lang.perl.misc and alt.perl and this
mailing list, and just stopped caring about the newly inducted, the newly
inducted would, most likely, become to JAPHs what Orcs are to Elves[1].

>Other than to vent my own frustrations :), my point is this.  Because of
>the influx of "new blood" there are quite a few beginning programmers
>who have not had the opportunity to REALLY learn the language they were
>hired to code in.  And, because of the subsequent economic curve ball
>thrown to the IT industry at large, many of those budding JAPH's have a
>decision -- stay in the game or leave.  Rather than complain about those
>who just "ask questions because they need the answer, not because they
>want to learn the answer," we as seasoned Perl programmers have the
>opportunity to pass on our love and enthusiasm for Perl and programming
>in general to those willing to embrace it.

Perl is a language that invokes a sense of community -- look at its
beginnings, and its creator (and founder).  The language can be easily
abused, much like the wings of butterflies; the clumsy and uncareful can
make Perl seem ugly and ungainly and difficult.  It is for us, the
learned, the JAPHs, to be sure new Perlers everywhere are introduced to
the language properly.  Sometimes that requires hand-holding, and
sometimes it requires us to remove the training wheels.

>I've given my share of one-liner answers, but based on this particular
>thread, I personally am going to endeavor to inform others, as much as I
>am able, rather than just "answer questions".

I am all for enlightening and sharing knowledge.  Sometimes, that means
pointing out the FAQ answer right in front of the poster's nose, if only
to inform the poster that such magical and wondrous documentation exists
and is easily accessible.



[1] From "The Silmarillion", by JRR Tolkien; specifically, "Of the Coming
of the Elves":

  All those of the Quendi [Elves] who came into the hands of Melkor ...
  were put there in prison, and by slow arts of cruelty were corrupted
  and enslaved; and thus did Melkor breed the hideous rave of the Orcs in
  envy and mockery of the Elves ...


-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **




Why 'and' not '&&' ? (was Cleaning up 'uninitialized value')

2001-05-30 Thread Peter Cornelius

> Use:
> 
>   if (@ARGV and -T $ARGV[0]) { ... }

Just wondering if there is a reason for using the lower precedence 'and'
here instead of '&&'?  I haven't been finding many uses for 'and' which
tells me I might not fully understand it.

Thanks,
Peter C.



RE: On Beginners' Mindsets, Part II

2001-05-30 Thread Scott Thompson

> -Original Message-
> From: Jeff Pinyan [mailto:[EMAIL PROTECTED]]
> Subject: Re: On Beginners' Mindsets, Part II
>
> On May 30, Peter Scott said:
>
> >*Curiosity* is an essential trait for the programmer.  In all
> seriousness,
> >if you don't have a deep desire to find out how things work - in
> >particular, software - this may not be the field for you.  Principally
> >because our tools are rarely so perfect at encapsulation that they
> >completely hide the underlying mechanism, therefore, it is necessary to
> >understand the underlying mechanism and to want to get at it.
>
> Curiosity without motivation is a bane, as I am sure those of us who have
> been sitting in IRC channels and on mailing lists, for the purposes of
> ANSWERING questions, are well aware.  People that ask questions because
> they need the answer, not because they want to learn the answer, are not
> helpful programmers in the long run -- they know only what they've been
> spoonfed, and have trouble formulating code or applying algorithms
> themselves.  They also have trouble explaining the code they cut and paste
> from Joe Coder's program.
>

While I couldn't agree more with both statements, I think it is the
unfortunate reality that, with the recent (last 2 years... ) boom and
subsequent bust of the Internet economy at large, there is a growing
majority of beginning programmers who will fall into the "grab and go"
mindset.
Now, let me assure recent posters to this list that I am in no way
targeting anyone in particular with that statement.  Rather, I am speaking
from my own experience in the local job market.  I certainly do not -- and
never WILL -- claim to be any kind of "expert" in Perl or any other
language.  As Peter pointed out, I am always learning so, in that regard, I
don't think there ARE any Perl "experts" -- just someone who has learned
more about something you have not. :)
And that brings me back around to my point.  With the recent need for Perl
hackers (among other related disciplines... ), a budding programmer didn't
need to be an "expert" to land a high-paying, high-profile web development
job.  The demand far exceeded the supply.  So, suddenly, you have relatively
inexperienced beginners needing to produce results within a start-up's time
frame.  So instead of seeking knowledge for the sake of knowledge, you have
an inordinate number of "greenhorns" looking for just enough information to
get the job done.
I even saw evidence of this attitude in the sudden addition of
Internet-related IT degrees at local colleges.  Here was this sudden demand
for "trained IT professionals," so schools started putting together
curricula willy-nilly to fill that demand.  I knew of one student, a junior
in high school, who became Cisco Certified as part of an Advanced Placement
IT curriculum a year ago.  That's great for her -- but based on what she
told me about the "class" she was taking, they were studying from material
designed to pass the exam, not material covering the core technologies
involved.  I personally worked 1.5 years for a local consulting firm whose
clients are now having to go back and hire other consultants to come in and
fix the mess left behind by the previous consultants.  Again, because those
original consultants lacked enough in depth knowledge to fully realize the
entirety of the project and all the development nuances necessary.
Other than to vent my own frustrations :), my point is this.  Because of
the influx of "new blood" there are quite a few beginning programmers who
have not had the opportunity to REALLY learn the language they were hired to
code in.  And, because of the subsequent economic curve ball thrown to the
IT industry at large, many of those budding JAPH's have a decision -- stay
in the game or leave.  Rather than complain about those who just "ask
questions because they need the answer, not because they want to learn the
answer," we as seasoned Perl programmers have the opportunity to pass on our
love and enthusiasm for Perl and programming in general to those willing to
embrace it.
I've given my share of one-liner answers, but based on this particular
thread, I personally am going to endeavor to inform others, as much as I am
able, rather than just "answer questions".

As Peter said... FWIW... :)

++++
|| UNIREZ, Inc.Scott Thompson ||
++---+++
|| Address: 2555 Southwest Grapevine Parkway | Title: Programmer  ||
||  Suite 200| Phone: (817) 416-5800  ||
||  Grapevine, Texas 76051   | Extension: 104 ||
|| Fax: (817) 251-9199   | Cell:  (972) 342-5660  ||
|| Web: http://www.unirez.com/   | Email: [EMAIL PROTECTED]||
++

Multiple email addresses

2001-05-30 Thread Gross, Stephan

I figured out how to look at email through the Net::IMAP::Simple module.  I
now have a deeper question.
 
I have one account that several different email accounts are tied to.  For
example, user account 'xyz' has mail at [EMAIL PROTECTED]  ,
but there are other Exchange email boxes, such as [EMAIL PROTECTED]
  that are tied to the same 'xyz' user account.
 
This is my problem: using IMAP, I have to pass along the account name and
password; however, this only allows me to see the email for the user account
('xyz' in my example).  How do get the email for [EMAIL PROTECTED]
 ?
 
 

___
Stephan Gross   Loral Skynet 908-470-2388 [EMAIL PROTECTED]
 

 



Re: Sleeping for less than a second

2001-05-30 Thread Paul


--- Craig Moynes/Markham/IBM <[EMAIL PROTECTED]> wrote:
> Is there anyway to sleep for less than a second using the default
> installation of perl ?

Yes, though it isn't pretty. =o)

select(undef, undef, undef, 0.25); # the last arg is seconds

c.f. perldoc -f select

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: Sleeping for less than a second

2001-05-30 Thread Walt Mankowski

On Wed, May 30, 2001 at 01:42:17PM -0400, Craig Moynes/Markham/IBM wrote:
> Hi all, my DNS server is down so I can't check online.

No need to check online.  This answer is in the FAQ that comes with
Perl.

> Is there anyway to sleep for less than a second using the default
> installation of perl ?
> And if not what CPAN module should I use when I get my internet connection
> back up ?

$ perldoc -q sleep
Found in /usr/local/lib/perl5/5.6.1/pod/perlfaq8.pod
 How can I sleep() or alarm() for under a second?

 If you want finer granularity than the 1 second that the
 sleep() function provides, the easiest way is to use the
 select() function as documented in the select entry in the
 perlfunc manpage.  Try the Time::HiRes and the BSD::Itimer
 modules (available from CPAN).

Walt

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




Re: Sleeping for less than a second

2001-05-30 Thread Jeff Pinyan

On May 30, Craig Moynes/Markham/IBM said:

>Is there anyway to sleep for less than a second using the default
>installation of perl ?

friday:~ $ perldoc -q sleep
=head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq8.pod

=head2 How can I sleep() or alarm() for under a second?

If you want finer granularity than the 1 second that the sleep()
function provides, the easiest way is to use the select() function as
documented in L.  If your system has itimers and
syscall() support, you can check out the old example in
http://www.perl.com/CPAN/doc/misc/ancient/tutorial/eg/itimers.pl .

I refer you then to perlfunc:

friday:~ $ perldoc -f select

[...]
You can effect a sleep of 250 milliseconds this way:

select(undef, undef, undef, 0.25);
[...]

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **




Sleeping for less than a second

2001-05-30 Thread Craig Moynes/Markham/IBM


Hi all, my DNS server is down so I can't check online.


Is there anyway to sleep for less than a second using the default
installation of perl ?
And if not what CPAN module should I use when I get my internet connection
back up ?
-
Craig Moynes
Internship Student
netCC Development
IBM Global Services, Canada
Tel: (905) 316-3486
[EMAIL PROTECTED]





Re: On Beginners' Mindsets, Part II

2001-05-30 Thread Morbus Iff

 >Secondly, want to understand *everything*.  Even if you leave some parts
 >until later because they're less interesting or less relevant, strive to
 >understand an entire process from top to bottom.  It's amazing how often

I agree wholeheartedly with this statement. I've done the gambit of 
advanced perl programming, but I still read perl tutorials and beginner 
columns. Why? Because I don't doubt that the author can shed a pe[a]rl of 
light in a slightly different way, or highlight a metaphor that I can 
reiterate to another...

When I buy magazines, I read *every single bit* of text. Same with books. 
It was written for a reason - it's my reading of that text that gives it 
reason, not hastily skipping over it because it's uninteresting at the time.

There are some people who say they only read the stuff they need to know at 
the time they need to know it - and that anything else means shoving 
useless facts into the brain that could push worthwhile facts out. I don't 
agree, not in the least.

 >Thirdly, devour good examples of code that are just within or just beyond
 >your current understanding.  They'll both broaden and deepen your expertise

Definitely agreeable. I learn much faster from examples.


Morbus Iff
.sig on other machine.
http://www.disobey.com/
http://www.gamegrene.com/




Re: iinfinite loop

2001-05-30 Thread Jeff Pinyan

On May 30, David Gilden said:

>$data = 'some
>multi line
>string';
>
>while($data){
>   push(@everyline, $_);  
>}

You're confusing this with

  while () {
# do something with $_;
  }

You can do:

  @lines = split /\n/, $data;

or you can download the IO::String module from CPAN
(http://search.cpan.org/):

  use IO::String;

  my $str_fh = IO::String->new($data);

  while (<$str_fh>) {
push @lines, $_;
  }

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **




Re: iinfinite loop

2001-05-30 Thread Ondrej Par

1) better use 

$data = < The following seems to never break out of the loop,
> any comments?
> Thanks
>
> Dave
>
> #!/usr/bin/perl -w
>
>
> $data = 'some
> multi line
> string';
>
>
> while($data){
>
>push(@everyline, $_);
>
> }

-- 
Ondrej Par
Internet Securities
Software Engineer
e-mail: [EMAIL PROTECTED]
Phone: +420 2 222 543 45 ext. 112




RE: iinfinite loop

2001-05-30 Thread Jeffrey Goff

Judging by the loop you seem to want, something like

$data="Hey\nThis is\nmultiline";
@everyline = split(/\n/,$data);

is probably more appropriate for your purposes. However the original
comments re: $data never being modified still hold true.

-Original Message-
From: Brent Michalski [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 30, 2001 1:31 PM
To: David Gilden
Cc: [EMAIL PROTECTED]
Subject: Re: iinfinite loop



Because the while loop will loop for as long as $data is "true" or contains
data  Considering that it has data in it, you have created an
"infinite" loop




 

David Gilden

  cc:

Subject: iinfinite loop

05/30/01 12:25

PM

 

 





The following seems to never break out of the loop,
any comments?
Thanks

Dave

#!/usr/bin/perl -w


$data = 'some
multi line
string';


while($data){

   push(@everyline, $_);

}






Re: iinfinite loop

2001-05-30 Thread Brett W. McCoy

On Wed, 30 May 2001, David Gilden wrote:

> The following seems to never break out of the loop,
> any comments?
> Thanks
>
> Dave
>
> #!/usr/bin/perl -w
>
>
> $data = 'some
> multi line
> string';
>
>
> while($data){
>
>push(@everyline, $_);
>
> }

Yes, it's going to loop infinitely because $data is always true -- it has
a defined value it is holding, so the loop will never end.  You can't loop
through a multiline string that way.  You should use split to break the
string up into a list context and put that into your array:

#might want to use a here doc for complex strings
my $data = 'data
data
data
';

my @lines = split /\n/, $data;

foreach my $line (@lines) {

print "$line : ";
}

my @everyline = split /\n/, $data;

-- Brett

Brett W. McCoy
Software Engineer
Broadsoft, Inc.
240-364-5225
[EMAIL PROTECTED]




Re: iinfinite loop

2001-05-30 Thread Brent Michalski


OOps, hit send too soon...

This is _not_ the same as reading from a filehandle!

while ()  is NOT the same as while($variable)  {unless $variable is a
filehandle}

If working with a filehandle, the while will loop until no data is left.
With a string, it will just keep looping while true (data in string)..

Brent




   
   
David Gilden   
   
  cc:
   
Subject: iinfinite loop
   
05/30/01 12:25 
   
PM 
   
   
   
   
   




The following seems to never break out of the loop,
any comments?
Thanks

Dave

#!/usr/bin/perl -w


$data = 'some
multi line
string';


while($data){

   push(@everyline, $_);

}







Re: iinfinite loop

2001-05-30 Thread Brent Michalski


Because the while loop will loop for as long as $data is "true" or contains
data  Considering that it has data in it, you have created an
"infinite" loop




   
   
David Gilden   
   
  cc:
   
Subject: iinfinite loop
   
05/30/01 12:25 
   
PM 
   
   
   
   
   




The following seems to never break out of the loop,
any comments?
Thanks

Dave

#!/usr/bin/perl -w


$data = 'some
multi line
string';


while($data){

   push(@everyline, $_);

}







Re: iinfinite loop

2001-05-30 Thread John Joseph Trammell

On Wed, May 30, 2001 at 01:25:07PM -0400, David Gilden wrote:
> The following seems to never break out of the loop,
> any comments?
> Thanks
> 
> Dave
> 
> #!/usr/bin/perl -w
> 
> 
> $data = 'some
> multi line
> string';
> 
> 
> while($data){
>   
>push(@everyline, $_);  
> 
> }

1. you forgot "use strict;"
2. since $data is true, this is the same as "while (1) {...}"

-- 
[W]hen the manager knows his boss will accept status reports without
panic or preeemption, he comes to give honest appraisals.
   - F. Brooks, _The Mythical Man-Month_



iinfinite loop

2001-05-30 Thread David Gilden

The following seems to never break out of the loop,
any comments?
Thanks

Dave

#!/usr/bin/perl -w


$data = 'some
multi line
string';


while($data){
  
   push(@everyline, $_);  

}



Email question

2001-05-30 Thread Gross, Stephan

I'd like to a write a program that would tell me, for several specific
accounts/mailboxes on a Microsoft Exchange server, how many emails are
there.  I can use either POP3 or IMAP protocols.  Any suggestions or
pointers?

___
Stephan Gross   Loral Skynet 908-470-2388 [EMAIL PROTECTED]
 

 



Re: On Beginners' Mindsets, Part II

2001-05-30 Thread Jeff Pinyan

On May 30, Peter Scott said:

>*Curiosity* is an essential trait for the programmer.  In all seriousness, 
>if you don't have a deep desire to find out how things work - in 
>particular, software - this may not be the field for you.  Principally 
>because our tools are rarely so perfect at encapsulation that they 
>completely hide the underlying mechanism, therefore, it is necessary to 
>understand the underlying mechanism and to want to get at it.

Curiosity without motivation is a bane, as I am sure those of us who have
been sitting in IRC channels and on mailing lists, for the purposes of
ANSWERING questions, are well aware.  People that ask questions because
they need the answer, not because they want to learn the answer, are not
helpful programmers in the long run -- they know only what they've been
spoonfed, and have trouble formulating code or applying algorithms
themselves.  They also have trouble explaining the code they cut and paste
from Joe Coder's program.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **




regexp Help

2001-05-30 Thread Kyrytow, Stefan

If someone could please help me.

I can't figure out how to use a variable in a regexp.

Example.
I am writing a script to parse a web log and report on all the hosts in the
log.
However I have a command line option to exclude a domain from the report.
My problem is that I can't figure out how to use the inputed value in a
regexp.

Log Format
host.domain.com

I want to be able to exclude domain.com

I have tried:
while( $exclude_domain !~ /$host/ ) { ... }

Any help is appreciated.

STEFAN KYRYTOW
EDS CANADA
Leveraged Platform Solution Centre
t 416.814.4911
p 416.517.2252
[EMAIL PROTECTED]




On Beginners' Mindsets, Part II

2001-05-30 Thread Peter Scott

Comments by Scott Thompson and Elaine Ashton prompt an early Part II.

*Curiosity* is an essential trait for the programmer.  In all seriousness, 
if you don't have a deep desire to find out how things work - in 
particular, software - this may not be the field for you.  Principally 
because our tools are rarely so perfect at encapsulation that they 
completely hide the underlying mechanism, therefore, it is necessary to 
understand the underlying mechanism and to want to get at it.

Now, I have to qualify and explain that statement.  Take for example, a 
modern automobile. It successfully encapulates the principles of internal 
combustion engines such that a driver who doesn't want to know any more 
about it than "Put gas in when this light goes on and take it to a service 
station if any other light goes on" doesn't have to.  The automobile has 
shielded the driver from having to know about spark plug gapping, timing 
advances, that sort of thing (not that plenty of owners don't get mileage 
out of knowing those things anyway).

In computer programming, the C compiler manages to do the same thing; most 
people don't need to dig below the level of C source any longer to find a 
problem.  (It wasn't always so; up to 10 years ago I used to have to go 
into the machine code generated by a compiler on occasion because there was 
a slight chance that the compiler had erred.)  For the most part, the Perl 
programmer can make the same claim.  But what of the edifices we construct 
with our high-level languages?  By and large, applications rarely 
encapsulate perfectly; there's always a need or substantial advantage to be 
gained from ferreting about under the hood.  In the last 10 years, this 
need has only increased, in my opinion; I see more complex applications 
coming to market in much shorter development cycles, and  as a result a 
product is more buggy, less complete, and less properly documented than one 
from the year before.  No matter how professional the product, somehow I 
always end up relinking shared libraries, editing header files, writing 
Perl 'glue', or some other kind of tinkering to get it to do what I want.

The need to delve into the workings of software is so pervasive that it was 
encasulated long ago in an acronym that's also geekspeak: UTSL, standing 
for "Use The Source, Luke".  Telling someone to UTSL is also recognizing 
that the source code itself is the ultimate authority on how it works and 
sometimes nothing else can answer a particular question.

So we work in an imperfect field that requires that we often tear things 
apart to make progress.  How should a beginner leverage this 
information?  Firstly, as I said, realize that if you don't have a desire 
to find out how things work *just for the sake of it*, you may not have fun 
being a programmer.  I know the obvious retort is, "I just want to get my 
job done," but as I've been explaining, getting this job done usually 
requires so much inquisitiveness that you'd better enjoy it.

Secondly, want to understand *everything*.  Even if you leave some parts 
until later because they're less interesting or less relevant, strive to 
understand an entire process from top to bottom.  It's amazing how often 
there's useful information hidden inside some part that you thought was 
perfectly encapsulated.  Or that helps you understand higher levels: 
learning how CPUs are constructed helps to understand why assembler is the 
way it is, which helps to understand how higher-level languages are 
constructed and why things like stacks and heaps are so important.

Thirdly, devour good examples of code that are just within or just beyond 
your current understanding.  They'll both broaden and deepen your expertise 
as you see other ways of doing things you already know how to do, and are 
forced to research new topics.

Finally, understand that the learning can never, ever, end.  You'll know 
that you're in the right place if this comes as good news.


Hmmm... FWIW, (c) 2001, Peter Scott




Ca't locate loadable object for module...

2001-05-30 Thread Margit Brunder

I get the error message "can't locate loadable object for module
HTML::Parser in @INC  at ./HTML/entities.pm line 79"
although the module Parser.pm is in the same directory as entities.pm
The path where Parser.pm is located is included in @INC !!

What's going wrong?

Thanks
Margit




Re: Hash tutorial?

2001-05-30 Thread Jeff Pinyan

On May 30, Paul said:

>Just an elaboration -- you can do this:
>
>  @hash{ qw( a b c ) } = qw( 1 2 3 );
>
>which should give you the same as:
>
>  %hash = ( a => 1, b => 2, c => 3 );

Only if %hash was previously empty.  Assigning to a hash all at once
clears it and sets the key-value pairs you prescribe:

  %hash = ( a => 1, b => 2, c => 3 );

Assigning to a hash slice sets only the key-value pairs for those keys:

  @hash{qw( d e f )} = (4..6);
  # %hash is now ( a, 1, b, 2, c, 3, d, 4, e, 5, f, 6 )

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **




Re: Hash tutorial?

2001-05-30 Thread Paul


--- Paul <[EMAIL PROTECTED]> wrote:
>  @ASCEBC{values %EBCASC} = keys %EBCASC; # flip for the compliment

Just an elaboration -- you can do this:

  @hash{ qw( a b c ) } = qw( 1 2 3 );

which should give you the same as:

  %hash = ( a => 1, b => 2, c => 3 );

Though the second one is a lot more readable, I think.
I would only recommend the first when evaluating expressions, as in the
EBCASC/ASCEBC example, above.

Also, my previous post was rife with typos, for whish I apologize. =o)

Paul

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: Hash tutorial?

2001-05-30 Thread Paul


--- Oliver Glass <[EMAIL PROTECTED]> wrote:
> Hello,

Hiya. =o)

> Despite a fair amount of general coding experience I keep slipping up
> with hashes... I learnt them in a hurry and so am working on loose
> foundations.

lol -- I've *never* done *that* before... 


> Could anyone reccomend a tutorial on the subject, preferably aimed at
> a little higher than novice level?

I can blather, and folk can ask for clarification. That usually works
pretty well, since other folk are pretty good at answering specific
question! lol! Let me start at a little more basic level, though, and
work up. It gives me more chance to put my foot in my mouth, and then
when someone corrects me, *I* learn stuff!

A Hash is an associative array. Whereas "arrays" use square brackets to
and numbers indicate an index,

  $array[1]
 
"hashes" use curly braces and strings.

  $hash{'this'}

Unlike normal arrays, all hash keys must be unique, because (as I
understand it) a "hashing" algorithm is used on the key value to decide
where it goes, so that when retrieving the value it can go through the
same algorithm to go straight to the value, rather than having to walk
through them individually and do string compares. In general, hashes
are a little slower than arrays (I've heard 15-20%), and take up more
memory -- they allocate memory in blocks, and add more when the hash is
half full (?), so they tend to take up about four times as much space
as the data in them would in an array. They are wonderfully flexible,
however

The elements of a hash must be scalars (DEFINITELY correct me on this
if I misrepresent!), but since references are scalars, a reference may
be stored, and the hash lookup mechanism will follow such linkages,
allowing complex and flexible multilevel structures. This is basically
the same way that multidimensional arrays are done, and as a result you
can create structures which include hashes of arrays of hashes of
values, if you want to get that fancy. Such a structure would be
accessed like this:

  $top{'key1'}[0]{'key2'} = $val;

Every indirection must be traced, however, so depending on your
processing needs, it's sometimes more efficient to compile the keys and
make one hash out of it:

  $top{'key1'.0.'key2'} = $val; # has been known to save me a LOT
# of time, memory, and headache

Hashes can also be used for complex access. When referring to an entire
hash, we use %, like this:

  print %hash;

The symbol used indicates the type of the final value, so in the
examples above, a scalar was being returned. It is possible, however,
to return a list by using the array character @. I have a module for
EBCDIC to ASCII conversions, which uses a hash table lookup; for the
reverse conversions, I just flipped and copied the table, like this:

 @ASCEBC{values %EBCASC} = keys %EBCASC; # flip for the compliment
table

What this does is assigns to %ASCEBC in a particular order, as
specified by the argument "{values %EBCASC}". the @ on @ASCEBC tells
perl I'm assigning an entire list at once, so what this statement does
is assigns to the values specified (as keys in %ASCEBC) from keys
%EBCASC.

Note that order for hashes, while predictable, is not intuitive; it's
based on the hashing algorith, ans seems quite random. The above code
works because the algorithm is constant, but don't think of it as
sorted. If the order matters, either don't use a hash, or order them
yourself somehow (which is a topic for another discussion, though maybe
not here. =o)

If one takes a reference to a hash, like this:

  $rh = \%hash;

then one can access it in several ways:

  $$rh{foo};  # same as $hash{foo}
  $rh->{foo}; # again, same as $hash{foo}
  keys %$rh   # same as keys %hash

This is commonly used as the mthod for objects, though it's best to use
accessors for the data, rather than fiddling with object properties
directly.

The constructor for an anonymous hash is curly braces, which return a
reference to the data they contain:

  $rh = { a => 1, b => 2 };

Now, to print 2, say:

  print $rh->{b};

A common mistake is to try using this constructor incorrectly, like
this:

  %hash = { a => 1, b => 2 };

This should give you an warning if you enable -w, saying the hash
assignment has only one element. You gave the hash a key with no value.
What was the key? the reference to the data that the {} returned. It
will *not* give you *any* clue as to what you have done wrong if you
don't use -w!

Ok, That should have been plenty of opportunity for me to stick my foot
in my mouth. =o)

Corrections?
Questions?



__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



RE: On Beginners' Mindsets, Part I

2001-05-30 Thread Peter Scott

At 08:42 AM 5/30/2001 -0500, Scott Thompson wrote:
>For myself, I have learned
>just as much about Perl -- sometimes MORE -- by "bucking" the tried-and-true
>methods to discover my own path.  Sometimes I'd come stumbling back to the
>common wisdom, battered and bruised for my efforts.  Other times, I've
>picked up my own little nuggets of wisdom that worked best for me and my
>situation despite the commonly accepted Truth.

Quite.  I think my response is long enough that it deserves to be a Part 
II.  Stay tuned...




Re: Different releases of Perl for Win

2001-05-30 Thread Me

> different flavours of Perl

Also check out http://cygwin.com/ which gives you
a simulated unix environment on Windows. This way
you can run identical perl setups on your w2k as on
your linux machines rather than using activestate on
the w2k machines.




RE: Re: how to copy a hash ?

2001-05-30 Thread Paul


--- [EMAIL PROTECTED] wrote:
> i don't know what kinds of hash $h is.
> maybe  $h is hash of hashes, or $h is hashof array.
> how to do that?

c.f. Randall's post on deep copying.

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: how to copy a hash ?

2001-05-30 Thread Paul


--- [EMAIL PROTECTED] wrote:
> how to copy a hash?
> example: $h is   reference  of a hash struct.
> i want to copy this hash struct.

Well, the simplistic answer would be:

  my %newHash = %{$h};

if $h = { a => 1, b => 2 }, then that's fine, but with subelements like
in a hash of hashes or arrays, you only copy the top level, which
*aliases* everything below that (*not* copying, just pointing back to
the subelements of the original).



__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: Binary and ASCII

2001-05-30 Thread Paul


--- Cameron Malchow <[EMAIL PROTECTED]> wrote:
> In unix, specifically OS X, if you have a perl program that is either
> binary or ascii how can you convert it to the opposite format?

No binary version of Perl programs (at least that I'd recommend).
Could you elaborate on what you mean?

For normal *NIX scripts, put a "shebang" (a shell-bang, #!) at the top.
No leading whitespace, like this:

#!/path/to/perl -w

Then just make the file executable.
Is that what you were looking for?

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: 'sort(func(list))' <=same as=> 'sort func (list)' ?!?!?

2001-05-30 Thread Jeff Pinyan

On May 30, Mark Salazar said:

>I was recently bitten by this, and it's not clear to me (and others) if
>this is correct Perl behavior or not.
>
>If you have a user defined function 'func' that returns a list and you'd
>like to sort that return value it's reasonable to try:
>
>  sort(func(@list));
>
>but apparently Perl interprets this as:
>
>  sort func @list;

I've been bitten by that before.  Even doing:

  sort foobar();

becomes

  sort foobar ();

which you have to admit is rather silly.

>thereby using 'func' as an ordering function instead of first processing
>'@list' with 'func' then sorting.  Now I've read the stuff on page 1 of
>PERLFUNC(1) about parenthesis and whitespace being optional, but still
>this just strikes me as wrong.  No?

This is due to Perl's parsing.  To get around this, you can preceed the
function call with a unary + like this:

  sort +foobar(@args);

or with an ampersand:

  sort &foobar(@args);

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **




Re: Checking DOS timestamps

2001-05-30 Thread Paul

--- Steve <[EMAIL PROTECTED]> wrote:
> My question is where do I get started with DOS file create modified
> etc timestamps?

 perldoc perlfunc
 
look at -M, and stat().
I don't think the fact that it's DOS will matter at all. =o)



__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: 'sort(func(list))' <=same as=> 'sort func (list)' ?!?!?

2001-05-30 Thread Paul


--- Mark Salazar <[EMAIL PROTECTED]> wrote:
> I was recently bitten by this, and it's not clear to me (and others)
> if this is correct Perl behavior or not.
> If you have a user defined function 'func' that returns a list and
> you'd like to sort that return value it's reasonable to try:
>   sort(func(@list));
> 
> but apparently Perl interprets this as:
>   sort func @list;
> 
> thereby using 'func' as an ordering function instead of first
> processing '@list' with 'func' then sorting.  Now I've read the stuff
> on page 1 of PERLFUNC(1) about parenthesis and whitespace being
> optional, but still this just strikes me as wrong.  No?

lol -- never been bitten by that one, but it makes sense.
Nasty, but one of those things.
Add a & in front of func to tell sort "this is not for you". =o)

 print sort &func(@list);




=
print "Just another Perl Hacker\n"; # edited for readability =o)
=
Real friends are those whom, when you inconvenience them, are bothered less by it than 
you are. -- me. =o) 
=
"There are trivial truths and there are great Truths.
 The opposite of a trival truth is obviously false.
 The opposite of a great Truth is also true."  -- Neils Bohr

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Czech speaking Perl help-desk

2001-05-30 Thread Ondrej Par

Dear subscribers,

if some of you are speaking Czech language, and you find answers in 
your native language more useful than English ones, you may attend the 
discussion group, dedicated to Perl, which runs on WWW-based server Pruvodce:

http://www.pruvodce.cz/kluby/perl

I hope that rest of you won't find this message too annoying :)

-- 
Ondrej Par
Internet Securities
Software Engineer
e-mail: [EMAIL PROTECTED]
Phone: +420 2 222 543 45 ext. 112




RE: use strict / explicit packages

2001-05-30 Thread Paul


--- David Gilden <[EMAIL PROTECTED]> wrote:
> Did I touch a nerve here or what?

LOL!!!

It happens. ;o]

> Ge, all of this totally   is confusing me,

Haven't got a clue what you mean. ~grin~
 
> So you know where I am coming from, I'm taking 
> a second on-line CGI/PERL class that leaves a lot to be desired (if
> anyone knows a good up-todate on-line class, please let me know!)

I could suggest nothing better than to take an hour out or two, read
through the CGI.pm docs, and write some test code for anything that
doesn't gel for you. It'll be time well spent, that you'll spend anyway
later if you don't. Better to do it now than waste the time debugging
later and have to do it anyway when you're already even more frustrated
and confused. 

> I will move up to learning CGI.pm, but for this month, I need to
> learn how share variables between PERL files.
> So by way of example what do I need to add to my code so I can use
> the Strict Pragma?

1) Make them global.
   It's sloppy, but it's quick. Always refere to the variable in
question as $package::name, and it'll be fine. For example:
   $main::x   = 1;  # puts this in the main namespace
   $Global::y = 2;  # puts this in "Global" namespace

Note that both of these are "Global". Any code anywhere in the program
can read them. main:: is where all your stuff goes by default, but by
saying "Global" (there's nothing magical about the word -- it could
have been "Foo" or "George" or whatever), you put it into the Global::
namespace. strict.pm won't let you just say $x because it's watching
your back, but $My::x is fine, because you went to the extra trouble to
tell it which x you want. It won't create $x for you, but will quietly
make a $My::x or a $main::x or $whatever::x for you, because you gave
it enough info to believe you know what you are doing. 

2) Pass them explicitly.
   This is a better way to do it, but from the sound of it, you'd have
to rearrange code a bit. It might not be worth it in this case,
especially with time constraints. Your call.

3) Make accessors.
   If in your require'd file you create say
  my($x) = 1;

then $x is fine, strict is happy, but $x *ONLY* exists in the scope of
the file in which it was declared, and can only be accessed from that
scope. If, however, you were to add an accessor function in the same
scope:

   sub x {
   $x = shift if @_;
   $x;
   }

then I *believe* the function would go into your current namespace, but
would still have access to the commonly scoped variable. That way, you
could get/set the var with that function, like so.

   x(2);
   print x();

Yes, it seems a little abstracted, but it's a big step on the road to
objects, which (tho you may never need them) are tried-and-true.

> I take it that this is considered bad programing style or is just out
> date,  like the  tag in  :)
> require "libcgi2.pl";

Kinda, lol

> Also I don't understand this '::' syntax.

That's just Perl's way of specifying where to look for a global.
Anything that's in a package is globally available to anything that
knows where to look, but packages are like rooms in the global house;
you can walk into them without a key, but only if you know where they
are. $main::x isn't the same variable as $My::x, even though both are
x, and both can be gotten from the main or My or Foo namespaces.

Scope is *entirely* another thing, in that a lexical (my()'d) variable
only exists in the scope in which it was created.

Consider the following:

 package main; # now in main:: (this is the default)
 my $x = 1;
 $main::x  = 2;
 $foo::x   = 3;
 package other;
 $other::x = 4; 

Now, if I say
 print $foo::x;

It prints 3, but if I just say
 print $x;

It prints 1, because my() pays no attention to namespace, and *all*
these are in the same *scope*. =o)

Now, I realize that may be confusing, but hopefully better minds will
expand and correct where I've babbled! lol



=
print "Just another Perl Hacker\n"; # edited for readability =o)
=
Real friends are those whom, when you inconvenience them, are bothered less by it than 
you are. -- me. =o) 
=
"There are trivial truths and there are great Truths.
 The opposite of a trival truth is obviously false.
 The opposite of a great Truth is also true."  -- Neils Bohr

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



'sort(func(list))' <=same as=> 'sort func (list)' ?!?!?

2001-05-30 Thread Mark Salazar

I was recently bitten by this, and it's not clear to me (and others) if this is
correct Perl behavior or not.

If you have a user defined function 'func' that returns a list and you'd like to
sort that return value it's reasonable to try:

  sort(func(@list));

but apparently Perl interprets this as:

  sort func @list;

thereby using 'func' as an ordering function instead of first processing '@list'
with 'func' then sorting.  Now I've read the stuff on page 1 of PERLFUNC(1)
about parenthesis and whitespace being optional, but still this just strikes me
as wrong.  No?



Re: Cleaning up 'uninitialized value'

2001-05-30 Thread Ondrej Par

On Wednesday 30 May 2001 16:45, Craig Moynes/Markham/IBM wrote:
> # If the first argument is a text file then  store the name
> if ( (-T $ARGV[0]) )
> # ^ This is the bad boy

Replace it with

if (defined($ARGV[0]) && (-T $ARGV[0]))

or possibly

if (@ARGV && (-T $ARGV[0]))

whatever seems more intuitive (second form uses @ARGV in scalar context, thus 
converting it to number of elements).

-- 
Ondrej Par
Internet Securities
Software Engineer
e-mail: [EMAIL PROTECTED]
Phone: +420 2 222 543 45 ext. 112




Re: Cleaning up 'uninitialized value'

2001-05-30 Thread Jeff Pinyan

On May 30, Craig Moynes/Markham/IBM said:

>I have a script that when it runs (with no parameters) I have warnings
>displayed (we have all seen them but) :
>
>>Use of uninitialized value at ./log_prune.pl line 14.

Because @ARGV is empty, $ARGV[0] is undef.

>if ( (-T $ARGV[0]) )

Use:

  if (@ARGV and -T $ARGV[0]) { ... }

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **




  1   2   >