Form creation and parsing

2003-10-09 Thread [EMAIL PROTECTED]
Hi, I'm quite new to Perl scripting, so any help could be really most valuable.
I'm trying to write a Perl script which creates a Form (I know how to create a
form with HTML or Php), and after the user has compiled the form and pressed the
submit button, the same script should parse the input and show the user an HTML
page with the elaboration of the input the user has inserted.
Thanks to anyone who can help me.
Paolo


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



RE: Form creation and parsing

2003-10-09 Thread Jonathan E. Hogue
This will create the form for you, including client side javascript for
validation. It will also do the server side validation. It will set
itself as the submit, and return a confirmation screen. It's all of 18
lines, that's less than it would take to write the HTML form itself.
Look at
http://search.cpan.org/~nwiger/CGI-FormBuilder-2.12/FormBuilder.pod for
more details.

use CGI::FormBuilder;

my $form = CGI::FormBuilder-new(
fields = [qw/name email phone gender/],
validate = { email = 'EMAIL', phone = 'PHONE' },
required = 'ALL',
font = 'arial,helvetica',
   );

if ($form-submitted  $form-validate) {
my $fields = $form-field;# get form fields as hashref
my $name = $fields-{name};

# Show confirmation screen
print $form-confirm(header = 1);
} else {
# Print out the form
print $form-render(header = 1);
}

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 09, 2003 9:16 AM
To: beginners-cgi
Subject: Form creation and parsing

Hi, I'm quite new to Perl scripting, so any help could be really most
valuable.
I'm trying to write a Perl script which creates a Form (I know how to
create a
form with HTML or Php), and after the user has compiled the form and
pressed the
submit button, the same script should parse the input and show the user
an HTML
page with the elaboration of the input the user has inserted.
Thanks to anyone who can help me.
Paolo


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




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



Print this page cgi script

2003-10-09 Thread Johnstone, Colin
Gidday All,

As an exercise I would like to write my own print this page cgi.

I need a regex to return the content from the page that I wish to print.
These will be indicated in the html by the use of the following tag
sets.

headline/headline
date/date
bod/bod


Any help appreciated.

Thank You
Colin

**
This message is intended for the addressee named and may contain
privileged information or confidential information or both. If you
are not the intended recipient please delete it and notify the sender.
**


server side includes using cgi

2003-10-09 Thread Dale . Young
Hello all,
 
I have been trying include a 'server side include' in a cgi script used to generate a 
html page with no success.  I have redirected the output from the script to a static 
html file which displays correctly in my browser (i.e. ssi configured ok) - so I'm 
thinking that either it can't be done, or my syntax is incorrect (refer below).  Note 
that there is no error message (to screen, or in the log files), though the include 
statement does exist in the source when viewed through my browser.
 
After searching far and wide I have been unable to locate any info/examples specific 
to this issue - possibly indicating that I'm going about this the wrong way (likely 
since I'm fairly new to perl/cgi).  At this point I have resolved to open a file 
handler and read in the html (vi print statements).
 
Any direction/assistance on the matter would be much appreciated.

 

#! /usr/bin/perl -w
 print Content-type: text/html\n\n;
 print htmlhead\n;
 print titleGuestBook Contents\/title\n;
 print !--\#include virtual=\\/header.html\--br\n;   NOT INCLUDED
 print \/head\n;
 print body\n;
 print h1GuestBook Entries\/h1\n;
 print table border=\1\ width=\60%\\n;
 print tr\n;
 print thName\/th\n;
   print \/table\n;
   print \/body\n;
   print \/html\n;

 

Thanks

 

Dale



Reg ex help

2003-10-09 Thread Johnstone, Colin
Gidday All,

I am writing a print this page script.

I have slurped in the page to be printed and now want to strip out the
stuff to print.

To do this I have created the following tag sets in the html page.

date/date
headline/headline
story/story

I need to write a regex to achieve this.

Any Help Appreciated.

Colin



**
This message is intended for the addressee named and may contain
privileged information or confidential information or both. If you
are not the intended recipient please delete it and notify the sender.
**


Re: Holding File handles in a {} anonymous hash

2003-10-09 Thread Rob Dixon

