Re: Again : Including other files

2001-06-28 Thread Gabor Szabo

Hi Rajeev,

it is the approach of perl4: without modules, 
You can use this but it will be better for you if created a module 
(or modules) from the included file and use that module.
the performance difference is neglectable compared to the runtime of a
script.

see 
perldoc perlmod


-- Gabor


Rajeev Rumale wrote:
 
 Hi,
 
 I have a similar situation in my project.  I have created a file like
 mylib.pl and I put all my subroutines into it.
 
 In every page which I use i just add a line require  mylib.pl  IT works
 fine for me.
 
 I would like to know
 1. if this approch is Good
 2. Is their any performance problem compared to writing the subs directly in
 main.
 3. Is there any better approch.
 
 with regards
 
 Rajeev Rumale

-- 
Gabor Szabo
http://www.tracert.com/
Web backend development
Phone: +972-(0)54-624648



Re: use strict errors?

2001-06-28 Thread Adam Carson

That's good.  I thought that's what the error was.  The list must finally be teaching 
me something.

 Curtis Poe [EMAIL PROTECTED] 06/28/01 03:07PM 
--- RDWest Sr. [EMAIL PROTECTED] wrote:
 hi yall,
  maybe i been up too long...   i'm confused with this...script works 
fine but
 returns errors with use strict...
 could someone plz explain what i'm doing wrong?
 tx

'use strict' will, amongst other things, force you to predeclare all variables (well, 
almost all)
that you use before you actually use them.  For example:

  #!/usr/bin/perl
  use strict;
  use CGI qw/:standard/;

  $username = param( 'username' );

That will not compile because you have attempted to assign a value to $username 
without declaring
it.  To get around this:

  my $username = param( 'username' );

Or:

  my $username;
  $username = param( 'username' );

Why do this?  A couple of weeks ago, I was working on a 2,000 line program that 
someone else
wrote, but they didn't use strict.  It took me over half an hour to figure out that 
one of the
variable names had been misspelled on one of the lines.  Had the 'strict' pragma been 
used, the
program would not even have compiled.  It would instantly have told me that the 
misspelled
variable wasn't declared and I could have gone it to fix it.  Unfortunately, once 
programs get
that large, retro-fitting them to use strict is very difficult.

I thought about fixing up your code, but it has some serious problems.  You have 
borrowed some
very, very broken form-handling code from some book or Web site.  For a thorough 
explanation of
why that code is broken, read
http://www.easystreet.com/~ovid/cgi_course/lesson_two/lesson_two.html.  I'd summarize 
the details
for you, but there are so many problems with that code that I felt a link was more 
appropriate.

Please don't take any of this personally.  I realize that you are new to Perl and I'm 
just hoping
to point you in the right direction.

Cheers,
Curtis Poe

=
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
Ovid on http://www.perlmonks.org/ 

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/




split function question

2001-06-28 Thread Brian Bukeavich

I need a little help with the split function. I'm trying to split a line 
based on comma delimeters(,), but when I use the syntax below I don't get 
the results I expect.  What am I doing wrong?  Is there a an special escape 
sequence for a comma?

my @asLine = split (/,/, $_);


Thanks
_
Get your FREE download of MSN Explorer at http://explorer.msn.com




Re: split function question

2001-06-28 Thread Curtis Poe

--- Brian Bukeavich [EMAIL PROTECTED] wrote:
 I need a little help with the split function. I'm trying to split a line 
 based on comma delimeters(,), but when I use the syntax below I don't get 
 the results I expect.  What am I doing wrong?  Is there a an special escape 
 sequence for a comma?
 
 my @asLine = split (/,/, $_);

Just a quick guess, but much of the comma-delimited data that I see has quoted fields 
that have
commas embedded in the quotes:

  Poe, Curtis, 34, Aspiring Screenwriter, Programmer

Trying to split the above line on commas will result in five fields instead of three.  
You should
probably use a module like Text::CSV or something similar.

If you show us some sample input, expected output, and actual output, we can offer 
better advice.

Cheers,
Curtis Poe

=
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
Ovid on http://www.perlmonks.org/

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



RE: split function question

2001-06-28 Thread Moon, John

 perl -e 'print Enter your values as 1,2,3...:;
$_=;
chomp;
my @asLine=split (/,/, $_);
foreach (@asLine) {
print asLine[.$i++.]=$_\n;
}'

You may want to see what you have 
   print $_\n 
for example just before you try the split ...

-Original Message-
From: Brian Bukeavich [mailto:[EMAIL PROTECTED]]
Sent: June 28, 2001 15:38
To: [EMAIL PROTECTED]
Subject: split function question


I need a little help with the split function. I'm trying to split a line 
based on comma delimeters(,), but when I use the syntax below I don't get 
the results I expect.  What am I doing wrong?  Is there a an special escape 
sequence for a comma?

my @asLine = split (/,/, $_);


Thanks
_
Get your FREE download of MSN Explorer at http://explorer.msn.com



Re: Streaming mp3

2001-06-28 Thread iain truskett

* John Edwards ([EMAIL PROTECTED]) [28 Jun 2001 14:35]:
 Hi. I'm writing some cgi to process an input (passed via URL encoding
 on the end of the URL) and return to the browser the selected mp3,
 streamed.

 I've got some code that generates a m3u file, with the URL to the
 right mp3, writes that m3u to the disk on the server and redirects the
 browser to the
 m3u. This should then connect back to the server and stream the mp3.
[...]

Just downloading the mp3 isn't what winamp and so on do. See
 http://www.perldoc.com/cpan/Apache/MP3.html


-- 
iain.  http://eh.org/~koschei/



hidden field value not getting set

2001-06-28 Thread Moon, John

Below is code to generate one or two forms... 
When both forms are generated the hidden value for the second form is not
getting replaced with the correct value...

Does anyone see a problem with this code ?

Thanks in advance ...


print $q-p($q-center(
Items from $REQUEST{START} to $displayed of $REQUEST{END} items));
# -- values OK here !
exit if $REQUEST{END} = $max_lines;# No Previous or Next
# Display previous  next buttons when appropriate
my $span = 9;

my %buttons = ();
if ($REQUEST{START}  1) {
 $span = 6;
$buttons{'1'}
= [($REQUEST{START},Previous $REQUEST{START}
Items,'prev')];
}
# are there more to display  ?
if ($REQUEST{START}  $REQUEST{END}) {
 $span -=3;
$displayed++;
$buttons{'2'}
= [($displayed,Next $displayed Items,'next')];
}
$row = '';
foreach (sort keys %buttons) {
$row .= $q-td({-align='CENTER',-colspan=$span},
$q-start_form(-name=$buttons{$_}[2]),
$q-submit(-name=$buttons{$_}[1]),\n,
$q-hidden(-name='ACCT',
-value=$REQUEST{ACCT}),\n,
$q-hidden(-name='CUST_ID',
-value=$REQUEST{CUST_ID}),\n,
$q-hidden(-name='TITLE',
-value=$REQUEST{TITLE}),\n,
$q-hidden(-name='ACTIVE',
-value=$REQUEST{ACTIVE}),\n,
$q-hidden(-name='START',
-value=$buttons{$_}[0]),\n, #  Problem ? 
$q-hidden(-name='END',
-value=$REQUEST{END}),\n,
$q-hidden(-name='INITIAL',
-value='NO'),\n,
'/FORM');
}

generates ...

center
Items from 11 to 20 of 69 items
/center
/p
table size=80% align=CENTER
tr
td align=CENTER colspan=3
form method=post
action=/ITP_Billing/cgi-bin/search_accounts.cgi
enctype=application/x-www-form-urlencoded name=prev
 input type=submit name=Previous 11 Items
value=Previous 11 Items / 
 input type=hidden name=ACCT value= / 
 input type=hidden name=CUST_ID value=14 / 
 input type=hidden name=TITLE value= / 
 input type=hidden name=ACTIVE value=Active
/ 
 input type=hidden name=START value=11 / 
 input type=hidden name=END value=69 / 
 input type=hidden name=INITIAL value=NO / 
 /FORM
/td
td align=CENTER colspan=3
form method=post
action=/ITP_Billing/cgi-bin/search_accounts.cgi
enctype=application/x-www-form-urlencoded name=next
 input type=submit name=Next 21 Items
value=Next 21 Items / 
 input type=hidden name=ACCT value= / 
 input type=hidden name=CUST_ID value=14 / 
 input type=hidden name=TITLE value= / 
 input type=hidden name=ACTIVE value=Active
/ 
 input type=hidden name=START value=11 / 
 input type=hidden name=END value=69 / 
 input type=hidden name=INITIAL value=NO / 
 /FORM
/td
/tr
/table



Re: Perl Boilerplate???

2001-06-28 Thread Peter Scott

At 09:24 AM 6/28/01 -0500, David Simcik wrote:
Hey,
 I, like the rest of you, am always looking for ways to make my 
 life more
convenient. Especially when coding. To this end, I am looking to fashion a
well-rounded template doc that I can use in Homesite (where I do most of my
work right now) made up of the essential pieces I'd expect to work with in
Perl and with a strong layout. I have trolled through most of the better
Perl books out there (Camel, Cookbook, Effective Perl, CGI Programming), but
have yet to find an example template outlined succintly (aside from the VERY
basic). So the question is, if anybody else does this (I'd be shocked if no
one did), what do YOUR templates looks like? What are some of the
idiomatically most important elements that should be included???

I think that beyond

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

you'd find contention about what to include... and some people will argue 
about the -w.  Were you looking for something like

#!/usr/bin/perl -w
use strict;
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);

No, wait, some people will argue about the last line as well.  Maybe this 
is why you haven't found any examples :-)
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Perl Boilerplate???

2001-06-28 Thread David Simcik

Hey,
I, like the rest of you, am always looking for ways to make my life more
convenient. Especially when coding. To this end, I am looking to fashion a
well-rounded template doc that I can use in Homesite (where I do most of my
work right now) made up of the essential pieces I'd expect to work with in
Perl and with a strong layout. I have trolled through most of the better
Perl books out there (Camel, Cookbook, Effective Perl, CGI Programming), but
have yet to find an example template outlined succintly (aside from the VERY
basic). So the question is, if anybody else does this (I'd be shocked if no
one did), what do YOUR templates looks like? What are some of the
idiomatically most important elements that should be included???

Regards,
DTS






Code Review Needed!

2001-06-28 Thread dave hoover

I would greatly appreciate ANY feedback anyone could
provide. The following page will provide details and a
link to download the tarball.

http://www.redsquirreldesign.com/soapbox

TIA


=
Dave Hoover
Twice blessed is help unlooked for. --Tolkien
http://www.redsquirreldesign.com/dave

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Clear screen

2001-06-28 Thread jaya kumaran


Hi all,

   I used this instruction to clear the screen on NT
   
   system(cls);
   print Hello;
  
  the same instruction is not working on unix. I modified the instruction to

  system(clear);
  print hello;

This works fine on unix. Is there any instruction in perl to perfom clear screen and 
it works on both windows and Unix 

Thanks in advance,
jaya K.

_
Get Free Fast Easy email from indiya.com: SIGNUP NOW : http://www.indiya.com



Re: Clear screen

2001-06-28 Thread Me

I used this instruction to clear the screen on NT

system(cls);
print Hello;

   the same instruction is not working on unix. I modified the
instruction to

   system(clear);
   print hello;

 This works fine on unix. Is there any instruction in perl to perfom
clear screen and it works on both windows and Unix

 Thanks in advance,

Would this:

clear;

assuming an earlier:

sub clear { system($^O =~ 'win' ? 'clear':'clr') }

be ok?

A more general solution for this sort of problem
(portable standard utilities) is to use Perl Power Tools:

http://language.perl.com/ppt/

but they haven't (yet?) been nicely bundled on cpan.




Re: Converting Unix paths to windows

2001-06-28 Thread Hasanuddin Tamir

On Wed, 27 Jun 2001, Daryl Hoyt [EMAIL PROTECTED] wrote,

 Hi,
 I am writing a script to be used on Windows and many different
 flavors of Unix.  I am looking for a good way to convert Unix paths
 to Windows.  Any Ideas?

use File::Spec;

I know your question is about converting.  But I offer you
portability so you don't need to convert anything and create
two (or more) scripts for two (or more) different systems.

Besides, as long as unix2windows *path* is concerned, Perl
in Windows treats / correctly, except perhaps the C: drive
notation.


__END__
-- 
s::a::n-http(www.trabas.com)




Re: Best practice for config file use?

2001-06-28 Thread Hasanuddin Tamir

On Wed, 27 Jun 2001, Michael Fowler [EMAIL PROTECTED] wrote,

 On Wed, Jun 27, 2001 at 06:58:37PM +0200, Jos I. Boumans wrote:
  I usually use a config file for this
  now you could do this 3 ways as i see it
 
  -just have a file that holds a lot of global vars and 'require/use' that
  in your mian script
  -get one hashref that you globalise and thus reduce namespace pollution
  -make it a module, give it a constructor returning a hashref and thus
  not polluting *anything*

 There are other methods for getting configuration information from an
 external file.

 4) Parse some specific configuration file format, and then provide