Rob Dixon wrote:

 Dan Anderson wrote:
 
  I have a module that works with a couple of different file handles.  Is
  it possible to hide them within an anonymous hash?  {} (i.e. the objects
  data).  Right now I have:
 
  if (condition_is_met()) {
open(FILE,file);
  }
 
  This is in the main body of my package (and thus, I assume, accessible
  by all functions).  Is it better to use tighter encapsulation (i.e. a
  closure or throwing it into an anonymous hash) or just to leave it in
  the body?

 I think you'd be safe like this, except that if you have a lot of them
 then you dont' know what the filehandle is going to be called. Here
 you've used *Package::FILE, but there's no general way of getting to
 that package name from any given filename. How about a hash of glob
 references?

 Here's a closure with a subroutine which keeps a list of handles for
 each file it has already opened. The program just uses it to print
 the next line from alternate files.

 I hope this helps.

 Rob


   use strict;
   use warnings;

   line_from ('filea');
   line_from ('fileb');

   line_from ('filea');
   line_from ('fileb');

   line_from ('filea');
   line_from ('fileb');

   {
 my %filehandle;
 my $fh;

 sub line_from {

   my $file = shift;

   $fh = $filehandle{$file};

   unless (defined $fh) {
 open $fh, $file or die $!;
 $filehandle{$file} = $fh;
   }

   print scalar $fh;
 }
   }

Nobody noticed that my 'closure' wasn't a closure! I was
going to write it that way but decided the simple subroutine
with persistent lexicals was easier and neater as it could
be self-initialising. FWIW a closure equivalent is here if
anybody's interested.

Rob


  use strict;
  use warnings;

  my ($file1, $file2) = qw/ filea fileb /;

  my %fetch = map { ($_ = file_iterator($_)) } $file1, $file2;

  for my $file (($file1, $file2) x 3) {
print $fetch{$file}-();
  }

  sub file_iterator {
my $file = shift;
my $fh;
open $fh, $file or die $!;
sub { scalar $fh };
  }




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



RE: stop/start

2003-10-09 Thread Tristram Nefzger
Regarding writing a unix daemon in perl, you might have a look at
http://www.webreference.com/perl/tutorial/9/index.html

-tristram


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



Re: required help

2003-10-09 Thread James Edward Gray II
Last warning:  You are still sending messages to my private address, 
which is inappropriate.  I read the beginner's list and will see any 
messages you send there, so do many other people who my be able to help 
you better/faster than me.  These people want to help you, that's why 
the list exists.  Please direct all future inquiries to 
[EMAIL PROTECTED] as I will ignore any further messages sent directly 
to me.

On Wednesday, October 8, 2003, at 10:47  PM, vaishali wrote:

This total cost is count of the field receiver ie in above example

sender: xyz.abc
department: xxx
branch: yyy

receiversent
---
4423432432  2003-09-09 09:09:00
65465466546 2003-08-06 01:10:10
-
Total Cost: 2
or Total count
ie a sender xyz.abc has sent two sms messages the cost of sms messages 
is Rs 1 so
the total cost is 2 ie messages send * Rs.1 = 2
Okay, I understand what you want now.  Unfortunately, I could not find 
the place in your code where you are printing the footer, to offer a 
fix.

You are already keeping track of the count in the %seen variable.  
$seen{$temp_sender2} will give you the count, at any give time.  Thus 
Total Cost: $seen{$temp_sender2}\n should give you the last line, 
wherever you are outputting it.

Now if your problem is that you can't figure out where to work in the 
footer, that may be a little tricky.  You could always read the 
database table into a large data structure, making it easier for you to 
output statistics.  Or, with your current approach, you could keep 
track of the last sender:

my $last_sender;	# must come before while loop

while (my $row=$sth-fetchrow_arrayref()) {
# ...

print $/,$/,'sender  
:',$temp_sender2,$/,'Department:',$lp1{$temp_sender1}{'department'},$/ 
,'Branch:',$lp1{$temp_sender1}{'branch'},$/,$header  
if(!$seen{$temp_sender2}++);
# replace the above line with something like:

if (not $seen{$temp_sender2}++) {
print '-' x 58, \nTotal Cost: $seen{$last_sender}\n if $last_sender;
print \n\nsender  :$temp_sender2\n,
Department:$lp1{$temp_sender1}{department}\n,
Branch:$lp1{$temp_sender1}{branch}\n,
$header;
}
print $row-[1],(' ' x (28-length($row-[1]))),
  $row-[2],(' ' x (22-length($row-[2]))),$/;
$last_sender = $temp_sender2;

}
Hope that helps.