access to the data from it via a hash or object.  There are various
modules available on CPAN for this
(http://www.cpan.org/modules/00modlist.long.html#ID12_Option_Arg).

 5) Parse a file written in Perl, that sets a lot of global variables,
into a hash, such as what Parse::PerlConfig (by yours truly) does
(http://www.cpan.org/authors/id/M/MF/MFOWLER/Parse-PerlConfig-0.05.tar.gz).


Additionally,

6). Use XML to build more complex configuration.
7). do()-ing the file instead of require()-ing it.


__END__
-- 
s::a::n-http(www.trabas.com)





Re-Mailer

2001-06-28 Thread Adam Theo


Hello, Adam Theo here;

does anyone know of a script to 're-mail' emails? i have a bunch of 
'saved' and 'archived' emails (in both Mozilla Inbox and RMAIL formats) 
stored on my local computer. i am looking for a script that will read 
these files, then re-send them to email accounts i specify, preserving 
sender, subject, and especially date intact.

if no-one knows of such a script, could they direct me to any modules 
they think will help? and also, does anyone know anything about the 
RMAIL format? such as how i could get perl to read that, or just as 
good, some other program that will convery it into a format that can be 
managed by an existing perl module/script for this sort of thing.

thanks.
--
   /\   Theoretic Solutions (www.Theoretic.com):
  //\\'Activism, Software, and Internet Services'
//--\\ Personal Homepage (www.Theoretic.com/adamtheo/):
   ][ 'Personal history, analysis, and favorites'
   ][   Birthright Online (www.Birthright.net):
  'Keeping the best role-playing game alive'
Email  Jabber:   Other:
-Professional: [EMAIL PROTECTED]  -AIM: AdamTheo2000
-General: [EMAIL PROTECTED]   -ICQ: 3617307
-Personal: [EMAIL PROTECTED]  -Phone: (850)8936047




Re: Clear screen

2001-06-28 Thread Hasanuddin Tamir

On Wed, 27 Jun 2001, jaya kumaran [EMAIL PROTECTED] wrote,

 Hi all,

I used this instruction to clear the screen on NT

system(cls);
print Hello;

   the same instruction is not working on unix. I modified the instruction to

   system(clear);
   print hello;

 This works fine on unix. Is there any instruction in perl to perfom clear
 screen and it works on both windows and Unix

First of all, if you're thinking about portable code, your first
resource to read will be the perlport manual page.  As said there,
nearly all Perl is already portable (one strategy is to emulate
missing functions for some poor system).

There will be a point that you really need to code in different ways
for different systems.  And you need the $^O special variable to
inspect the OS the script is running under.  Additionally, if you're
going to use this a lot, you better save the clear character in the
variable and print it later many times.

my $clear;
if ($^O =~ /mswin/i || $^O =~ /dos/i) {
$clear = `cls`;
} elsif ($^O eq 'linux') {
$clear = `clear`;
}
# add other checking here to support more systems
# (this is of course not a complete way for all needs)

Other strategy is by evaluating the expression to see if the function
is supported in the particular system.

eval {
is_this_function_supported();
};
die $@ if $@; # or you can just skip the function
  # and let the program continues

More in 'perldoc -f eval' on this.


__END__
-- 
s::a::n-http(www.trabas.com)




Populating string (scalar)

2001-06-28 Thread Rajeev Rumale

Hi

I need to assign a long multiline string value to a scalar.

I would like to know a way where  i can assing a string value to a scalar
with inserting the escape char(\).  something similar to what we do with
print

print  label;

.title $title./title.
..
label

Here we need not escape the / char in /title;
Can we use any similar method to assing a value to any scalar,

Sorry if I am asking a stupid question.

with regards

Rajeev Rumale

~~~
Rajeev Rumale
MyAngel.Net Pte Ltd.,Phone  :
(65)8831530 (office)
#04-01, 180 B, The Bencoolen,   Email  :
[EMAIL PROTECTED]
Bencoolen Street, Singapore - 189648 ICQ: 121001541
Website : www.myangel.net
~~~





- Original Message -
From: Nick Transier [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, June 27, 2001 10:50 PM
Subject: Incrementing Strings


 If I define a variable as a string
 my $var = a;

 I can get the increment to work
 print ++$var; -- prints b

 but the decrement
 print --$var -- prints -1

 Why? and how can I decrement it?


 Thanks,
 -Nick
 _
 Get your FREE download of MSN Explorer at http://explorer.msn.com






Re: Populating string (scalar)

2001-06-28 Thread Paul Johnson

On Thu, Jun 28, 2001 at 04:42:08PM +0800, Rajeev Rumale wrote:
 Hi
 
 I need to assign a long multiline string value to a scalar.
 
 I would like to know a way where  i can assing a string value to a scalar
 with inserting the escape char(\).  something similar to what we do with
 print
 
 print  label;
 
 .title $title./title.
 ..
 label

How about

my $var =  label;

.title $title./title.
..
label

:-)

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



system - rsh problem

2001-06-28 Thread Stefan Zwijsen


Hi,

I try to execute the following line on Solaris:
system (rsh,btzp17,`/usr/local/bin/perl -e foreach $line
(@allfiles) { print $line;}`) ;

@allfiles is a list of pathnames and files
The lines should be printed via a rsh on a station called btzp17.

If I execute
rsh btzp17 /usr/local/bin/perl -e 'foreach $line (@allfiles) { print
$line ;}'
at the command line it works.

From within the script it doesn't work. I receive the following error:
Bareword found where operator expected at -e line 1, near /var/adm
(Missing operator before adm?)
syntax error at -e line 1, near /var/adm 
Execution of -e aborted due to compilation errors.
(The /var/adm is expanded from @allfiles)

Thanks for any help,
Stefan.



Input redirection

2001-06-28 Thread jaya kumaran



Hi,

  I need the o/p of 
 perl -v 
   to be redirected to a file test.txt

  open(FILEHANDLE, test.txt) || die can't open the file;
print FILEHANDLE perl -v ;

one executing this , I get the following error

Unrecognized file test: -v at D:\test\perl\TEST1.PL line 6.

How to write the o/p of 'perl -v' in the file(test.txt).

Thanks in advance,
jaya

_
Get Free Fast Easy email from indiya.com: SIGNUP NOW : http://www.indiya.com



RE: Input redirection

2001-06-28 Thread John Edwards

You could print the verion like this

open(FILEHANDLE,test.txt) or die Can't open the file: $!;
print FILEHANDLE $]\n; # $] is the special variable that holds the running
version of Perl
close FILEHANDLE;

or if you really want the output of perl -v

$returned = `perl -v`;

open(FILEHANDLE,test.txt) or die Can't open the file: $!;
print FILEHANDLE $returned\n;
close FILEHANDLE;

HTH

John

-Original Message-
From: jaya kumaran [mailto:[EMAIL PROTECTED]]
Sent: 28 June 2001 11:16
To: [EMAIL PROTECTED]
Subject: Input redirection




Hi,

  I need the o/p of 
 perl -v 
   to be redirected to a file test.txt

  open(FILEHANDLE, test.txt) || die can't open the file;
print FILEHANDLE perl -v ;

one executing this , I get the following error

Unrecognized file test: -v at D:\test\perl\TEST1.PL line 6.

How to write the o/p of 'perl -v' in the file(test.txt).

Thanks in advance,
jaya

_
Get Free Fast Easy email from indiya.com: SIGNUP NOW : http://www.indiya.com


--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.





Re: Input redirection

2001-06-28 Thread Hasanuddin Tamir

On Thu, 28 Jun 2001, jaya kumaran [EMAIL PROTECTED] wrote,

 Hi,

   I need the o/p of
  perl -v
to be redirected to a file test.txt

   open(FILEHANDLE, test.txt) || die can't open the file;
 ^
 |
I hope this is just a typo, you missed the opening double-quote.
But you need to include $! as well so you know exactly the reason
when the open() fails.

 print FILEHANDLE perl -v ;

 one executing this , I get the following error

 Unrecognized file test: -v at D:\test\perl\TEST1.PL line 6.

 How to write the o/p of 'perl -v' in the file(test.txt).

You must treat 'perl -v' as shell command by enclosing it in the
backticks to get the output,

print FILEHANDLE `perl -v`;

More on this is in the Quote and Quote-like Operators entry in perlop
manpage.


Otherwise, bare '-v' will be treated as file test operator.
Perl has a plenty of file test operator in this form, -f to
test if the argument is a file, -d if a directory, -s to get
the size, etc.  perldoc -f -X for more on this.

Anyway, is it really hard to do,

perl -v  test.txt

from the command line?


__END__
-- 
s::a::n-http(www.trabas.com)





Re: Running PERL as root

2001-06-28 Thread Karthik Krishnamurthy

Cobalt RaQ runs apache as root so that their front-end can run with root
perms. You could use cgiwrap for the same effect, i suppose. there is also
webmin, which runs with root priveleges. but webmin has its own httpd server
coded in perl (thereby reducing the chances of buffer overflows and such)
as webmin comes with a BSD style licence, you could cannibalize it for your 
needs

there was a thread on bugtraq about the merits of running apache as root. 
as apache has a pretty good safety record, you should be able to run apache 
as root pretty safely. however if you are a little more paranoid, try cgiwrap.

BEWARE: the idea of running a CGI script to administrate a server is pretty
idiotic, in my opinion. i am trying to code a web based front end for 
virtual/ip hosting web servers like cobalt's, so i understand the necessity in
certain cases. however, it is frightening and goes against all accepted 
security norms.

kk