James

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


RE: undefined subroutine

2003-10-09 Thread Dan Muey
 I'm trying to convert so I can use a server that doesn't 
 support PHP, but I'm giving up. With my limited knowledge I 

That's a good server. I've had more trouble with php on 
our webservers I'd almost get rid of it,. But one guy use 
the PHPBB forum so I can't unless he stops using it!

 think it's impossible. I was told that the scripting was all 
 Perl, so conversion should have been easy. But, I guess 

I doubt it's impossible. A lot of times I'll take somethgin 
handed to me, look at it for a bit then say It will take 
less time, energy, etcc if I just rewrite it. Not only will 
it be perl but it will be The latest and greatest perl and I 
can be sure there's no stupid holes that someone else left. 
( Well ok, no deliberate stupid holes, I'm not totally imune 
to stupidness ;p )

 there's some C mixed in there as well or maybe some of it is 
 PHP specific.

What is the task/process of the script?
I havn't been paying to much attention to the list so I'll go 
Back and see what you're up to.

DMuey

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



Monitoring application runtime

2003-10-09 Thread Steve . E . Pittman




I am using Win32::Spawn($application, $cmdLine, $processID) to launch a
non-windows app..is there a method to determine when the application has
ended?

I obviously have the PID but I have not found a WIN32 function to monitor
the process.

Regards,

Steve


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



grep argument list too long...how to get around it?

2003-10-09 Thread Kevin Old
Hello everyone,

We use the Barracuda Spam appliance (barracudanetworks.com) to filter
our spam and their web based interface is written in Perl.  They have a
form that allows the user to search messages for key words.  Evidentally
it stores the each message in a file in a directory and when trying to
search several hundred thousand messages for a word the response back
is:

egrep: argument list too long

It looks like their using grep via a system command or the grep function
in Perl.

Now, to my question.  How do others get around the limitations of
sending stuff to grep?  

I know they're probably not aware of it yet as we just got the firmware
update the other day.  I'm a perl programmer so I thought I'd try to
figure out the solution and send it to them to incorporate into the
firmware.

Any ideas?

Thanks,
Kevin
-- 
Kevin Old [EMAIL PROTECTED]


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



Re: grep argument list too long...how to get around it?

2003-10-09 Thread Steve Grazzini
On Thu, Oct 09, 2003 at 11:54:00AM -0400, Kevin Old wrote:
 We use the Barracuda Spam appliance (barracudanetworks.com)

[ snip ]

 egrep: argument list too long
 
 It looks like their using grep via a system command or the grep function
 in Perl.

It's definitely the external grep...

 I know they're probably not aware of it yet as we just got the firmware
 update the other day.  I'm a perl programmer so I thought I'd try to
 figure out the solution and send it to them to incorporate into the
 firmware.

I'd just send a bug report.

-- 
Steve

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



RE: grep argument list too long...how to get around it?

2003-10-09 Thread Wiggins d'Anconia


On 09 Oct 2003 11:54:00 -0400, Kevin Old [EMAIL PROTECTED] wrote:

 Hello everyone,
 
 We use the Barracuda Spam appliance (barracudanetworks.com) to filter
 our spam and their web based interface is written in Perl.  They have a
 form that allows the user to search messages for key words.  Evidentally
 it stores the each message in a file in a directory and when trying to
 search several hundred thousand messages for a word the response back
 is:
 
 egrep: argument list too long
 
 It looks like their using grep via a system command or the grep function
 in Perl.
 
 Now, to my question.  How do others get around the limitations of
 sending stuff to grep?  
 
 I know they're probably not aware of it yet as we just got the firmware
 update the other day.  I'm a perl programmer so I thought I'd try to
 figure out the solution and send it to them to incorporate into the
 firmware.
 
 Any ideas?
 

To get around this in the past I have used 'find' combined with an 'exec' switch 
because that shortens the arg list to 'egrep' to one for each file found, but this 
isn't a terribly elegant (or fast) solution for a distributed software package.

http://danconia.org

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



RE: grep argument list too long...how to get around it?

2003-10-09 Thread Bakken, Luke
 We use the Barracuda Spam appliance (barracudanetworks.com) to filter
 our spam and their web based interface is written in Perl.  
 They have a
 form that allows the user to search messages for key words.  
 Evidentally
 it stores the each message in a file in a directory and when trying to
 search several hundred thousand messages for a word the response back
 is:
 
 egrep: argument list too long
 
 It looks like their using grep via a system command or the 
 grep function
 in Perl.
 
 Now, to my question.  How do others get around the limitations of
 sending stuff to grep?  
 
 I know they're probably not aware of it yet as we just got 
 the firmware
 update the other day.  I'm a perl programmer so I thought I'd try to
 figure out the solution and send it to them to incorporate into the
 firmware.
 
 Any ideas?

Rather than calling

egrep REGEX really long list of files ...

they should be calling (ksh here, use echo instead of print for other shells):

print really long list of files | xargs egrep REGEX

Luke

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



RE: grep argument list too long...how to get around it?

2003-10-09 Thread Dan Muey
 Hello everyone,

Howdy

 
 We use the Barracuda Spam appliance (barracudanetworks.com) 
 to filter our spam and their web based interface is written 
 in Perl.  They have a form that allows the user to search 
 messages for key words.  Evidentally it stores the each 
 message in a file in a directory and when trying to search 
 several hundred thousand messages for a word the response back
 is:
 
 egrep: argument list too long
 

If I was trying to grep a zillion files at once and it wouldn't 
let me I'd probably grep them one at a time.
For instance via the backtivck execution You might have:

my @matchedfiles = qx(cat `ls /files/` |grep $string);
# a really bad way to do this but for example's sake...

You could do:

for(`ls /files/`) {
if(`cat $_ |grep $string`) { push(@matchedfiles,$_); }
}

Then you are only greping one file at a time instead of a list of too many.
Of course what would be better is to use the readdir() functions to list the files 
and open() and grep() combo to grep the contents. But the same principle applies.

Just make sure the barracuda folks says thanks for fixing their problem :)

HTH

DMuey

 It looks like their using grep via a system command or the 
 grep function in Perl.
 
 Now, to my question.  How do others get around the 
 limitations of sending stuff to grep?  
 
 I know they're probably not aware of it yet as we just got 
 the firmware update the other day.  I'm a perl programmer so 
 I thought I'd try to figure out the solution and send it to 
 them to incorporate into the firmware.
 
 Any ideas?
 
 Thanks,
 Kevin
 -- 
 Kevin Old [EMAIL PROTECTED]
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

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



RE: grep argument list too long...how to get around it?

2003-10-09 Thread Kevin Old
On Thu, 2003-10-09 at 12:13, Dan Muey wrote:
  Hello everyone,
 
 Howdy
 
  
  We use the Barracuda Spam appliance (barracudanetworks.com) 
  to filter our spam and their web based interface is written 
  in Perl.  They have a form that allows the user to search 
  messages for key words.  Evidentally it stores the each 
  message in a file in a directory and when trying to search 
  several hundred thousand messages for a word the response back
  is:
  
  egrep: argument list too long
  
 
 If I was trying to grep a zillion files at once and it wouldn't 
 let me I'd probably grep them one at a time.
 For instance via the backtivck execution You might have:
 
 my @matchedfiles = qx(cat `ls /files/` |grep $string);
 # a really bad way to do this but for example's sake...
 
 You could do:
 
 for(`ls /files/`) {
   if(`cat $_ |grep $string`) { push(@matchedfiles,$_); }
 }

Are you sure about using ls?  We have directory here that has several
thousand files in it and when doing an ls *.whatever-extension we always
get an argument list too long.

Any idea what the actual file limit is for grep?

 
 Then you are only greping one file at a time instead of a list of too many.
 Of course what would be better is to use the readdir() functions to list the files 
 and open() and grep() combo to grep the contents. But the same principle applies.
 
 Just make sure the barracuda folks says thanks for fixing their problem :)

Yeah, we're hoping for a few months of service for free.:)

This was also a personal quest to find the answer for myself.  So either
way I win.

Thanks for your help,
Kevin
-- 
Kevin Old [EMAIL PROTECTED]


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