On Wed, Jun 27, 2001 at 11:12:34PM -0400, Bill Pierson wrote:
 Thanks for your replies. Actually, I'd like to be able to modify system
 config files, stop and restart daemons, etc.
 
 I'm not aware of the different ways to accomplish this; any tips would be
 appreciated.
 
 The server is in a protected environment.
 
 
 --Bill
 
 
 -Original Message-
 From: Farouk Khawaja [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, June 27, 2001 10:44 PM
 To: Bill Pierson; [EMAIL PROTECTED]
 Subject: Re: Running PERL as root
 
  Bill Pierson [EMAIL PROTECTED] wrote:
  I have a quick question about running a perl
 program as root via CGI.
  I would assume it's platform dependant, and in my
 situation I have Linux
  Redhat 7.1 w/Apache 1.3.19 webserver.
 
  This question is a little off-topic, however I'm
 guessing that a few of you
  may have tackled this issue before.
 
  Thanks again,
  --Bill
 
 I wouldn't run any CGI script as root, no matter how
 securly I belive I've written it.  What are you
 trying to do that would require root permission to
 accomplish?
 
 Maybe you can explore alternatives.
 
 



Re: substr (help,help,help);

2001-06-28 Thread Craig S Monroe


 btw, why did you say 4, not 5? 'Login' has 5 characters last time I
looked!

I had a momentary (so I thought) lapse of confusion and applied the offset
rule to the
length (e.g. first character is 0).

grab a copy of that part of the string, then throw it in to the great big
bit void in the sky

That was stupid mistakehello, no clue what I was thinking...

($mybit) = m#/nic/login/([^]*?)#;

This explanation was extremely helpful

Thank you for taking the time explain each of my issues.

Another satisfied customer.thank you again!!

Craig
[EMAIL PROTECTED]
Pager
Numeric: 1-877-895-3558
Email pager: [EMAIL PROTECTED]
--
You will never find time for anything.
If you want time, you must make it.

Charles Buxton

- Original Message -
From: Me [EMAIL PROTECTED]
To: Craig S Monroe [EMAIL PROTECTED]; Beginners@Perl (E-mail)
[EMAIL PROTECTED]
Sent: Wednesday, June 27, 2001 5:45 PM
Subject: Re: substr (help,help,help);


  while (SOURCE){
   if (m/\/nic\/login/){

 this just says yes or no, you have a match or you don't.
 m// (and friends like s///) can do more than that for you.
 for one thing, they can grab a particular piece of what
 they match.

   substr ($_,28,4);

 what substr normally does -- get or change a piece of
 a string -- overlaps what m// and friends can do. if you
 are already using m// or friend it's often simpler to use
 that to do what substr can do.

 in the above case, substr isn't doing anything at all!
 you don't set that part of the string to anything, nor do
 you set any variable to contain the bit that's grabbed.
 you're simply saying, grab a copy of that part of the
 string, then throw it in to the great big bit void in the
 sky. you could do:

 $foo = substr($_, 28, 4);

 but, as noted above, it's easier to extend your use of m//.

 btw, why did you say 4, not 5? 'Login' has 5 characters
 last time I looked!

 back to m//. Try this:

 ($mybit) = m#/nic/login/([^]*?)#;

 I used # as the m delimiters so you don't have
 to escape the / characters.

 the (...) is the bit that grabs something.

 the [^] bit means match anything but a  character.
 the * bit means match any number of non 's.
 the ? bit means match as few as still makes the
 match true (if possible). (otherwise the grabbed bit
 would be the rest of the line up to just before the last 
 encountered.





javascript-detail

2001-06-28 Thread Prachi Shroff

Hi folks,

Well, I am actually implementing an LWP::UserAgent to walk through a website 
and do the things I want it to and get me the desired results(dont 
worry, this is a noble cause :-) ) and my problem is that there are some 
javascripts on that webpage which I need to execute thru my perl 
code.and I have not been able to find a way to do it. I do not have the 
code for those javascripts, all I know is the way they are called and run on 
the webpage.
Hope this is clear enough. Can anyone come up with any clues now?

thanks,
Prachi
_
Get your FREE download of MSN Explorer at http://explorer.msn.com




RE: javascript-detail

2001-06-28 Thread John Edwards

you could try downloading the javascript code from the server. If the code
is in external files and added into the page like so

script language=JavaScript1.2 src=/code/script.js/script

You should be able to download the code by grabing the matching URL. E.g
http://servername/code/script.js

Running it within Perl is another matter entirely and I have no clue on
that...

John

-Original Message-
From: Prachi Shroff [mailto:[EMAIL PROTECTED]]
Sent: 28 June 2001 14:24
To: [EMAIL PROTECTED]
Subject: javascript-detail


Hi folks,

Well, I am actually implementing an LWP::UserAgent to walk through a website

and do the things I want it to and get me the desired results(dont 
worry, this is a noble cause :-) ) and my problem is that there are some 
javascripts on that webpage which I need to execute thru my perl 
code.and I have not been able to find a way to do it. I do not have the 
code for those javascripts, all I know is the way they are called and run on

the webpage.
Hope this is clear enough. Can anyone come up with any clues now?

thanks,
Prachi
_
Get your FREE download of MSN Explorer at http://explorer.msn.com


--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.





RE: FW: rmdir

2001-06-28 Thread Porter, Chris

Mike,

Still unsure how to approach.  Very new to perl and I don't want to screw
this up.  Any input from you would be great.  Thank you.

Chris

-Original Message-
From: Michael Fowler [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 27, 2001 5:27 PM
To: Me
Cc: Porter, Chris; [EMAIL PROTECTED]
Subject: Re: FW: rmdir


On Wed, Jun 27, 2001 at 03:51:43PM -0500, Me wrote:
 Basically, you have to write a sub that does the
 following sort of thing (ignoring your wrinkle that
 you don't want to delete all the files in the initial
 directory):

Or you could use File::Path::rmtree.  I'm surprised no one has given this
answer yet.


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



background processing (again?)

2001-06-28 Thread Ronald J. Yacketta

Folks,

to make a long story short I have a req to-do the following.
1) gather continues data from netstat -I hme0 $SLEEPTIME  $netstatTMPFILE 
while still parsing other information/data etc..

that is, the script needs to be bale to collect the netstat data while it is
running other process, not just fork netstat and wait for it to die/return.
it will never die/return unless it is killed.

Regards,
Ron




Re: background processing (again?)

2001-06-28 Thread David M. Lloyd

On Thu, 28 Jun 2001, Ronald J. Yacketta wrote:

 Folks,
 
 to make a long story short I have a req to-do the following. 1) gather
 continues data from netstat -I hme0 $SLEEPTIME  $netstatTMPFILE 
 while still parsing other information/data etc..
 
 that is, the script needs to be bale to collect the netstat data while
 it is running other process, not just fork netstat and wait for it to
 die/return. it will never die/return unless it is killed.

Try something like this:

open NETSTAT, netstat -I hme0 $SLEEPTIME | or die Can't start netstat: $!\n;

Then, just read from the NETSTAT filehandle.

For more information, look at 'open' and 'sysopen' in the Camel book.  
Also, you may want to consider using 'select' if you don't want to block
on reads.  (Be sure you look at the 'ready file descriptors' version of
'select').


- D

[EMAIL PROTECTED]




Re: arrays

2001-06-28 Thread Bill Pierson

I'm a learner myself, but here is a quick guess:
open(IN,/etc/httpd/conf/httpd.conf) || die $!;
@conf = IN;
close(IN);

foreach (@conf) {
if ($_ =~ /ServerName (.*)/i) {
push (@servers,$1);
}
}
print @servers\n;

You may also need to put in a exclusion for the main servername directive at
the beginning of the conf file if you don't want that included in your list.
This example also assumes that there is only 1 space between the server name
and the actual server name.

Hope this helps,
--Bill



- Original Message -
From: Tyler Longren [EMAIL PROTECTED]
To: Perl Beginners [EMAIL PROTECTED]
Sent: Thursday, June 28, 2001 9:44 AM
Subject: arrays


Hello everyone,

I'm just starting perl.  I want to search through httpd.conf and get the
ServerName from each virtual host.
Ex:
VirtualHost *
DocumentRoot /home2/ploo.net/www
ServerName www.ploo.net
CustomLog /home2/ploo.net/logs/access_log
ErrorLog /home2/ploo.net/logs/error_log
TransferLog /home2/ploo.net/logs/transfer_log
ScriptAlias /cgi-bin/ /home2/ploo.net/cgi-bin/
/VirtualHost
VirtualHost *
DocumentRoot /home2/test.net/www
ServerName www.test.net
CustomLog /home2/test.net/logs/access_log
ErrorLog /home2/test.net/logs/error_log
TransferLog /home2/test.net/logs/transfer_log
ScriptAlias /cgi-bin/ /home2/test.net/cgi-bin/
/VirtualHost

Could I get the ServerName values put into an array so I can do something
with each different ServerName?  Thank you everyone.

Tyler






Re: arrays

2001-06-28 Thread dave hoover

Tyler wrote:

 Hello everyone,
 
 I'm just starting perl.  I want to search through
 httpd.conf and get the
 ServerName from each virtual host.
 Ex:
 VirtualHost *
 DocumentRoot /home2/ploo.net/www
 ServerName www.ploo.net
 CustomLog /home2/ploo.net/logs/access_log
 ErrorLog /home2/ploo.net/logs/error_log
 TransferLog
 /home2/ploo.net/logs/transfer_log
 ScriptAlias /cgi-bin/
 /home2/ploo.net/cgi-bin/
 /VirtualHost
 VirtualHost *
 DocumentRoot /home2/test.net/www
 ServerName www.test.net
 CustomLog /home2/test.net/logs/access_log
 ErrorLog /home2/test.net/logs/error_log
 TransferLog
 /home2/test.net/logs/transfer_log
 ScriptAlias /cgi-bin/
 /home2/test.net/cgi-bin/
 /VirtualHost
 
 Could I get the ServerName values put into an array
 so I can do something
 with each different ServerName?  Thank you everyone.
 
 Tyler

Try this:

-
open(FILE, httpd.conf);
while (FILE) {
push(@server_names, $1) if /ServerName\s+(.*)/
}
close FILE;
-

Now the array @server_names holds the values you want.

HTH


=
Dave Hoover
Twice blessed is help unlooked for. --Tolkien
http://www.redsquirreldesign.com/dave

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Re: arrays

2001-06-28 Thread Tyler Longren

Thank you everyone.  All of you have been a great help.  That is exactly
what I need.  I'll figure out how to get just the servernames from the
VirtualHosts myself (I'll try anyway)  ;-)

Thanks!
Tyler

- Original Message -
From: Brett W. McCoy [EMAIL PROTECTED]
To: Tyler Longren [EMAIL PROTECTED]
Cc: Perl Beginners [EMAIL PROTECTED]
Sent: Thursday, June 28, 2001 9:18 AM
Subject: Re: arrays


 On Thu, 28 Jun 2001, Tyler Longren wrote:

  I'm just starting perl.  I want to search through httpd.conf and get the
  ServerName from each virtual host.

 Sure:

 open(APACHE_CONF, httpd.conf) or die Could not open Apache config file:
 $!\n;

 my @servernames;

 while(APACHE_CONF) {

 if(/^ServerName\s(.*)$/i) {
 push @servernames, $1;
 }
 }

 close(APACHE_CONF);

 -- Brett

http://www.chapelperilous.net/btfwk/
 
 Tuesday After Lunch is the cosmic time of the week.




die / exit / style question

2001-06-28 Thread Ela Jarecka

Hi folks,
I have a couple of doubts/questions about the usage of above functions:

1. will those three always work the same ( I have troubles understanding the
'die' description in Llama book ( $!, $?8, the status of the last reaped
child from a system, wait, close on a pipe, or `command`))?:

if ( ( $reqrec-fillServ($ServRef) ) == undef ) {
   print fillRec failed! \n;
   exit;
}

if ( ( $reqrec-fillServ($ServRef) ) == undef ) {
   die fillRec failed! \n;
}

$reqrec-fillServ($ServRef) or die fillServ failed;

In fillServ function, I use 'return;' upon failure and 'return 1;' if
everything is OK. 

2. is it a matter of style to use 'not defined(_expression_)' or
(_expression_) == undef? I get warnings in the second case..
Will defined cover also an empty string?

Any comments will be greatly appreciated, as it is my first bigger program
in Perl and I would like it to work flawless...

Ela




Works, but can it be better?

2001-06-28 Thread Bradley Wendelboe

Greetings,

The following script queiries the status of NT services.  My question is
there a way to directly query the @servicenames{name} and get the value of a
sub key in that hash?  Now I search all {name} keys and continue from there.

Also, how can I get rid of blank line feeds in the input file?  The format
is:

Server:Service

If I have more than one \n after the last entry, it tries to test for them!

Thanks,

Bradley

use strict;
use diagnostics;
use Win32::Lanman;
use vars qw(@status %status @servicenames $server $myservice $service);

#Translate error codes to text.
push ( @status, qw(7 Paused 4 Started 3 Stopping 2 Starting 1 Stopped) );
%status = @status;

#Load server/services to be queried.
open( LIST, c:\\test\\SerSvs.txt );

while (LIST) {
chomp;
( $server, $myservice ) = split (/:/);
if
  ( !Win32::Lanman::EnumServicesStatus( $server, ,
SERVICE_WIN32,
  SERVICE_STATE_ALL, \@servicenames ) )
{
print Sorry, something went wrong connecting to $server; error: ;

# get the error code
print Win32::Lanman::GetLastError () . \n;
}
for $service(@servicenames) {
if ( ${$service}{name} eq $myservice ) {
print $server ${$service}{name}\n;
print Status $status{${$service}{state}}\n;

}
}
}
close LIST




Re: die / exit / style question

2001-06-28 Thread Jeff 'japhy' Pinyan

On Jun 28, Ela Jarecka said:

if ( ( $reqrec-fillServ($ServRef) ) == undef ) {
   print fillRec failed! \n;
   exit;
}

This prints a message to STDOUT (or the currently select()ed handle), and
exits the program with an error code of 0.

Testing for equality with undef is a mistake.

if ( ( $reqrec-fillServ($ServRef) ) == undef ) {
   die fillRec failed! \n;
}

This prints a message to STDERR (or gets caught by $SIG{__DIE__} first),
and exits the program with a NON-ZERO error code (signifying that the
program terminated abnormally).

Testing for equality with undef is (still) a mistake.

$reqrec-fillServ($ServRef) or die fillServ failed;

This is good.

In fillServ function, I use 'return;' upon failure and 'return 1;' if
everything is OK. 

You should not test for equality with undef, because undef becomes NOT
undef when used in any context.

  print 2 + undef; # becomes 2 + 0, albeit with a warning
  print hi . undef;  # becomes hi . , albeit with a warning

  if ($x == undef) {
# you get here if $x is 0, '', or undef
  }

  if ($x eq undef) {
# you get here if $x is '' or undef
  }

Instead, use the defined() approach:

  if (not defined $x) {
# $x can ONLY have the value of undef if it gets here
  }

However, you can treat undef as false (since it is) in a boolean
expression:

  # this IS a silly way to write this function, but nevermind
  sub large_number {
return if $_[0]  1_000_000;
return 1;
  }

  if (large_number($foo)) {
# it's big if it got here
  }

You don't need to test for == 1 or == undef or defined(...), because 1 is
true, and undef is false.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
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
**  Manning Publications, Co, is publishing my Perl Regex book  **




Re: arrays

2001-06-28 Thread Tyler Longren

One more quick question.  How can I count the values in an array
(@servernames)?
I want to print my servernames seperately:

$i=0;
while ($i = $num_servers) {
print $servernames[$i]\n;
}
Something like that (I don't know if that will even work in perl...but it
does in PHP).

Thanks!
Tyler


- Original Message -
From: Brett W. McCoy [EMAIL PROTECTED]
To: Tyler Longren [EMAIL PROTECTED]
Cc: Perl Beginners [EMAIL PROTECTED]
Sent: Thursday, June 28, 2001 9:18 AM
Subject: Re: arrays


 On Thu, 28 Jun 2001, Tyler Longren wrote:

  I'm just starting perl.  I want to search through httpd.conf and get the
  ServerName from each virtual host.

 Sure:

 open(APACHE_CONF, httpd.conf) or die Could not open Apache config file:
 $!\n;

 my @servernames;

 while(APACHE_CONF) {

 if(/^ServerName\s(.*)$/i) {
 push @servernames, $1;
 }
 }

 close(APACHE_CONF);

 -- Brett

http://www.chapelperilous.net/btfwk/
 
 Tuesday After Lunch is the cosmic time of the week.




RE: Gzip on Win32

2001-06-28 Thread Wright, James C.

For a great free Unix-like command line interface for Win32, install Cygwin.
It gives you many of the Gnu tools (including gzip) in its original install,
and you can install others (such as Perl).  Look at
http://www.xav.com/perl/lib/Pod/perlcygwin.html.
-jim

-Original Message-
From: David Simcik [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 28, 2001 11:05 AM
To: Perl Beginners
Subject: Gzip on Win32


Hey,
I'm hoping this will be a straighforward question...I'm assuming I
need a
command-line interface GZip utility to work with the MCPAN installation
utility??? Where can I find one?

Thanks.
DTS



RE: delete the last string

2001-06-28 Thread Ronald J. Yacketta

 I want to delete a string but only the last.

You could search backwards in the string and remove the first occurrence
I do not have the details on doing this, but from reading the master regex
book, it can be done

I am sure others with more perl exp can cough up an example or two..


-Ron




Re: arrays

2001-06-28 Thread Brett W. McCoy

On Thu, 28 Jun 2001, Tyler Longren wrote:

 One more quick question.  How can I count the values in an array
 (@servernames)?
 I want to print my servernames seperately:

my $server_count = @servernames;

An array used in a scalar context returns the number of elements in the
array.

or you could do

foreach my $i (0..$#servernames) {

print $servernames[$i]\n;
}

$#array returns the index of the last element, which is usually the number
of elements - 1.

-- Brett
   http://www.chapelperilous.net/btfwk/

I'm not stupid, I'm not expendable, and I'M NOT GOING!




deleting a line with a particular string.

2001-06-28 Thread Deepesh Tiwari

---
I have a file having 100 lines.
I want to remove the lines, having a particular string, completely from the
file. (notreplacing them with blank lines even)

Is there a way in perl for doing this ?

--deepesh





Re: delete the last string

2001-06-28 Thread Chas Owens

Reverse the string, reverse the pattern, do the substitue, reverse the
string again.

the string is I am the titi last human on titi earth.
the pattern is /titi/

so reverse the string (with reverse in a scalar context):
.htrae itit no namuh tsal  itit eht ma I

reverse the pattern /itit/

do the substitute

reverse the string again to make it normal again.

code
#!/usr/bin/perl -w

use strict;

my $str = I am the titi  last human on titi earth.;

my $rev = reverse $str;

$rev =~ s/itit//;

$str = reverse $rev;

print $str\n;
/code



On 28 Jun 2001 16:58:03 +0200, Stéphane JEAN BAPTISTE wrote:
 
 
 Hi
 
 I want to delete a string but only the last.
 Example/
 
 
 I am the titi  last human on titi earth.
 
 
 - I want to erase the last titi nut not the other.
 
 How can I do this
 
 thanks
 
--
Today is Prickle-Prickle, the 33rd day of Confusion in the YOLD 3167
Or is it?





Re: delete the last string

2001-06-28 Thread Chas Owens

An important note:

Be very careful when reversing the regexp /$* / is not the reverse of
/ *$/ (/^ */ is).

On 28 Jun 2001 11:14:58 -0400, Chas Owens wrote:
 Reverse the string, reverse the pattern, do the substitue, reverse the
 string again.
 
 the string is I am the titi last human on titi earth.
 the pattern is /titi/
 
 so reverse the string (with reverse in a scalar context):
 .htrae itit no namuh tsal  itit eht ma I
 
 reverse the pattern /itit/
 
 do the substitute
 
 reverse the string again to make it normal again.
 
 code
 #!/usr/bin/perl -w
 
 use strict;
 
 my $str = I am the titi  last human on titi earth.;
 
 my $rev = reverse $str;
 
 $rev =~ s/itit//;
 
 $str = reverse $rev;
 
 print $str\n;
 /code
 
 
 
 On 28 Jun 2001 16:58:03 +0200, Stéphane JEAN BAPTISTE wrote:
  
  
  Hi
  
  I want to delete a string but only the last.
  Example/
  
  
  I am the titi  last human on titi earth.
  
  
  - I want to erase the last titi nut not the other.
  
  How can I do this
  
  thanks
  
 --
 Today is Prickle-Prickle, the 33rd day of Confusion in the YOLD 3167
 Or is it?
 
 
 
--
Today is Prickle-Prickle, the 33rd day of Confusion in the YOLD 3167
Keep the Lasagna flying!





RE: deleting a line with a particular string.

2001-06-28 Thread Ronald J. Yacketta


 I have a file having 100 lines.
 I want to remove the lines, having a particular string, 
 completely from the
 file. (not replacing them with blank lines even)
 
 Is there a way in perl for doing this ?

most defiantly, tho I am a novice at perl right now.
I have sent this to the beginners list to get more help.

-Ron




Hash of arrays

2001-06-28 Thread F.H

Hi All,

I just wonder why the if condition is always true regardless of the value of the array 
AB.
@AB = [1,2], and $i gets printed even for values not inlcuded in array AB.

foreach $i ( 0 .. $#{ $testsec{'AB'} } ) {
if ($testsec{'AB'}[$i] = 6543){ # always true
 print $i\n;
}
else { last ;}
print  $testsec{'AB'}[$i]\n;
}
}

I appreciate if someone can help.

I.S   
__
Get your own FREE, personal Netscape Webmail account today at 
http://webmail.netscape.com/



Screen refresh

2001-06-28 Thread sevoski


Hello,
I would like to know of a way to refresh a console screen, opposed to just
augmenting the console text. This would help greatly in making simple
menus. 

 --Sebastian Lisic






Re: Hash of arrays

2001-06-28 Thread Paul


--- F.H [EMAIL PROTECTED] wrote:
 I just wonder why the if condition is always true regardless of the
 value of the array AB.
 if ($testsec{'AB'}[$i] = 6543){ # always true

Because = is an assignment. =o)

 print foo if $x = 65343; 

will always print, because = returns the 6543 assigned, which is true.

Try == instead. ;o]

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Re: arrays

2001-06-28 Thread dave hoover

Tyler wrote:
 One more quick question.  How can I count the values
 in an array
 (@servernames)?
 I want to print my servernames seperately:
[snip]

Tyler,

To get a numeric count of the elements in
@servernames, do this:

$count = @servernames;  # count now equals the number
of elements in @servernames

To print out each of the elements, do this:

foreach $name (@servernames) {
 print $name\n;
}

Another way to do the above is this:

for (@servernames) {
 print $_\n;  # when no placeholder variable is
specified, by default the $_ variable is used
}

HTH,


=
Dave Hoover
Twice blessed is help unlooked for. --Tolkien
http://www.redsquirreldesign.com/dave

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Fork (not the kind you eat with)

2001-06-28 Thread Pierre Smolarek

The one thing in perl that gets my head all confused is fork.

Can someone point me in the right direction (be it book, website, or kind
enough to offer code).

I need to make a script that has to check 16000 servers in around 6 minutes.
My rough maths works out that 44 checks a second are needed. Each server
check takes about 0.5 seconds to return, so the best bet is to fork each
individual check, the result of which gets added to mysql so no need to have
a conversation going on between child and parent. Idealy i would like to
control the max amount children i have to, say, around 50.

Any help would be greatful.

(I have the cook book open but only seems to talk about a single parent
child pair..?!)


Pierre.




referencing a flat file DB

2001-06-28 Thread Jon Riddle

Hello everyone,
I am trying to create a simple cgi script that if a user enters the
correct information on a contest form, they are entered into a flat-file DB.
This I have conquered.  My next feat is that before I write their personal
information into the DB, I am comparing 3 fields from the DB to 3 fields
being submitted by the user for duplicate submissions in sub one_time (the
fields are phone number fields).  The problem is, is that I never get a
match and the user is able to submit an infinite amount of time.  Here is my
source code.  It's only about 65 lines.  Thank you for  your help!

Jon Riddle
Interactive Gallery Inc.
Phone- 818-501-4486 ext. 3037
Email- [EMAIL PROTECTED]

The three great virtues of a programmer are
laziness, impatience and hubris.
  Larry Wall 

#!/usr/local/bin/perl -w

use CGI;
use CGI::Carp qw(carpout fatalsToBrowser);
$Q = CGI;

$content_length = $ENV{'CONTENT_LENGTH'};
read (STDIN, $posted_information, $content_length);

$posted_information =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack (C, hex ($1))/eg;
$posted_information =~ s/\+/ /g;

@fields = split (//, $posted_information);

($label, $name) = split (/=/, $fields[0]);
($label, $street) = split (/=/, $fields[1]);
($label, $city) = split (/=/, $fields[2]);
($label, $state) = split (/=/, $fields[3]);
($label, $zip) = split (/=/, $fields[4]);
($label, $PHONE_AREA) = split (/=/, $fields[5]);
($label, $PHONE_PRE) = split (/=/, $fields[6]);
($label, $PHONE_SUFF) = split (/=/, $fields[7]);
($label, $serviceProvider) = split (/=/, $fields[8]);
($label, $lapDance) = split (/=/, $fields[9]);
($label, $lapDance2) = split (/=/, $fields[10]);
($label, $lapDance3) = split (/=/, $fields[11]);
($label, $lapDance4) = split (/=/, $fields[12]);
($label, $lapDance5) = split (/=/, $fields[13]);

#Compares correct anwsers
$lapResults .= ,$lapDance,$lapDance2,$lapDance3,$lapDance4,$lapDance5;
if ($lapResults eq
,AvaVincent,JessicaDrake,JewellDeNyle,ShaylaLaVeaux,ShaySweet) { $correct
= 1}


if (!$correct) {
print $Q-redirect('http://www.ten.com/contest/thanklost.htm');
}
else {
if  (one_time(1)) {
print
$Q-redirect('http://www.ten.com/contest/already.html');
}
else {
open (OUTPUT,  lapdance.db) || die Cannot open lapdance.db: $!;
print OUTPUT $name, :, $street, :, $city, :, $state, :,
$zip,:, $PHONE_AREA, :, $PHONE_PRE, :, $PHONE_SUFF,\n;
close OUTPUT;
print $Q-redirect('http://www.ten.com/contest/thankwon.htm');
}
}
# Routine that checks DB for previous valid 
# entry comparing telephone number
sub one_time {
open (VARIFY,  lapdance.db) || die Cannot open lapdance.db: $!;
while (VARIFY) {
$stats = VARIFY;
$compare = { split (/:/, $stats)};
@records = \$compare;
if (($records[6] eq $PHONE_AREA)  ($records[7] eq
$PHONE_PRE)  ($records[8] eq $PHONE_SUFF)) {
$sorry = 1;
}
}
close VARIFY;
return $sorry;
}
# EOF ### 




Re: simple regex question

2001-06-28 Thread Paul


--- Mike Ring [EMAIL PROTECTED] wrote:
 I've learned a bit about regular expressions today. I have a string
 formatted
 like CN=foo,OU=bar,O=pah and I need to parse out foo. I have
 created the
 following code which does work:
 
 $dnvalue =~ m/([^,]*)/;
 $username = $1;
 $username =~ s/(CN=)//;
 print $username
 
 However, I'd like to do the match/replace on a single line. Can
 anyone show me
 how to combine these statements into a more elegant regular
 expression?

 my ($cn) = $dnvalue =~ /^CN=([^,]*),/;

The list context provided by the parens around $cn will make the match
return the value found. =o)

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



RE: simple regex question

2001-06-28 Thread John Edwards

There's no need to match past the CN=, then prepend the CN= back to the
string. Use the following

$dnvalue = CN=foo,OU=bar,O=pah;

$dnvalue =~ /(CN=[A-Za-z0-9]*)/;
$username = $1;
print $username

This looks for CN= followed by any number of letters (upper or lowercase)
and numbers. If you don't mind matching on an underscore too (_) use the
following instead

$dnvalue =~ /(CN=\w*)/;


HTH

John

-Original Message-
From: Mike Ring [mailto:[EMAIL PROTECTED]]
Sent: 28 June 2001 17:17
To: [EMAIL PROTECTED]
Subject: simple regex question



Hello all.

I've learned a bit about regular expressions today. I have a string
formatted
like CN=foo,OU=bar,O=pah and I need to parse out foo. I have created the
following code which does work:

$dnvalue =~ m/([^,]*)/;
$username = $1;
$username =~ s/(CN=)//;
print $username

However, I'd like to do the match/replace on a single line. Can anyone show
me
how to combine these statements into a more elegant regular expression?

Thanks,
Mike


--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.





Re: FW: rmdir

2001-06-28 Thread Michael Fowler

On Thu, Jun 28, 2001 at 09:49:32AM -0400, Porter, Chris wrote:
 Still unsure how to approach.  Very new to perl and I don't want to screw
 this up.  Any input from you would be great.  Thank you.
 
 -Original Message-
 From: Michael Fowler [mailto:[EMAIL PROTECTED]]

 Or you could use File::Path::rmtree.  I'm surprised no one has given this
 answer yet.

Your best bet to figuring out how to use File::Path::rmtree is to read
perldoc File::Path, or http://www.perldoc.com/perl5.6/lib/File/Path.html. 
It's all pretty straightforward.


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



RE: simple regex question

2001-06-28 Thread John Edwards

Sorry. Ignore that. It's 5:30 and home time. What can I say.

Use this instead.

$dnvalue =~ /CN=(\w*)/;
$username = $1;
print $username

-Original Message-
From: John Edwards [mailto:[EMAIL PROTECTED]]
Sent: 28 June 2001 17:31
To: 'Mike Ring'; [EMAIL PROTECTED]
Subject: RE: simple regex question


There's no need to match past the CN=, then prepend the CN= back to the
string. Use the following

$dnvalue = CN=foo,OU=bar,O=pah;

$dnvalue =~ /(CN=[A-Za-z0-9]*)/;
$username = $1;
print $username

This looks for CN= followed by any number of letters (upper or lowercase)
and numbers. If you don't mind matching on an underscore too (_) use the
following instead

$dnvalue =~ /(CN=\w*)/;


HTH

John

-Original Message-
From: Mike Ring [mailto:[EMAIL PROTECTED]]
Sent: 28 June 2001 17:17
To: [EMAIL PROTECTED]
Subject: simple regex question



Hello all.

I've learned a bit about regular expressions today. I have a string
formatted
like CN=foo,OU=bar,O=pah and I need to parse out foo. I have created the
following code which does work:

$dnvalue =~ m/([^,]*)/;
$username = $1;
$username =~ s/(CN=)//;
print $username

However, I'd like to do the match/replace on a single line. Can anyone show
me
how to combine these statements into a more elegant regular expression?

Thanks,
Mike


--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.





RE: referencing a flat file DB

2001-06-28 Thread mark crowe (JIC)

Hi Jon

Hey, is this a competition to identify lapdancers or something? If so, don't
forget to post the URL up here when you've got it working ;-) (especially
since we now know all the answers)