Re: Exponential numbers

2003-10-09 Thread david
Pedro Antonio Reche wrote:

 Dear all,
 I have a table that has exponential numbers of the type 0.203E-2 and I
 will like to reformat getting rid off the exponential so that the
 previous number would look when printed as 0.00203.
 Is there any easy way to do this?
 Any help welcome.

brain dead approach:

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

for(qw~ 0.203E-20.203E+9 0.203e-9
0.20233E-12 0.123e+3 3435E+15 ~){

/(\d+)E(.)(\d+)/i;

my $l = $2 eq '+' ? 0 : length($1) + $3;

printf('%20s'. '%.' . $l . f\n,$_ becomes ,$_);
}

__END__

prints:

   0.203E-2 becomes 0.00203
   0.203E+9 becomes 20300
   0.203e-9 becomes 0.0203
0.20233E-12 becomes 0.20233
   0.123e+3 becomes 123
   3435E+15 becomes 3435000

perldoc -f sprintf
perldoc -f printf

david
-- 
$_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$;
map{~$_1{$,=1,[EMAIL PROTECTED]||3])=~}}0..s~.~~g-1;*_=*#,

goto=print+eval

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



Perl Debugger

2003-10-09 Thread Jeff Westman
Hi,

I'm using perl version 5.6.1 for Unix (HPUX-11).  I would like to be able to
retain my 'watches' and breakpoints in between debug sessions.  Is there a
way to do this with the standard debug library that comes with perl?

(I know I can save these with the ptkdb package, but I cannot get that to
work since it requires Tk which requires gcc which requires other libraries
... long story, but that's not an option)


TIA


-Jeff

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



getting end of an array

2003-10-09 Thread rmck
Hi,

I have a script that I what the last part of the element of an array? So I can restart 
the script with the same element. Help:

#!/bin/perl
use strict;
 
# Need IP of current procees so I can re-start it.
# How it is returned:
# root  6762  1355  0   Oct 05 pts/20:00 /bin/perl -w ./script.pl 
211.211.111.111
#  

my @ip = `ps -ef|grep script.pl|grep -v grep`;
  
# Grab PID of current procees so I can kill it.
# How it is returned:
#6762
#
my @script= `pgrep script.pl`;
 
foreach (@nab) {
print(Killing $_\n);
}
 
foreach (@ip){
print /opt/script.pl $_\n;   
  
}

###


whats displayed:

bash-2.03# ./ks.pl 
 
Killing 6762
 
/opt/script.pl root  6762  1355  0   Oct 08 pts/20:00 /bin/perl -w ./script.pl 
211.211.111.111
 
bash-2.03# 

I would lilke it to:
bash-2.03# ./ks.pl 
 
Killing 6762
 
/opt/script.pl 211.211.111.111 
 
bash-2.03# 


Please advise...And of course thanks
Rob

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



Re: getting end of an array

2003-10-09 Thread Rob Dixon
Hi Rob.

I'm trying to help. Really I am. But first of all it looks
like you should be writing a bash script file (Perl isn't
a scripting language).

Please explain:

Rmck wrote:

 I have a script that I what the last part of the element of
 an array? So I can restart the script with the same element.
 Help:

 #!/bin/perl
 use strict;

 # Need IP of current procees so I can re-start it.
 # How it is returned:
 # root  6762  1355  0   Oct 05 pts/20:00 /bin/perl -w ./script.pl 
 211.211.111.111
 #

 my @ip = `ps -ef|grep script.pl|grep -v grep`;

This will grab the output of the command line into a
Perl array '@ip' of output records.

You seem to be doing this so that you can get the PID '6762'
from the output?

 # Grab PID of current procees so I can kill it.
 # How it is returned:
 #6762
 #
 my @script = `pgrep script.pl`;

OK, now you're getting the output records of another command
into another array '@script' which you never use again.

You seem to be doing this so that you can get the PID '6762'
from the output in a different way?

 foreach (@nab) {
 print(Killing $_\n);
 }

You're printing the contents of Perl array @nab (which you
haven't used before) saying that each element has been
'killed'. The array is empty and this will output nothing.

 foreach (@ip){
 print /opt/script.pl $_\n;
 }

And now you're printing the contents of '@ip' with each
record prefixed with '/opt/script.pl ' and an additional
newline appended.

 ###


 whats displayed:

 bash-2.03# ./ks.pl
 Killing 6762

 /opt/script.pl root  6762  1355  0   Oct 08 pts/20:00 /bin/perl -w 
 ./script.pl 211.211.111.111

 bash-2.03#

 I would lilke it to:
 bash-2.03# ./ks.pl
 Killing 6762

 /opt/script.pl 211.211.111.111 

 bash-2.03#

This part I don't understand at all. Perhaps others do?

What is 'ks.pl'? Is it the name of the Perl script that
you've shown us?

 Please advise...And of course thanks

You're writing a Perl program which essentially runs 'ps'
and prints the output slightly reformatted.

Try to explain what it is you want to do.

And I still think you should be writing a bash script!

I hope this helps in some way.

Rob



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



Re: grep argument list too long...how to get around it?

2003-10-09 Thread Randal L. Schwartz
 Dan == Dan Muey [EMAIL PROTECTED] writes:

Dan for(`ls /files/`) {
Danif(`cat $_ |grep $string`) { push(@matchedfiles,$_); }
Dan }

Hmm.  Where to begin?

- Dangerous use of ls.
- Useless use of cat.
- Dangerous use of backticks.
- Shelling out when every one of those steps is done as well
  or better by Perl.
- Insecure use of child shells

In short, code that should be used as a BEFORE model in a BEFORE
and AFTER talk on any of the subjects of best practices, security,
optimizing for speed, maintainability, dealing with filenames with
whitespace, etc etc.

Dan Then you are only greping one file at a time instead of a list of
Dan too many.  Of course what would be better is to use the readdir()
Dan functions to list the files and open() and grep() combo to grep
Dan the contents. But the same principle applies.

More than just better.  More correct.  Safer.  Faster.  Easier to
maintain.  Less likely to break when tried on real-world stuff.

I say this not because I am criticizing you Dan, but because I want to
make sure that NOBODY ELSE ON THIS BEGINNER LIST COPIES THAT CODE for
their own purposes.  It's really just so far off the mark to be badly
dangerous.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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



Re: grep argument list too long...how to get around it?

2003-10-09 Thread Rob Dixon
Randal L. Schwartz wrote:

  Dan == Dan Muey [EMAIL PROTECTED] writes:

 Dan for(`ls /files/`) {
 Dan if(`cat $_ |grep $string`) { push(@matchedfiles,$_); }
 Dan }

 Hmm.  Where to begin?

 - Dangerous use of ls.
 - Useless use of cat.
 - Dangerous use of backticks.
 - Shelling out when every one of those steps is done as well
   or better by Perl.
 - Insecure use of child shells

Hi Randal.

I'll buy most of those, but wonder at your choice of 'dangerous'
and 'insecure'?

The return from the 'ls' bactick is certainly unpredictable and
dependent on context. Is that what you mean? And surely backticks
can't be inherently dangerous in any sense, only the command line
that they embrace?

It would be useful if you could explain what security breaches
are potentiated by 'child shells' (and isn't this just another
phrase for 'backticks'?)

'Shelling out' ('backticks' again) is a symptom of the
misconception of Perl as a scripting language, and I think the
criticism is better made in those terms. It is comparable to
the weak code arising from misconceiving Perl as being C.

It helps to stand a few more up when you knock some down :)

Rob



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



Re: getting end of an array

2003-10-09 Thread Dan Anderson
 And I still think you should be writing a bash script!

humour
TMTOWTDI

:-D
/humour

-Dan


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



RE: grep argument list too long...how to get around it?

2003-10-09 Thread Bakken, Luke
  Dan for(`ls /files/`) {
  Dan if(`cat $_ |grep $string`) { push(@matchedfiles,$_); }
  Dan }
 
  Hmm.  Where to begin?
 
  - Dangerous use of ls.
  - Useless use of cat.
  - Dangerous use of backticks.
  - Shelling out when every one of those steps is done as well
or better by Perl.
  - Insecure use of child shells
 
 Hi Randal.
 
 I'll buy most of those, but wonder at your choice of 'dangerous'
 and 'insecure'?
 
 The return from the 'ls' bactick is certainly unpredictable and
 dependent on context. Is that what you mean? And surely backticks
 can't be inherently dangerous in any sense, only the command line
 that they embrace?