Anyway, one thing that might be causing problems is these two lines in your
one_time sub
   $compare = { split (/:/, $stats)};
   @records = \$compare;

I think you'd be better off to use:
@records = split (/:/, $stats)

At the moment you are splitting to a scalar (which I think just puts the
first (or is it the last?) value from that split into the scalar) and then
assigning a reference to that scalar as an array. I'm sure that's not good
for you (and I'm a bit surprised that -w didn't pick it up, or haven't you
tried it from the command line?)

Other than that I can't see anything that should actually stop it working.
It's not the prettiest code I've ever seen though...

Cheers

Mark C


 Hello everyone,
   I am trying to create a simple cgi script that if a 
 user enters the
 correct information on a contest form, they are entered into 
 a flat-file DB.
 This I have conquered.  My next feat is that before I write 
 their personal
 information into the DB, I am comparing 3 fields from the DB 
 to 3 fields
 being submitted by the user for duplicate submissions in sub 
 one_time (the
 fields are phone number fields).  The problem is, is that I 
 never get a
 match and the user is able to submit an infinite amount of 
 time.  Here is my
 source code.  It's only about 65 lines.  Thank you for  your help!
 



Re: delete the last string

2001-06-28 Thread Jeff 'japhy' Pinyan

On Jun 28, Chas Owens said:

An important note:

Be very careful when reversing the regexp /$* / is not the reverse of
/ *$/ (/^ */ is).

So how can you reverse a regex safely?  Try YAPE::Regex::Reverse... ;)

Actually, I've not released it yet.  But it works quite well:

  jpinyan@sushi [12:42pm] ~ #614 perl rev-test
  (?-xism: *$)
  reversed: (?-imsx:^\n? *)

Upon reversing the reversed, we'd get

  (?-imsx: *\n?\z)

which is proper.  I've not released it yet because I've not added handlers
for ^ and $ under the /m modifier.

  (?m-isx: *$) [matches abc\ndef  \nghi\n]
  reversed: (?m-isx:^ *) [matches \nihg\n  fed\ncba]

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
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
**  Manning Publications, Co, is publishing my Perl Regex book  **





Re:[OT:style]deleting a line with a particular string.

2001-06-28 Thread Paul


--- Me [EMAIL PROTECTED] wrote:
  I have a file having 100 lines.
  I want to remove the lines, having a particular string, completely
  from the file. (notreplacing them with blank lines even)
 
  Is there a way in perl for doing this ?
 
 At a shell prompt / command line, enter:
 
 perl -ne '/string/ or print' file
 
 where string is the string and file is the file.

I prefer 'print unless /string/'. 
As if it matters. ;o] 


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



passing parameters to Perl script

2001-06-28 Thread Scott Taylor

Hello,

How can I pass parameters from *nix command line to a Perl script?
  Like $1 in shell scripting.

#!/usr/bin/perl -w

$myfile = $1;

doesn't work.

Thanks.

Scott




Re: passing parameters to Perl script

2001-06-28 Thread Jeff 'japhy' Pinyan

On Jun 28, Scott Taylor said:

How can I pass parameters from *nix command line to a Perl script?
  Like $1 in shell scripting.

You want the @ARGV array.  $ARGV[0] is the first argument to your
program.  Check the 'perlvar' documentation for more about @ARGV.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
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
**  Manning Publications, Co, is publishing my Perl Regex book  **




Re: confusing Perl idioms and practices

2001-06-28 Thread Peter Scott

At 09:52 AM 6/28/01 -0700, Gregg Williams wrote:

Hi--I recently posted a message titled writing readable Perl. In it, I
said:

snip

This is a simple example--too simple for some--but it gives you an idea of
what I'm looking for. Thanks again for your time.

Readable is like obscene (in more ways than one, in some code I've 
seen).  I spent a little time in my book (one day I hope to have to say 
which book :-) going over pros and cons of different takes on this.  But as 
it stands, readable is simply meaningless, and guaranteed to cause 
friction.  Your elaboration doesn't help either.  Readable is only 
meaningful in a context of how the code is going to be used and what your 
tactical and strategic goals are.  Debating it in a virtual vacuum like 
this is what I call a pinhead discusssion - how many angels can dance on 
the head of a pin...

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




Re: Fork (not the kind you eat with)

2001-06-28 Thread Chas Owens

A parent can fork as many times as it wants to (for that matter a child
could fork as well).  So your code would look like this:

$SIG{CHLD} = IGNORE; #works on unix platforms, auto reaps children
foreach $machine (get_machines()) {
$pid = fork;
if ($pid == 0) { #I am a child
check_machine($machine);
} elsif (not $pid) { 
#if parent then $pid = process id, if error then 
#$pid = undef
error();
}
}

On 28 Jun 2001 17:03:39 +0100, Pierre Smolarek wrote:
 The one thing in perl that gets my head all confused is fork.
 
 Can someone point me in the right direction (be it book, website, or kind
 enough to offer code).
 
 I need to make a script that has to check 16000 servers in around 6 minutes.
 My rough maths works out that 44 checks a second are needed. Each server
 check takes about 0.5 seconds to return, so the best bet is to fork each
 individual check, the result of which gets added to mysql so no need to have
 a conversation going on between child and parent. Idealy i would like to
 control the max amount children i have to, say, around 50.
 
 Any help would be greatful.
 
 (I have the cook book open but only seems to talk about a single parent
 child pair..?!)
 
 
 Pierre.
 
 
--
Today is Prickle-Prickle, the 33rd day of Confusion in the YOLD 3167
Keep the Lasagna flying!





Re: delete the last string

2001-06-28 Thread Peter Scott


I want to delete a string but only the last.
Example

I am the titi  last human on titi earth.

- I want to erase the last titi nut not the other.

No-one in my mailbox has mentioned a more obvious solution for the regex 
beginner:

s/(.*)titi/$1/

Greed is good.  :-)
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Re: passing parameters to Perl script

2001-06-28 Thread Brett W. McCoy

On Thu, 28 Jun 2001, Scott Taylor wrote:

 How can I pass parameters from *nix command line to a Perl script?
   Like $1 in shell scripting.

 #!/usr/bin/perl -w

 $myfile = $1;

This will:

my $file = $ARGV[0];

@ARGV contains all of the command-line parameters.

-- Brett
   http://www.chapelperilous.net/btfwk/

There's no such thing as a free lunch.
-- Milton Friendman




Re: Fork (not the kind you eat with)

2001-06-28 Thread Peter Scott

At 05:03 PM 6/28/01 +0100, Pierre Smolarek wrote:
The one thing in perl that gets my head all confused is fork.

Can someone point me in the right direction (be it book, website, or kind
enough to offer code).

Network Programming with Perl, by Lincoln Stein (Addison-Wesley, 2001) is 
very good on this topic.  If you want the full skinny on what's going on 
underneath, Advanced Programming in the UNIX Environment by W. Richard 
Stevens (also Addison-Wesley).
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




RE: Perl Boilerplate???

2001-06-28 Thread John Joseph Roets

This guy had one...
http://www.best.com/~quong/perlin20/