Randal's thinking of something like a file in the /files/ dir named $(rm -rf /), I 
think.

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



Regular Expression question

2003-10-09 Thread Trina Espinoza
How do you create a regular expression that allows you to have files like 
ths:
Stuff_Dev
Greg_Files
myThings_
_default

I wrote this

s/([A-Za-z]*)/\n$1/g;

It only gets the letters, but I am not sure how to write in the underscore. 
Any attemps I have made
on adding the _ get the wrong results e.g --s/([A-Za-z]_*)/\n$1/g; 
---Didn't work.Created a newline
right before the underscore.

Assistance would be much appreciated :)

-T

_
Get McAfee virus scanning and cleaning of incoming attachments.  Get Hotmail 
Extra Storage!   http://join.msn.com/?PAGE=features/es

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


Sound in Perl?

2003-10-09 Thread Jamie Martin
Hi,

I am trying to mess around with sound a little bit. I want to write an
ear-training exercise in which you practice distinguishing intervals smaller
than a semitone. Can I generate tones in Perl? Can I specify them in cents
(hundreths of a semitone . . . a semitone is the distance between two
adjacent keys on a piano), or in cycles per second? If not, what other
language might I try? Do I need special hardware?

Thanks,

Jamie



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



RE: Regular Expression question

2003-10-09 Thread Dan Muey
 I wrote this
 
 
 s/([A-Za-z]*)/\n$1/g;

Try this: 

s/\W//g;

\w matches letters number and underscores \W matches  anythgiin not letters numbers or 
underscores.
Take a look at tr also it may be able to help you out.


HTH

Dmuey

 
 
 It only gets the letters, but I am not sure how to write in 
 the underscore. 
 Any attemps I have made
 on adding the _ get the wrong results e.g --s/([A-Za-z]_*)/\n$1/g; 
 ---Didn't work.Created a newline
 right before the underscore.

You put the newline there your self with \n if you don't want newline you must remove 
that.

 
 Assistance would be much appreciated :)
 
 -T

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



RE: Regular Expression question

2003-10-09 Thread Hanson, Rob
Like Jeff said, you can just use \w if you are allowing numbers as well.

 s/([A-Za-z]_*)/\n$1/g;

This will take a little bit of explaining, so bear with me.

[ ... ] - Brackets represent a character class.  A char class will match a
SINGLE char that is inside of it.  So if I wanted to match a, b, or c
I would use [abc].  As a shortcut you can use a range to specify a list of
chars.  A range line a-k is the same as abcdefghijk.  Ranges are just a
shortcut, and you can use ranges along with single chars in the char class.
So I could match a single char that is in the range a-k or is a z by
using [a-kz].

Your mistake was that you placed the underscore (_) outside of the range,
not inside it.

This is what you meant to do:

s/([A-Za-z_]*)/\n$1/g;

Hope that helps.

Rob

-Original Message-
From: Trina Espinoza [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 09, 2003 4:11 PM
To: [EMAIL PROTECTED]
Subject: Regular Expression question


How do you create a regular expression that allows you to have files like 
ths:
Stuff_Dev
Greg_Files
myThings_
_default

I wrote this


s/([A-Za-z]*)/\n$1/g;


It only gets the letters, but I am not sure how to write in the underscore. 
Any attemps I have made
on adding the _ get the wrong results e.g --s/([A-Za-z]_*)/\n$1/g; 
---Didn't work.Created a newline
right before the underscore.

Assistance would be much appreciated :)

-T

_
Get McAfee virus scanning and cleaning of incoming attachments.  Get Hotmail

Extra Storage!   http://join.msn.com/?PAGE=features/es


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

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



Re: Regular Expression question

2003-10-09 Thread James Edward Gray II
On Thursday, October 9, 2003, at 03:43  PM, Dan Muey wrote:

I wrote this

s/([A-Za-z]*)/\n$1/g;
Try this:

s/\W//g;
That looks like a capital W to me, though your explanation used the 
correct w.  \W matches any NON-word character and thus wouldn't work 
here.

James

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


Re: undefined subroutine

2003-10-09 Thread Dodo
Dynamic page...just some server side include and a menu.



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



File::Path question

2003-10-09 Thread Prasad Karpur
I initially set $value1, $value2 and $value3 to null values
$value1 = ; $value2 = ; $value3 = ;
I get the values of $value1, $value2 and $value from input

$valuexyz = $value1$value2$value3;

mkpath([$TMPDIR/$valuexyz], 1, 0777);

$valuexyz does not get evaluated. But if i set $value = a1 and $value2 = 
b1 and $value3 = c1, then mkpath works fine. What am i doing wrong?

Thanks

Prasad

_
Instant message in style with MSN Messenger 6.0. Download it now FREE!  
http://msnmessenger-download.com

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


Re: Exponential numbers

2003-10-09 Thread david
John W. Krahn wrote:

 David wrote:

 brain dead approach:
 
 #!/usr/bin/perl -w
 use strict;
 
 for(qw~ 0.203E-20.203E+9 0.203e-9
 0.20233E-12 0.123e+3 3435E+15 ~){
 
 /(\d+)E(.)(\d+)/i;
 my $l = $2 eq '+' ? 0 : length($1) + $3;
 
 You shouldn't use the numerical scalars unless the match was successful.
 
   /(\d+)E(.)(\d+)/i and my $l = $2 eq '+' ? 0 : length($1) + $3;

it won't fail for the numbers i have for this test but yes, error checking 
is generally almost always a good thing.

 
 
 printf('%20s'. '%.' . $l . f\n,$_ becomes ,$_);
 
 That could also be written as:
 
   printf %20s%.*f\n, $_ becomes , $l, $_;

yes, whichever you prefer.

 
 
 }
 
 Or, you could write it like this:
 
 for ( qw(0.203E-2 0.203E+9 0.203e-9 0.20233E-12 0.123e+3 3435E+15) ) {
 ( my $l = sprintf %.18f, $_ ) =~ s/\.?0+$//;
 printf %12s becomes %s\n, $_, $l;
 }

no. try it with 0.20233e-20.

david
-- 
$_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$;
map{~$_1{$,=1,[EMAIL PROTECTED]||3])=~}}0..s~.~~g-1;*_=*#,

goto=print+eval

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



Re: grep argument list too long...how to get around it?

2003-10-09 Thread Randal L. Schwartz
 Rob == Rob Dixon [EMAIL PROTECTED] writes:

Rob Randal L. Schwartz wrote:
 
  Dan == Dan Muey [EMAIL PROTECTED] writes:
 
Dan for(`ls /files/`) {
Dan if(`cat $_ |grep $string`) { push(@matchedfiles,$_); }
Dan }
 
 Hmm.  Where to begin?
 
 - Dangerous use of ls.
 - Useless use of cat.
 - Dangerous use of backticks.
 - Shelling out when every one of those steps is done as well
 or better by Perl.
 - Insecure use of child shells

Rob Hi Randal.

Rob I'll buy most of those, but wonder at your choice of 'dangerous'
Rob and 'insecure'?

Rob The return from the 'ls' bactick is certainly unpredictable and
Rob dependent on context. Is that what you mean? And surely backticks
Rob can't be inherently dangerous in any sense, only the command line
Rob that they embrace?

It's not a full PATH, hence it is subject to PATH manipulation.
It doesn't deal with filenames that contain newlines.

Rob It would be useful if you could explain what security breaches
Rob are potentiated by 'child shells' (and isn't this just another
Rob phrase for 'backticks'?)

Rob 'Shelling out' ('backticks' again) is a symptom of the
Rob misconception of Perl as a scripting language, and I think the
Rob criticism is better made in those terms. It is comparable to
Rob the weak code arising from misconceiving Perl as being C.

Rob It helps to stand a few more up when you knock some down :)

Rather than repeat it, I'll merely point you to my latest
UR column at http://www.stonehenge.com/merlyn/UnixReview/col48.html.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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



finding a spot in a file

2003-10-09 Thread chad kellerman
Hello,

   I am opening up a file (actually a my.conf).  I only want 2 lines in
the file.  port and datadir

   The problem I am running into is that there is a port = 3324 in both
the [client] section and the [mysqld] section.

   I want to open the file and go straight to the [mysqld] section and
grab the values for port and datadir.

   Can anyone point me in the right direction?


Thanks,
Chad


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