jjr

 -Original Message-
 From: Peter Scott [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, June 28, 2001 1:15 PM
 To: David Simcik; Perl Cgi; Perl Beginners
 Subject: Re: Perl Boilerplate???
 
 
 At 09:24 AM 6/28/01 -0500, David Simcik wrote:
 Hey,
  I, like the rest of you, am always looking for ways to make my 
  life more
 convenient. Especially when coding. To this end, I am looking to 
 fashion a
 well-rounded template doc that I can use in Homesite (where I do 
 most of my
 work right now) made up of the essential pieces I'd expect to 
 work with in
 ...



Re: referencing a flat file DB

2001-06-28 Thread Michael Fowler

On Thu, Jun 28, 2001 at 09:06:38AM -0700, Jon Riddle wrote:

Be forewarned, what follows is a critique of code you didn't ask about.


 #!/usr/local/bin/perl -w
 
 use CGI;
 use CGI::Carp qw(carpout fatalsToBrowser);

Always:

  use strict;

when debugging code.


 $Q = CGI;

This assigns the string 'CGI' to $Q.  I doubt that's what you intended.

  my $Q = new CGI;



Remove this from here:
 
 $content_length = $ENV{'CONTENT_LENGTH'};
 read (STDIN, $posted_information, $content_length);
 
 $posted_information =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack (C, hex ($1))/eg;
 $posted_information =~ s/\+/ /g;
 
 @fields = split (//, $posted_information);

to here.

Do not roll your own CGI parser, you will almost assuredly miss something.

 
 ($label, $name) = split (/=/, $fields[0]);
 ($label, $street) = split (/=/, $fields[1]);
 ($label, $city) = split (/=/, $fields[2]);
 ($label, $state) = split (/=/, $fields[3]);
 ($label, $zip) = split (/=/, $fields[4]);
 ($label, $PHONE_AREA) = split (/=/, $fields[5]);
 ($label, $PHONE_PRE) = split (/=/, $fields[6]);
 ($label, $PHONE_SUFF) = split (/=/, $fields[7]);
 ($label, $serviceProvider) = split (/=/, $fields[8]);
 ($label, $lapDance) = split (/=/, $fields[9]);
 ($label, $lapDance2) = split (/=/, $fields[10]);
 ($label, $lapDance3) = split (/=/, $fields[11]);
 ($label, $lapDance4) = split (/=/, $fields[12]);
 ($label, $lapDance5) = split (/=/, $fields[13]);

Use:

my $name   = $Q-param('name'  );
my $street = $Q-param('street');
etc.

Better yet, don't assign them to temporary variables, use them directly when
necessary, or stick them in a hash.



 #Compares correct anwsers
 $lapResults .= ,$lapDance,$lapDance2,$lapDance3,$lapDance4,$lapDance5;
 if ($lapResults eq
 ,AvaVincent,JessicaDrake,JewellDeNyle,ShaylaLaVeaux,ShaySweet) { $correct
 = 1}

This looks like a bad way of doing this.  You should probably put the
expected names in an array, then iterate over each of your parameters and
make sure they're in the array.

  my @params  = ($lapDance, $lapDance2, $lapDance3, $lapDance4, $lapDance5);
  my $correct = 1;
  for (my $i = 0; $i  @params; $i++) {
  if ($params[$i] ne $EXPECTED_NAMES[$i]) {
  $correct = 0;
  last;
  }
  }


 if (!$correct) {
   print $Q-redirect('http://www.ten.com/contest/thanklost.htm');
 }
 else {
   if  (one_time(1)) {
   print
 $Q-redirect('http://www.ten.com/contest/already.html');
   }
   else {
 open (OUTPUT,  lapdance.db) || die Cannot open lapdance.db: $!;
 print OUTPUT $name, :, $street, :, $city, :, $state, :,
 $zip,:, $PHONE_AREA, :, $PHONE_PRE, :, $PHONE_SUFF,\n;

Use join:

  print OUTPUT join(:, $name, $street, $city, $state, ...), \n;


 close OUTPUT;
   print $Q-redirect('http://www.ten.com/contest/thankwon.htm');
   }
 }
 # Routine that checks DB for previous valid 
 # entry comparing telephone number
 sub one_time {
   open (VARIFY,  lapdance.db) || die Cannot open lapdance.db: $!;
   while (VARIFY) {
   $stats = VARIFY;

This:

   $compare = { split (/:/, $stats)};
   @records = \$compare;

is very likely the source of your asked problem.  You are constructing an
anonymous hash with '$compare = { split (/:/, $stats)}', then assigning a
reference to that anonymous hash to $records[0].

Replace this with:

@records = split(/:/, $stats);


   if (($records[6] eq $PHONE_AREA)  ($records[7] eq
 $PHONE_PRE)  ($records[8] eq $PHONE_SUFF)) {
   $sorry = 1;
   }
   }
 close VARIFY;
 return $sorry;
 }
 # EOF ### 


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



Re: referencing a flat file DB

2001-06-28 Thread Michael Fowler

On Thu, Jun 28, 2001 at 05:34:22PM +0100, mark crowe (JIC) wrote:
  $compare = { split (/:/, $stats)};
  @records = \$compare;
 
 I think you'd be better off to use:
   @records = split (/:/, $stats)

While this is correct..

 
 At the moment you are splitting to a scalar (which I think just puts the
 first (or is it the last?) value from that split into the scalar) and then
 assigning a reference to that scalar as an array.

this isn't.  He's creating an anonymous hash with { split(/:/, $stats) },
then assigning it to $compare.  He then assigns a reference to $compare to
$records[0], which makes it a reference to a hash reference.


 I'm sure that's not good for you (and I'm a bit surprised that -w didn't
 pick it up, or haven't you tried it from the command line?)

The code will only cause a warning if the split returns an odd number of
elements.


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



Re: background processing (again?)

2001-06-28 Thread Karthik Krishnamurthy

the code that i sent you should be able to do that.
/kk
On Thu, Jun 28, 2001 at 09:51:19AM -0400, Ronald J. Yacketta wrote:
 Folks,
 
 to make a long story short I have a req to-do the following.
 1) gather continues data from netstat -I hme0 $SLEEPTIME  $netstatTMPFILE 
 while still parsing other information/data etc..
 
 that is, the script needs to be bale to collect the netstat data while it is
 running other process, not just fork netstat and wait for it to die/return.
 it will never die/return unless it is killed.
 
 Regards,
 Ron



Re: Fork (not the kind you eat with)

2001-06-28 Thread Pierre Smolarek

Thanks a lot and thanks to the guy who mentioned those book, amazon has
my order :)

this code was exactly what i needed...


- Original Message -
From: Chas Owens [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, June 28, 2001 7:07 PM
Subject: Re: Fork (not the kind you eat with)


 A parent can fork as many times as it wants to (for that matter a child
 could fork as well).  So your code would look like this:

 $SIG{CHLD} = IGNORE; #works on unix platforms, auto reaps children
 foreach $machine (get_machines()) {
 $pid = fork;
 if ($pid == 0) { #I am a child
 check_machine($machine);
 } elsif (not $pid) {
 #if parent then $pid = process id, if error then
 #$pid = undef
 error();
 }
 }

 On 28 Jun 2001 17:03:39 +0100, Pierre Smolarek wrote:
  The one thing in perl that gets my head all confused is fork.
 
  Can someone point me in the right direction (be it book, website, or
kind
  enough to offer code).
 
  I need to make a script that has to check 16000 servers in around 6
minutes.
  My rough maths works out that 44 checks a second are needed. Each server
  check takes about 0.5 seconds to return, so the best bet is to fork each
  individual check, the result of which gets added to mysql so no need to
have
  a conversation going on between child and parent. Idealy i would like to
  control the max amount children i have to, say, around 50.
 
  Any help would be greatful.
 
  (I have the cook book open but only seems to talk about a single parent
  child pair..?!)
 
 
  Pierre.
 
 
 --
 Today is Prickle-Prickle, the 33rd day of Confusion in the YOLD 3167
 Keep the Lasagna flying!





Re: Inheritance of package global variables

2001-06-28 Thread Michael Fowler

On Thu, Jun 28, 2001 at 03:05:17PM -0400, Richard J. Barbalace wrote:
 The 'use base' pragma nicely takes care of the @ISA and %FIELDS
 variables for me, but I also need to have the package global variable
 %Attributes inherited.  The 'use vars' and assignment in MyPackage is
 rather verbose, and I'm wondering if there is a better or terser way
 of doing that.  What's the recommended way of inheriting package
 global variables?

Exporting is usually a bad idea when dealing with classes, it breaks
encapsulation.  You should probably setup a class method for this.

That being said, you can export variables just like you export any other
data type, with Exporter; perldoc Exporter or
http://www.perldoc.com/perl5.6/lib/Exporter.html.


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



Re: background processing (again?)

2001-06-28 Thread Michael Fowler

On Thu, Jun 28, 2001 at 09:51:19AM -0400, Ronald J. Yacketta wrote:
 to make a long story short I have a req to-do the following. 1) gather
 continues data from netstat -I hme0 $SLEEPTIME  $netstatTMPFILE  while
 still parsing other information/data etc..

Given David M. Lloyd's suggestion to open a handle on netstat output, you
still need to read from the handle, which is a blocking operation.  Unless
you've already got a framework built for reading chunks from a filehandle
then continuing on to process other things, you'll probably need an event
loop, or a select loop, to go with this.

What is it this is intended to accomplish?  What is the program you're
writing?  Perhaps it would benefit from POE or Event.pm.


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



Administering Perl

2001-06-28 Thread tree

I have a question on administering perl..

I recently upgraded perl on the box from 5.6 to 5.6.1 and now i'm seeing
alot of these Subroutine redefined messages.  what is a subroutine
redefined message??

I also had to reinstall alot of CPAN modules.. i'm probably being
boneheaded and there's documenation about this somewhere.. but how can I
avoid re-installing all the cpan modules i've installed when i upgrade
perl?  is it as simple as copying them over?


Mike




date:calc

2001-06-28 Thread Katie Elliott

Hi,
Can you tell me if Date:Calc is the best way for calcuating dates?  I would like to 
pass specific dates to analog to do log file analysis on the dates.  

Here are my scripts:
1)Previous Month
#!/usr/bin/perl

use Date::Calc qw( Today Days_in_Month Date_to_Text); 

  ($year,$month) = Today();

#calculating previous month

  if ($month == 1)
  {
        $previous_mon = 12;
        $year = $year - 1;
        $days=Days_in_Month($year,$previous_mon);
        $begin_date = 01;
        $end_date = $days;
  print Previous Month's Dates were From $year $previous_mon$begin_date To $year 
$previous_mon$end_date.\n 
  }
  else
  {
      if ($month  1)
      {
          $previous_mon = $month - 1;
          $days=Days_in_Month($year,$previous_mon);
          $begin_date = 01;
          $end_date = $days;
  print Previous Month's Dates were From $year $previous_mon$begin_date To $year 
$previous_mon$end_date.\n 
      }
   }  

2)Previous Week
#!/usr/bin/perl

use Date::Calc qw( Today Day_of_Week Add_Delta_Days
                     Day_of_Week_to_Text Date_to_Text );

  $saturday_dow = 6; # 6 = Saturday
  $sunday_dow = 7; # 7 = Sunday
  @today = Today();
  $current_dow = Day_of_Week(@today);

#calculating saturday's date of previous week

  if ($saturday_dow == $current_dow)
  {
      @prev = Add_Delta_Days(@today,-7);
  }
  else
  {
      if ($saturday_dow  $current_dow)
      {
          @next = Add_Delta_Days(@today,
                    $saturday_dow - $current_dow);
          @prev = Add_Delta_Days(@next,-7);
      }

      else 
      {
          @prev = Add_Delta_Days(@today,
                    $saturday_dow - $current_dow);
          @next = Add_Delta_Days(@prev,+7);
      }
   }  
  $dow = Day_of_Week_to_Text($saturday_dow);
  print Today is:      , ' ' x length($dow),
                               Date_to_Text(@today), \n;

@previoussaturday=@prev;


#calculating sunday's date of previous week
#sunday is 7, which is larger than any other weekday 1-7

  if ($sunday_dow == $current_dow)
  {
      @prev = Add_Delta_Days(@today,-14);
  }
  else
  {
      if ($sunday_dow  $current_dow)
      {
          @next = Add_Delta_Days(@today,
                    $sunday_dow - $current_dow);
          @prev = Add_Delta_Days(@next,-14);
      }
  }
  $dow2 = Day_of_Week_to_Text($sunday_dow);
  @previoussunday=@prev; 

  print Previous Weeks Dates were From @previoussunday To @previoussaturday.\n


__
Get your own FREE, personal Netscape Webmail account today at 
http://webmail.netscape.com/



Trailing spaces ... aka rtrim();

2001-06-28 Thread Frank Newland

All, 
I wish to remove trailing spaces..

#!/usr/bin/perl -w
use strict ;
my $line  ;
while ()  {
chomp $_ ;
$line =~ s/\s+$//; #  remove trailing spaces
print  $line \n;
}

My output is equal number of blank lines..

Where is my error?

Frank




Re: Trailing spaces ... aka rtrim();

2001-06-28 Thread Brett W. McCoy

On Thu, 28 Jun 2001, Frank Newland wrote:

 #!/usr/bin/perl -w
 use strict ;
 my $line  ;
 while ()  {
 chomp $_ ;
 $line =~ s/\s+$//; #  remove trailing spaces
 print  $line \n;
 }

No where in your script do you assign a value to line.  What you want is
something like:

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

while (chomp(my $line = ))  {
  $line =~ s/\s+$//; #  remove trailing spaces
  print $line \n;
}


   http://www.chapelperilous.net/btfwk/

I guess it was all a DREAM ... or an episode of HAWAII FIVE-O ...




Re: Trailing spaces ... aka rtrim();

2001-06-28 Thread Peter Cline

At 03:27 PM 6/28/01 -0500, you wrote:
All,
I wish to remove trailing spaces..

#!/usr/bin/perl -w
use strict ;
my $line  ;
while ()  {
chomp $_ ;
$line =~ s/\s+$//; #  remove trailing spaces
print  $line \n;
}

My output is equal number of blank lines..

Where is my error?

Frank

You haven't initialized $line.  You should either use $_ as the variable on 
which you perform the regex and then print, or set $line = $_ or
while ($line = )

hth


Peter Cline
Inet Developer
New York Times Digital




Re: Trailing spaces ... aka rtrim();

2001-06-28 Thread Jos I. Boumans

Bud, what do you expect to be in $line?
you're declaring it, running a while loop, assigning input to $_, changing
something $line (which holds nothing mind you) then printing $line for every
line you get from 

in short, i *think* you mean:

while(){ s/\s+$//; print }

hth
Jos Boumans

- Original Message -
From: Frank Newland [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, June 28, 2001 10:27 PM
Subject: Trailing spaces ... aka rtrim();


 All,
 I wish to remove trailing spaces..

 #!/usr/bin/perl -w
 use strict ;
 my $line  ;
 while ()  {
 chomp $_ ;
 $line =~ s/\s+$//; #  remove trailing spaces
 print  $line \n;
 }

 My output is equal number of blank lines..

 Where is my error?

 Frank






Re: Administering Perl

2001-06-28 Thread Elaine -HFB- Ashton

tree [[EMAIL PROTECTED]] quoth:
*I have a question on administering perl..
*
*I recently upgraded perl on the box from 5.6 to 5.6.1 and now i'm seeing
*alot of these Subroutine redefined messages.  what is a subroutine
*redefined message??
*
*I also had to reinstall alot of CPAN modules.. i'm probably being
*boneheaded and there's documenation about this somewhere.. but how can I
*avoid re-installing all the cpan modules i've installed when i upgrade
*perl?  is it as simple as copying them over?

It depends on the version and it gets to be a bit of a dodgy situation to
which there is no easily defined answer for everyone.

Assuming that you made 5.6.1 and installed it without a hitch you will
notice that /usr/local/lib/perl5 has a 5.6/ 5.6.1/ and site_perl/ dir in
it. If you type 'perl -V' it will show you the @INC which will point to
the 5.6.1 libs. Now your locally installed modules are going to be
installed in /usr/local/lib/perl5/site_perl/5.6.1 [ if you installed in
/usr/local ] and your 5.6 modules will be in
/usr/local/lib/perl5/sit_perl/5.6. You could try and copy over all of the
5.6 modules into 5.6.1 and then copy the perllocal.pod to the arch dir in
the 5.6.1 distribution changing the installation path for the modules in
it butit's a lot more work than it's worth especially when you can't
be sure the 5.6.1 didn't break something that worked fine with 5.6. 

The saner way to do this is to use autobundle with CPAN.pm if you still
have a copy of your perl5.6 binary around.
http://www.cpan.org/misc/cpan-faq.html#How_make_bundle 
shows how to use this. It makes the job of installing modules en masse
quite a bit less painful.

e.



RE: Windows Background Process

2001-06-28 Thread murphy, daniel (BMC Eng)

I have this snippet of code that I picked up from Learning Perl on Win32
Systems (O'Reilly) that may be helpful. For more info, check the
Win32::Process module. As a Perl rookie myself, I really can't explain it -
I just know it works. ;-)


use Win32::Process;

Win32::Process::Create($Process,
c:\\program files\\ultraedit\\uedit32.exe,
uedit32 $alljobs_list ,
0,
DETACHED_PROCESS,
.)||  die Creating UltraEdit process: $!;






Dan Murphy   [EMAIL PROTECTED]   
EMC Corp.508-435-1000 x14559
Hopkinton, MA  01748

EMC2
where information lives




-Original Message-
From: C.Ouellette [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 27, 2001 6:17 AM
To: [EMAIL PROTECTED]
Subject: Windows Background Process


Hello,

I need to start an external program from my perl
script.  This program will need to run in the
background so my script can continue doing other
things.  It also still needs to notify the program
when it terminates.

I would appreciate any help on how I would do this. 
My environment is Windows NT 4.0, with Activestate
perl 5.6.1.  I'm also not sure how Windows runs a
background process, so any tips there would be
appreciated.

Lastly, I've been monitoring this list for a few weeks
now. It has been extremely helpful in getting me
started with Perl. Thank you to everyone involved.

Tina Ouellette

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



data matching

2001-06-28 Thread F.H

Hi all,

I am trying to skip any line in my input file that doesn't have a city with a street 
named 'MAIN'. I am matching record[3] in my input file with a $city (array) from a 
hash (%state) that I got from another file. The problem is that @city contains more 
than one element!


while ($line = INPUT){



$city = $record[3] ;
for ($i = 0; $i =  $#{ $state{$city}; $i ++  ) {  

next if$state{$city}[$i] ne MAIN

   
   } 


...

}

@city is an array of streets can be = ['MAIN', 'MAIN1','BROADWAY','PARK'], I want to 
match
Thanks for your help
I.S

__
Get your own FREE, personal Netscape Webmail account today at 
http://webmail.netscape.com/



RE: referencing a flat file DB

2001-06-28 Thread Jon Riddle

Hello all,
I would like to take a moment to thank everyone who helped me out on
my project.  I am obviously new to Perl and am a total hack, but eventually,
I will become proficient.  For those that are wondering, my lap dance
program is just a small contest for members of www.ten.com and yes, I do
work in the Porn industry (Interactive Gallery, subsidiary of Nasdaq:NOOF).
Perl is alive and well in the adult world and is even traded on Wall street,
the stock that is!  We have an engineering team that are all mongers,
however they have bigger fish to fry then my little contest program.  So,
thanks again for the help and very constructive criticisms.  One day, I will
be the mentor!


P.S., I would give out a user name and password, but the likeliness of their
being underage participants in this forum is too great.
Jon Riddle
Interactive Gallery Inc.
Phone- 818-501-4486 ext. 3037
Email- [EMAIL PROTECTED]

The three great virtues of a programmer are
laziness, impatience and hubris.
  Larry Wall 



RE: Re[5]: Best practice for config file use?

2001-06-28 Thread Grant McLean

From: Tim Musson [mailto:[EMAIL PROTECTED]]
 I like this option the best of the 3, but it is still hard to give to
 a non programing person and not expect them to mess up setting the
 vars...
 
 ie, = is what you separate things with, explaining which ' to
 use (' not `), end each parameter line with a ,

You might like to check out XML::Simple it was designed for exactly
this problem.

Using Jos' example:

 JIB ### config.pl ###
 JIB $href = {
 JIB usr= 'foo',
 JIB pwd  = 'bar',
 JIB host  = 'bleh.com',
 JIB }; 

If you put your config data in a file called foo.xml:

  config
usrfoo/usr
pwdbar/pwd
hostbleh.com/host
  /config

and your script was called foo.pl:

  use XML::Simple;

  my $config = XMLin();

  print Host: $config-{host}\n;

Then you have a script which can be configured by someone
who doesn't know Perl.

The XMLin() function takes all sorts of optional arguments
telling it where to find the XML and how to treat it, but if
you don't supply any arguments it simply looks for a file called
script name.xml in the same directory as the script.

XMLin() returns a hashref.  Nested elements in the XML get
returned as nested hashrefs or arrayrefs.

More info at:

  http://web.co.nz/~grantm/cpan/

Regards
Grant



=
Grant McLean   | email: [EMAIL PROTECTED] | Lvl 6, BP House
The Web Limited| WWW:   www.web.co.nz| 20 Customhouse Quay
Internet Solutions | Tel:   +64 4 495 8250   | Box 1195, Wellington
Awesome service| Fax:   +64 4 495 8259   | New Zealand



 -Original Message-
 From: Tim Musson [mailto:[EMAIL PROTECTED]]
 Sent: Friday, June 29, 2001 4:24 AM
 To: [EMAIL PROTECTED]
 Subject: Re[5]: Best practice for config file use?
 
 
 Hey Jos,
 
 I like this option the best of the 3, but it is still hard to give to
 a non programing person and not expect them to mess up setting the
 vars...
 
 ie, = is what you separate things with, explaining which ' to
 use (' not `), end each parameter line with a ,
 
 Wednesday, June 27, 2001, 6:15:54 PM, you wrote:
 
 JIB 2.script that just uses one hashref to hold all the vars you
 JIB need, let's call it config.pl too
 
 JIB ### config.pl ###
 JIB $href = {
 JIB usr= 'foo',
 JIB pwd  = 'bar',
 JIB host  = 'bleh.com',
 JIB };
 
 JIB ### in your script you'd say: ###
 JIB require 'config.pl'
 JIB use vars qw($href);#now it's just one variable 
 that's being used, still
 JIB holding all your config data
 
 -- 
 [EMAIL PROTECTED]
 Using The Bat! eMail v1.53d
 Windows NT 5.0.2195 (Service Pack 1)
 Life would be easier if I had the source code.
 



2**4 = 16 what about 16...=2

2001-06-28 Thread P lerenard

Hi ,
could I do 16**(0.25)
can I do that without downloading any module?

Thanks,

Pierre

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




Re: 2**4 = 16 what about 16...=2

2001-06-28 Thread Jeff 'japhy' Pinyan

On Jun 28, P lerenard said:

could I do 16**(0.25)
can I do that without downloading any module?

Yeah.  Just like you did it.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
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
**  Manning Publications, Co, is publishing my Perl Regex book  **




Re: data matching

2001-06-28 Thread F.H


[EMAIL PROTECTED] wrote:

 
 --- F.H [EMAIL PROTECTED] wrote:
  Hi all,
 
 Hi. =o)
 
  I am trying to skip any line in my input file that doesn't have a
  city with a street named 'MAIN'. I am matching record[3] in my input
  file with a $city (array) from a hash (%state) that I got from
  another file. The problem is that @city contains more than one
  element!
 
 a $city (array) ???
 
 What do you mean?

Sorry for the confusion, But I meant city is an array and at the same time an element 
of the hash %state.

  while ($line = INPUT){
  
 
 It might help to see some of the ellipsed code
 

Nothing much:
for ($line) { # get rid of quotes
s/^|$//g;
s/\s*,\s*|,*/,/g;
}

  $city = $record[3] ;
  for ($i = 0; $i =  $#{ $state{$city}; $i ++  ) {  
 
 Never use the
  for( ; ; ) { }
 construct in Perl without a significant and compelling reason.
 foreach is virtually always better for lots of reasons. Try:
 
   for my $i ( 0 .. $#{ $state{$city} ) {
 
              next if    $state{$city}[$i] ne MAIN
 
 Is that next supposed to advance the while loop?
 Because I think it's an expensive no-op that just advances the for
 loop.

I've tried that as well, and the purpose is to skip any line where the city doesn't 
have street = 'MAIN'
 Label the while like this:
 
   READ: while($line=INPUT) {
 
 and then specify which loop is being advanced with
 
   next READ if 
 
                 } 
 
 Hmm...
 maybe:
   READ: while($line=INPUT) {
         my %lookup = ();
         @lookup{@state{$city}} = 1 .. scalar(@state{$city});
         next READ unless $lookup{MAIN};
         # it's there, so do whatever code...
         
  }
 
 I haven't tested this, and something about it feels funny
 But it's a start. =o)
 
 __
 Do You Yahoo!?
 Get personalized email addresses from Yahoo! Mail
 http://personal.mail.yahoo.com/
 
__
Get your own FREE, personal Netscape Webmail account today at 
http://webmail.netscape.com/



Data::Dumper module

2001-06-28 Thread Teresa Raymond

Could someone please help me translate this. All I can figure out for 
sure are the first 2 lines.  For a class assignment we need to: Read 
the documentation on the Data::Dumper module (type 'perldoc 
Data::Dumper' ). Use it to display the contents of your data 
structure.  Thanks in advance.

1 @c = ('c');   #make ordinary array with value c
2 $c = \@c; #make a reference to array c
3 $b = {};#make an anonymous hash?
4 $a = [1, $b, $c];
5 $b-{a} = $a; #make hash key, a, variable a?
6 $b-{b} = $a-[1];#make hash key, b, var a's 2nd element?
7 $b-{c} = $a-[2];
8 print Data::Dumper-Dump([$a,$b,$c], [qw(a b c)]);

*** Teresa Raymond
*** http://www.mariposanet.com
*** [EMAIL PROTECTED]


Re[6]: Finding @INC

2001-06-28 Thread Maxim Berlin

Hello Randal,

Thursday, June 28, 2001, Randal L. Schwartz [EMAIL PROTECTED] wrote:


RLS NO NO.  That doesn't work.  All of those unshifts are executed REGARDLESS
RLS of the $OS type.
[...]
Randal, thank you for your patience and examples, but please do not
explain how BEGIN works again. I know that.

RLS So, Maxim, YOU are demonstrating the very reason I would flunk your
RLS code.  It *doesn't* work!
my code is not absolytely correct, but it *works*. In
*this* case form is more important than contents for *me*.

RLS BEGIN { unshift @INC, ... } is reducible to the standard idiom
RLS of use lib ..., and should used in preference.
I understand, that beginners@ isn't right place for my example and our
discussion, but i took a part from very old (but still
working) perl script; yes, i should have checked that part before
sending, but (sigh...) nobody is perfect.
my apologies.

Best wishes,
 Maximmailto:[EMAIL PROTECTED]





Re: Data::Dumper module

2001-06-28 Thread Peter Scott


Could someone please help me translate this. All I can figure out for sure 
are the first 2 lines.  For a class assignment we need to: Read the 
documentation on the Data::Dumper module (type 'perldoc Data::Dumper' ). 
Use it to display the contents of your data structure.  Thanks in advance.

You seem to be pretty much there.  O course, it would be a disservice to do 
your homework for you, so I'll point you in the direction of how to learn 
it yourself.

1 @c = ('c');   #make ordinary array with value c
2 $c = \@c; #make a reference to array c
3 $b = {};#make an anonymous hash?

All correct so far.

4 $a = [1, $b, $c];

Anonymous array.  Try perldoc perlref.

5 $b-{a} = $a; #make hash key, a, variable a?

Yes, we'd say variable $a

6 $b-{b} = $a-[1];#make hash key, b, var a's 2nd element?

Not as clear an explanation as would convince me you knew what was happening.

7 $b-{c} = $a-[2];
8 print Data::Dumper-Dump([$a,$b,$c], [qw(a b c)]);

If you run this, the output should make it easier to understand what the 
code is doing.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Re[6]: Finding @INC

2001-06-28 Thread Peter Scott

At 02:24 AM 6/29/01 +0400, Maxim Berlin wrote:
Thursday, June 28, 2001, Randal L. Schwartz [EMAIL PROTECTED] wrote:

RLS NO NO.  That doesn't work.  All of those unshifts are executed REGARDLESS
RLS of the $OS type.
[...]
Randal, thank you for your patience and examples, but please do not
explain how BEGIN works again. I know that.

RLS So, Maxim, YOU are demonstrating the very reason I would flunk your
RLS code.  It *doesn't* work!
my code is not absolytely correct, but it *works*. In
*this* case form is more important than contents for *me*.

Your idea of working needs some revision.  Your code may produce the 
results you want, but it is structured in a way that implies you don't 
understand what it's doing, or you wouldn't have done it that way.  That's 
unhelpful to beginners in particular, and you would be well served by 
looking again to see how Randal's analysis can be used to improve your use 
of Perl.  This is not just a matter of style.  I could and would have made 
the same arguments, but Randal was faster and more articulate.

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




Re: data matching

2001-06-28 Thread Michael Fowler

On Thu, Jun 28, 2001 at 02:34:31PM -0700, Paul wrote:
  $city = $record[3] ;
  for ($i = 0; $i =  $#{ $state{$city}; $i ++  ) {  
 
 Never use the
  for( ; ; ) { }
 construct in Perl without a significant and compelling reason.
 foreach is virtually always better for lots of reasons. Try:
 
   for my $i ( 0 .. $#{ $state{$city} ) {

Well, you make a good point that one should use foreach, but then you use it
in almost identical way as the for loop.  If you were to use it this way,
you might as well use a for loop.  The most readable and idiomatic way to do
this is:

foreach my $street (@{ $state{$city} }) {
... if $street ne MAIN;
}

You should try to avoid the foreach (0 .. $#array) form; that list has to go
into memory somewhere, and it's just a more verbose way of saying foreach
(@array).

Otherwise, that's some good advice.


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



Re: Finding @INC

2001-06-28 Thread Michael Fowler

On Fri, Jun 29, 2001 at 02:24:56AM +0400, Maxim Berlin wrote:
 Thursday, June 28, 2001, Randal L. Schwartz [EMAIL PROTECTED] wrote:
 
 RLS NO NO.  That doesn't work.  All of those unshifts are executed REGARDLESS
 RLS of the $OS type.
 [...]
 Randal, thank you for your patience and examples, but please do not
 explain how BEGIN works again. I know that.
 
 RLS So, Maxim, YOU are demonstrating the very reason I would flunk your
 RLS code.  It *doesn't* work!
 my code is not absolytely correct, but it *works*. In
 *this* case form is more important than contents for *me*.

I don't understand, if you wanted all of those paths in @INC, why put them
in conditionals?  Why didn't you do something along the lines of:

# I don't recall exactly what the original code was, so the specifics
# may be a bit off.
BEGIN { unshift(@INC, C:\\winnt, /usr/local, /usr) }

if ($OSNAME eq 'nt') {
`del ...`;
} elsif ($OSNAME eq 'linux') {
`rm -rf ...`;
} elsif ($OSNAME eq 'freebsd') {
`rm -rf ...`;
}

That is, effectively, what you achieve by having BEGIN blocks in each
conditional.  This certainly doesn't look like what you intended.


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



Re: data matching

2001-06-28 Thread Paul


--- Michael Fowler [EMAIL PROTECTED] wrote:
 On Thu, Jun 28, 2001 at 02:34:31PM -0700, Paul wrote:
   $city = $record[3] ;
   for ($i = 0; $i =  $#{ $state{$city}; $i ++  ) {  
  
  Never use the
   for( ; ; ) { }
  construct in Perl without a significant and compelling reason.
  foreach is virtually always better for lots of reasons. Try:
  
for my $i ( 0 .. $#{ $state{$city} ) {
 
 Well, you make a good point that one should use foreach, but then you
 use it
 in almost identical way as the for loop.  If you were to use it this
 way,
 you might as well use a for loop.  The most readable and idiomatic
 way to do
 this is:
 
 foreach my $street (@{ $state{$city} }) {
 ... if $street ne MAIN;
 }
 
 You should try to avoid the foreach (0 .. $#array) form; that list
 has to go
 into memory somewhere, and it's just a more verbose way of saying
 foreach
 (@array).
 
 Otherwise, that's some good advice.

lol -- my point was poorly made.
I meant that if you feel you *have* to iterate over indexes, you can
still use foreach.

Your point is apparently that you almost never need to iterate over
indexes, which is the half of the point I meant to make that I never
got around to, lol! =o)

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Re: data matching

2001-06-28 Thread F.H

Hello
Here is my script, I am missing something. All I am trying to do is to skip
LA and BURLINGTON lines, because they are missing 'MAIN'.
Thanks.
I.S

my %state;
%state = (
CHICAGO = [MAIN, BROADWAY, OAK],
LA = [DELTA, GAMMA],
BOSTON = [FIRST, MAIN],
BURLINGTON = [SECOND, ONE],
SEATTLE = [GREAT,MAIN],
);



SWITCH:{ while ($line = DATA){
#next if /^\s*$/;
@line = split /\s*,\s*/, $line;
$city = $line[3];
#print @line;
#print CITY : $city\n;
foreach  $street (@{ $state{$city} } ){
   print $street, \n;  
 if ( $street ne MAIN){
   next SWITCH;
   }
}

 }
}

__DATA__
STATE ,IL, SDW,CHICAGO
STATE,CA, SFD,LA
STATE, MA, FDR,BOSTON
STATE, CT,FGD,BURLINGTON
STATE, WA, SDF,SEATTLE
__END__


Michael Fowler [EMAIL PROTECTED] wrote:

 On Thu, Jun 28, 2001 at 02:34:31PM -0700, Paul wrote:
   $city = $record[3] ;
   for ($i = 0; $i =  $#{ $state{$city}; $i ++  ) {  
  
  Never use the
   for( ; ; ) { }
  construct in Perl without a significant and compelling reason.
  foreach is virtually always better for lots of reasons. Try:
  
    for my $i ( 0 .. $#{ $state{$city} ) {
 
 Well, you make a good point that one should use foreach, but then you use it
 in almost identical way as the for loop.  If you were to use it this way,
 you might as well use a for loop.  The most readable and idiomatic way to do
 this is:
 
     foreach my $street (@{ $state{$city} }) {
         ... if $street ne MAIN;
     }
 
 You should try to avoid the foreach (0 .. $#array) form; that list has to go
 into memory somewhere, and it's just a more verbose way of saying foreach
 (@array).
 
 Otherwise, that's some good advice.
 
 
 Michael
 --
 Administrator                      www.shoebox.net
 Programmer, System Administrator   www.gallanttech.com
 --
 
__
Get your own FREE, personal Netscape Webmail account today at 
http://webmail.netscape.com/



Matching strings

2001-06-28 Thread twelveoaks

I have a series of variables, say, 
$var0 $var1 $var2  $var3...  
up to lots and lots depending on user input.

They are also available as an array 
@vars = (element1, element2,...)

I want to test to see if any two of their values are identical. Basically if the user 
has made an entry that is not unique he should get an error message.

I know how to compare any two of them of course

if ($var1 == $var2)  { $youlose = yes }

but I don't want to do this over and over again. 
Is there a simple way to, say, compare multiple values to see if any two within the 
group match?

Thanks,
Tara



Re: Screen refresh

2001-06-28 Thread sevoski

I found the answer in the previous post Clear Screen.


On Thu, 28 Jun 2001, sevoski wrote:

 
 Hello,
 I would like to know of a way to refresh a console screen, opposed to just
 augmenting the console text. This would help greatly in making simple
 menus. 
 
  --Sebastian Lisic
 
 
 
 




RE: Matching strings

2001-06-28 Thread Wagner-David

First you would need to do a string compare vs numeric compare(ie,
eq vs == ).  If they can never enter the same response or value and you
don't care about capitalization, then you could use a hash and either
lower/upper case the input. If key exists and/or is defined, then would have
to respond with a different value.

Wags ;)

-Original Message-
From: twelveoaks [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 28, 2001 17:53
To: [EMAIL PROTECTED]
Subject: Matching strings


I have a series of variables, say, 
$var0 $var1 $var2  $var3...  
up to lots and lots depending on user input.

They are also available as an array 
@vars = (element1, element2,...)

I want to test to see if any two of their values are identical. Basically if
the user has made an entry that is not unique he should get an error
message.

I know how to compare any two of them of course

if ($var1 == $var2)  { $youlose = yes }

but I don't want to do this over and over again. 
Is there a simple way to, say, compare multiple values to see if any two
within the group match?

Thanks,
Tara



Re: Matching strings

2001-06-28 Thread twelveoaks

Peter Scott Wrote:

 my %h;
 @h{@vars} = ();
 if (keys %h != @vars) { $youlose = yes; }


Maybe I'm missing something - won't these *always* match, since @vars has been used to 
create keys %h?  

It seems that way when I test it.

What I want to detect is whether any two of the values within @vars are identical.

Will this do that?

-T



Optional Variables

2001-06-28 Thread Kim Green

My question pertains to using command line variables in Perl. 
I created a script that uses SQL and runs from an application, and the only
parameter is optional.  This script works well when the parameter is
required or not used at all.
I have altered the SQL script so that it can accept a variable or execute
the query without it, but I need to do the same in Perl.

I am using @ARGV and explicitly assigning it to a variable.  Below is an
excerpt:
if (defined(@ARGV[1])) 
{
$filename = @ARGV[1];
$sth-execute($filename) || die Couldn't execute statement
 . $sth-errstr;

This is my first script, so I have been reading, researching and testing
what I find. However, I found nothing about this anywhere.


Please help!
Thanks,
Kim



Re: Matching strings

2001-06-28 Thread Hasanuddin Tamir

On Thu, 28 Jun 2001, twelveoaks [EMAIL PROTECTED] wrote,

 Peter Scott Wrote:

  my %h;
  @h{@vars} = ();
  if (keys %h != @vars) { $youlose = yes; }


 Maybe I'm missing something - won't these *always* match, since @vars has
 been used to create keys %h?

No, depends on the content of @array.

When you use the array @vars to create the keys, the uniqueness is
guaranteed.  Peter gave you the code to prove that (I didn't test
it though).  Imagine you have,

@array = qw(one one one two); # 4 elements

Since the keys must be unique, only two of the four elements fill
in the key slots, they are 'one' and 'two'.  Let's create the hash
manually,

%h = (
one = 1,
one = 2,
one = 3,
two = 4,
);

You only get two keys here (the last value will override the the
previous, so in this case, $h{one} will be 3).  So the comparison,

keys %h != @vars

yields true, they're not equal.


 It seems that way when I test it.

 What I want to detect is whether any two of the values within @vars are
 identical.

 Will this do that?

There's another approach, still using hash.  Initialize an empty hash,
say %seen.  Iterate the @vars and check whether the current element
has been seen.

my %seen;
foreach my $elem (@vars) {
if (exists $seen{$elem}) {
$youlose = 'yes';
} else {
$seen{$elem} = ''; # empty string will be sufficient,
   # but see below
}
}

But it's convenient to do the check and keep in single step,

if ($seen{$elem}++) {
$youlose = 'yes';
}

It's the same as,

if ($seen{$elem}) {
$youlose = 'yes';
} else {
$seen{$elem} += 1;
}


HTH;
__END__
-- 
s::a::n-http(www.trabas.com)





Re: writing readable Perl

2001-06-28 Thread Rajeev Rumale

Dear Greeg,

. I intend this e-mail for the more knowledgeable
 programmers who are reading this mailing list.

Well though I don't fall in that category.  I have very much felt the need
of same.
We can give it a start and soon we will reach the end also...;-)

Rajeev Rumale

~~~
Rajeev Rumale
MyAngel.Net Pte Ltd.,Phone  :
(65)8831530 (office)
#04-01, 180 B, The Bencoolen,   Email  :
[EMAIL PROTECTED]
Bencoolen Street, Singapore - 189648 ICQ: 121001541
Website : www.myangel.net
~~~



- Original Message -
From: Gregg Williams [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, June 27, 2001 6:54 AM
Subject: writing readable Perl


 The recent Re: print FN 'junk\n'  thread makes this an ideal time for me
 to write this e-mail
 -- I do *not* want to start any flames, so please reply to me privately
at
 [EMAIL PROTECTED] --

 I am a Perl semi-nubie who has, over the years, been mystified by various
 pieces of Perl code. I am pleased by the interest in the learn.perl.org
site
 and [EMAIL PROTECTED] mailing list, and I'm interested in in writing some
 kind of article for the Perl community advocating a common sense approach
to
 writing Perl code and that can be read (by you and others) easily in the
 future.

 I have begun collecting examples of code that I feel are needlessly
 complicated or obscure and invite you to send me things that you think are
 examples of this sort of thing. I will (eventually) try to write something
 up of benefit to the Perl community. Thanks.

 --greggw

 PS: PLEASE remember to send them to [EMAIL PROTECTED] Thanks.  --gw

 ### I'm using voice-recog. software to dictate e-mails,  ###
 ### so please ask if something reads funny; thanks --   ###






RE: Gzip on Win32

2001-06-28 Thread Kris G Findlay


you only need winzip from www.winzip.com it can uncompress gzip and tar
zipped files no problem !!

i use all the time !!

{--}
 Kris G Findlay
{--}

-Original Message-
From: Wright, James C. [mailto:[EMAIL PROTECTED]]
Sent: 28 June 2001 16:03
To: 'David Simcik'; Perl Beginners
Subject: RE: Gzip on Win32


For a great free Unix-like command line interface for Win32, install Cygwin.
It gives you many of the Gnu tools (including gzip) in its original install,
and you can install others (such as Perl).  Look at
http://www.xav.com/perl/lib/Pod/perlcygwin.html.
-jim

-Original Message-
From: David Simcik [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 28, 2001 11:05 AM
To: Perl Beginners
Subject: Gzip on Win32


Hey,
I'm hoping this will be a straighforward question...I'm assuming I
need a
command-line interface GZip utility to work with the MCPAN installation
utility??? Where can I find one?

Thanks.
DTS




  1   2   >