Re: Fw: Could [you] [please] tell me how to remove white spacees presentbetween delimiter[s]

2005-09-02 Thread James Taylor

#!/usr/bin/perl

my $st1="'---'~^  '123PS01D'~^";
for(split(/\~\^/,$st1)) {
  $_ =~ s/\s//g;
  # Do something with your variable
}


Is that what you're asking? I'm unsure

[EMAIL PROTECTED] wrote:


'---'~^  '123PS01D'~^

here delimiter is ~^ 


'---'~^'123PS01D'~^

Do u see the difference in the two lines 
In the first one there is space is present i want to remove that one 
The second is ok..

I think it will clear u in the better way.


with regards



Mayank Ahuja
Assistant System Engineer
Tata Consultancy Services Limited
Ph:- 044-5816
Cell:- 9283199460
Mailto: [EMAIL PROTECTED]
Website: http://www.tcs.com
- Forwarded by Mayank Ahuja/CHN/TCS on 09/02/2005 09:16 PM -

Chris Devers <[EMAIL PROTECTED]> 
09/02/2005 09:03 PM

Please respond to
Perl Beginners List 


To
[EMAIL PROTECTED]
cc
Perl Beginners List 
Subject
Re: Could [you] [please] tell me how to remove white spacees 
presentbetween  delimiter[s]







On Fri, 2 Sep 2005 [EMAIL PROTECTED] wrote:

 

I have a file like this in which data is 
abc,def,xyz,mno, 


means the delimter is comma here

but in the string if it comes abc, def,  xyz, mno

then [please] tell me how to remove this white space.
   



The popular way to do this around here is with a Perl program.

Can you show the list the Perl program you've tried so far? 

If you can, we can try to give you feedback. 


Good luck!


 




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




Re: Mod_Perl Pass Associative Arrays

2004-12-11 Thread James Taylor
Chris Devers wrote:
On Fri, 10 Dec 2004, James Taylor wrote:

Hi everyone, wondering if anyone knew how to pass an associative array 
via POST to mod_perl.  Something like:

HTML forms don't really provide for complex data structures, so any 
solution is going to have to be cobbled together.

I think your best bet is to just have form elements with names like 
'searchname', 'searchemail', etc, and just have code on the server to 
organize it into a hash:

  $search{name}  = $req->param('searchname');
  $search{email} = $req->param('searchemail');
etc. 

 

Eh, score 1 for PHP then.  The reason I can't specifically do what 
you're mentioning is that the field names being passed could be 
ANYTHING, as the code is for a module I'm writing.  Anyway, I went ahead 
and just made it cheesy, instead of doing field[something], i made all 
of the input names "field=something", send the hash through a foreach 
loop - if the name of the field =~ /field/, i split on the = and ditch 
the first variable.  Feh

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



Mod_Perl Pass Associative Arrays

2004-12-10 Thread James Taylor
Hi everyone, wondering if anyone knew how to pass an associative array 
via POST to mod_perl.  Something like:



then it posts to say.. example.pl

my $r=Apache->request;
my $req=Apache::Request->new(shift);
my %stuff=$req->param('search');
That for example doesn't work, but... I'd like it to :)  Anyone know how 
to get this going?  By the way, I *need* the names to preserve, having 
search[] would defeat the purpose of what I'm trying to do here.  Thanks

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



Mod_Perl Target Headers

2004-11-04 Thread James Taylor
I posted this to the mod_perl list originally, but noone ever answers my 
questions on there.  Guess my noob questions don't belong on that list:
Again, this is for mod_perl
Should be a pretty simple question, looking for an option in header_out 
to target a frame.

For example...
snip
$r=Apache->request;
$r->err_header_out("Pragma", "no-cache");
$r->header_out('Location' => 'http://www.somesite.com/login_expired.html');
$r->status(REDIRECT);
$r->send_http_header;
snip
Was hoping I could do something like:
$r->header_out('Target'=>'_top');
but that doesn't seem to work.  Any suggestions?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Mod Perl Helper Functions

2004-10-05 Thread James Taylor
Bob Showalter wrote:
FWIW, That example works OK for me under Apache 1.3.31, mod_perl 1.29 when I
run under Apache::Registry. I had to add a declaration for %somehash, but
otherwise it runs without error. Is main.pl running under Apache::Registry,
or is it a PerlHandler or some other type of handler?
It always makes me nervous to see assumptions about the current working
directory in any web server stuff. You should code the full path to
helper.pl, or better, create a proper module and pull it in with use.
 

Here's a better example of something that actually might serve a bit 
more purpose along with the error I'm getting for THIS
particular example.

And yes, this is running under Apache::Registry:
test.pl:
#!/usr/bin/perl
use strict;
use Apache::Constants qw(OK DECLINED SERVER_ERROR FORBIDDEN);
use Apache::Cookie ();
require('lib/helper.pl');
print "Content-type: text/html\n\n";
my $rand=&genrand(20);
print "$rand";
helper.pl:
sub genrand {
  my [EMAIL PROTECTED]; my $r;
  my @chars=('a'..'z','A'..'Z','0'..'9','_');
  $r.=$chars[rand @chars] for(1..$l);
  return $r;
}
1;
When running test.pl, I get the following in my logs:
Use of uninitialized value in foreach loop entry at lib/helper.pl line 4.
Use of uninitialized value in foreach loop entry at lib/helper.pl line 4.
Use of uninitialized value in concatenation (.) or string at 
/export/home/newsite/perl/test.pl line 10.

So, what I can gather is that the value '20' isn't being received by the 
genrand subroutine, and it's getting something else instead.  What 
exactly, I'm not sure
but I know it has to do SOMETHING with Apache::Registry.  To test things 
out, I went ahead and changed the genrand sub to spit out what it was 
receiving:

sub genrand {
   my @[EMAIL PROTECTED]; my $r;
   $r.="$_\n" for @blah;
   return $r;
}
What did it return? "20"
Now how the hell that happened, I don't know, but it STILL isn't getting 
that value passed.  Any idea what apache's sending here and why it 
doesn't want to
grab the variable?

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



Mod Perl Helper Functions

2004-10-05 Thread James Taylor
I posted this to the mod_perl list 2 days ago, but it seems a bit 
inappropriate there as the discussion is much more
advanced than my question... That and I haven't gotten a response, so 
sorry for the crosspost :)

I'm running apache 1.3.x with the associated version of mod_perl, but am 
having trouble creating regular old include
files to be used with helper functions.  Works just great with regular 
old CGI, mod_perl doesn't like it.  Say for example I have two files, 
main.pl and helper.pl.

# helper.pl
sub dowhatever() {   # this is completely pointless, i'm just using it 
as an example
  my [EMAIL PROTECTED];  my $p;
  foreach my $k(sort keys %params) { $k =~ s/'$//g;  $p.=$k; }
  return $p;
}
1;

# main.pl
#!/usr/bin/perl
use strict;
use Apache::Constants qw(OK DECLINED SERVER_ERROR FORBIDDEN);
use Apache::Cookie ();
require('helper.pl');
#..some stuff
my $q=&dowhatever(%somehash);
That doesn't work in the least, I keep getting errors in my apache logs 
saying sub dowhatever is an undefined function, etc.  Is it possible to
even do anything like this in mod_perl, or do I need to write an Apache 
module / Perl Module just to have helper functions in there?
Also, I know it's poor style to put multiple statements on 1 line, I 
just wanted to make this message shorter, so no style tips please. 
Thanks for any help!

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



Re: Modifying STDIN

2004-03-16 Thread James Taylor
I actually can't do it that way, this is a part of a custom perl module 
that someone wrote, and those are just 2 lines from the module.

On Mar 15, 2004, at 11:01 PM, Randy W. Sims wrote:

On 03/16/04 00:06, James Taylor wrote:
I'm modifying a script someone wrote that basically reads a file file 
into STDIN, and I was curious if there was anyway of modifying the 
stdin value without having to first open the file, modify it, close 
the file, and then open it into stdin.
I think what you want is a traditional filter:

=== myfilter.pl ===
#!/usr/bin/perl
use strict;
use warnings;
while (my $line = <>) {
  chomp($line);
  $line =~ s/^/sprintf("%3s ", $.)/e;
  print "$line\n";
}
__END__

piping it to its own STDIN produces

cat myfilter.pl | perl myfilter.pl

  1 #!/usr/bin/perl
  2
  3 use strict;
  4 use warnings;
  5
  6 while (my $line = <>) {
  7   chomp($line);
  8   $line =~ s/^/sprintf("%3s ", $.)/e;
  9   print "$line\n";
 10 }
See perldoc perlopentut, section "Filters"

Regards,
Randy.


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



Modifying STDIN

2004-03-15 Thread James Taylor
I'm modifying a script someone wrote that basically reads a file file 
into STDIN, and I was curious if there was anyway of modifying the 
stdin value without having to first open the file, modify it, close the 
file, and then open it into stdin.

Basically, looks like:

open(STDIN,$filename) || die "whatever\n";
close(STDOUT);
Well, I need to to a search/replace on STDIN, something like:

open(STDIN,$filename) || die "blah\n";
STDIN =~ s/one/two/g;
close(STDOUT);
Line 2 isn't intended to work, it's just there to show you what i'm 
trying to accomplish.

Thanks for your help!

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



Re: regex multiple lines

2004-01-02 Thread James Taylor
ok, well I ended up dropping the regex and splitting the strings and 
re-building them after being inspired by another thread.

so,

my $str="text 
text to
be replac
ed";
my $repl="replacement text";
my ($a,$b)=split('',$str);
my ($c,$d)=split('',$b);
$str=$a.$repl.$d;
I'd still like to know if you can do this via regex however.

On Jan 2, 2004, at 5:38 PM, James Taylor wrote:

I'm trying to parse a bit out of an HTML file, where the formatting 
could change daily as far as spaces/newlines go.  Say for example I 
have something like this:

$str=<

Hello this is juts an example
blahahahaha
http://www.somewhere.com";>
HELLO
Hello world

EOF
$repl="Replacement Text";

$str =~ s/\.+?/mi

comes up with nothing, though I am able to match them on their own.  
Thanks

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



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



regex multiple lines

2004-01-02 Thread James Taylor
I'm trying to parse a bit out of an HTML file, where the formatting 
could change daily as far as spaces/newlines go.  Say for example I 
have something like this:

$str=<

Hello this is juts an example
blahahahaha
http://www.somewhere.com";>
HELLO
Hello world

EOF
$repl="Replacement Text";

$str =~ s/\.+?/mi

comes up with nothing, though I am able to match them on their own.  
Thanks

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



Re: CGI Script Fork

2003-11-22 Thread James Taylor
The reason I need to run it in the background and just display the 
message is that the person that's going to be running this program 
wants to be able to close the window.  The process running in the 
background can take up to 10 minutes and he's afraid that he may 
accidentally close the window while it's running and thus will have to 
start the process again.  So, the reason for the fork isn't for the 
message to be displayed, it's so that it starts the system call in the 
background so we don't have to sit through it.

On Nov 21, 2003, at 11:08 PM, Robert Brown wrote:

If the only real purpose for the fork is so that the message can be
displayed, why don't you just display the message in a form, and then
go do the long operation single threaded.  When the long operation
finishes, continue to output to the same page and use some javascript
to change the contents of the form field where it says please wait.
I wrote a web based chat over a year ago that makes use of the fact
that if you specify a large value in the file size header, the browser
will stay connected for quite a while.  I can output posted messages
to the browser and it will display them as they come.  It will just
patiently wait there with its busy indicator showing, but it works
fine.  If you experience timeout problems, just output a blank space
character every 3 seconds or so.  This will not change anything, as
the text is being set via html rendering, sso spaces don't count.
If, on the other hand, you really need to fork a background task, you
may be thwarted by the apache perl cgi module that keeps the perl
interpreter in apache instead of forking a new perl for every cgi
script.  I do not know if you can fork a background task with
perl-cgi-mod or not.


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


CGI Script Fork

2003-11-21 Thread James Taylor
I'm working on a cgi script that basically, upon running it, runs a
separate script in the background, and displays a message saying
"Script is running.  Should be done soon." on the web browser and...
that's it.  The browser can be closed, and the script will continue to
run in the background.  Here's the jest of what I have, but... The
problem is that it doesn't work.  When you run it, it does a system()
call to run the script, and then waits for completion, where it then
displays "Script is running.  Should be done soon.".  I tried using
exec() instead but that didn't work either.  Also tried adding & to the
end of the command, didn't help.
#!/usr/bin/perl
use strict;
use CGI qw(:cgi-lib :cgi :html2);
$SIG{CHLD}='IGNORE';
my $pid=fork();
if($pid) {
system "/www/scripts/process_list.pl";   # Run script in background
} else {
# Print confirmation script to browser, that's it
print header."Script is running.  Should be done
soon.";
}
Any ideas on how to make this work properly??  This is running on 
Solaris 8 with apache, if it matters at all.  Thanks

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


conf files

2002-06-10 Thread James Taylor

I have this app I just wrote, and I wanted to give my users a more 
'standard' .conf file, instead of forcing them to open up the script, 
and dig through and change variables (Some people get confused by 
this... Go figure).  SO, I wanted to give a .conf sort of like the 
apache conf file where you'll see things like:

ENCRYPTION=1 
#Set this to 0 if you don't want encryption
ENCTYPE=3DES 
# 3DES or BLOWFISH
BASEDIR=/home/user 
# Path to something


## Sockets #

PORT=1200 
# Port to connect to
TYPE=TCP 
# TCP or UDP
HOST=localhost 
# Hostname



You get the idea.  Anyway, I could make a file like this and then 
'require' it I suppose, then run a regex on the lines and assign the 
variables THAT way, but I was curious if anyone could think of a better 
way to do this instead of forcing myself to make all these un-needed 
lines in my script just to get the variables.  Maybe a module or 
something?  Any suggestions would be appreciated!



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




CHAP?

2002-06-05 Thread James Taylor

I have a program I wrote, client and server, that communicate through 
sockets - There currently is no sort of authentication between the two 
other than hosts.allow allowing the IP of the client for that port, and 
that's all.  People wanting to use my program have told me they won't 
use it unless I implement some sort of encryption using SSL or SSH 
tunneling.  I don't really want to do this, so i was thinking of putting 
in some sort of challenge handshake, using MD5 hashes based on 
'something'.  Does anyone know of any good examples on how to do this, 
or where to start?

I'm thinking there is some sort of common passcode between the 
client/server - The client sends a number based on some sort of 
algorythm performed on the code - The server takes that, runs it through 
it's own algorythm, and then the client has to send another number, and 
that number should match what the server came up with.  I haven't really 
done any mathematical programming, so.. I don't know how to write this 
where it would be too weak.

Any suggestions on where to start?


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




another regex question

2002-04-22 Thread James Taylor

Hmm, it looks like something was wrong with my mail server, so I'm 
sending this question again - If you already got this, I apologize:


I'm have this program that reads over mail logs looking for spammers, 
and depending on certain conditions, they're marked as a spammer.  If 
the reverse lookup on the relay used matches their email address 
however, no matter what, we're not marking them as a spammer. However, 
I've run across a problem where a users email address can look something 
like

[EMAIL PROTECTED]

and the relay used will be reversed to:

relay.inthemiddleofnowhere.com

How do I match JUST the last part of the address, so that 
inthemiddleofnowhere.com is the only thing picked up, no matter how many 
subdomains are listed, and it also matches if the email address is just 
[EMAIL PROTECTED] ? I can't seem to figure this one out.


Also, there is one spammer in particular who's email addresses look 
something like:

OWNER-NOLIST-3249_Columbia_music*TJUDKINS**EXO*[EMAIL PROTECTED]

When I get one of the emails from this spammer, I get this error with 
the script:

Nested quantifiers before HERE mark in regex 
m/OWNER-NOLIST-3249_Columbia_music*TJUDKINS** << HERE
EXO*[EMAIL PROTECTED]/ at /sbin/removespam.pl line 10.

I'm assuming the asterisk is breaking the regex already in place 
somehow. Anyone know what might be causing this one, and how to fix it?






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




another regex question

2002-04-22 Thread James Taylor

I'm have this program that reads over mail logs looking for spammers, 
and depending on certain conditions, they're marked as a spammer.  If 
the reverse lookup on the relay used matches their email address 
however, no matter what, we're not marking them as a spammer. However, 
I've run across a problem where a users email address can look something 
like

[EMAIL PROTECTED]

and the relay used will be reversed to:

relay.inthemiddleofnowhere.com

How do I match JUST the last part of the address, so that 
inthemiddleofnowhere.com is the only thing picked up, no matter how many 
subdomains are listed, and it also matches if the email address is just 
[EMAIL PROTECTED]? I can't seem to figure this one out.


Also, there is one spammer in particular who's email addresses look 
something like:

OWNER-NOLIST-3249_Columbia_music*TJUDKINS**EXO*[EMAIL PROTECTED]

When I get one of the emails from this spammer, I get this error with 
the script:

Nested quantifiers before HERE mark in regex 
m/OWNER-NOLIST-3249_Columbia_music*TJUDKINS** << HERE
EXO*[EMAIL PROTECTED]/ at /sbin/removespam.pl line 10.

I'm assuming the asterisk is breaking the regex already in place somehow. Anyone know 
what might be causing this one, and how to fix it?





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




TK madness

2002-04-18 Thread James Taylor

I'm trying to develop a user interface for a program I've written - What 
I need the program to do is print out the results of the current process 
to the TK interface.  I absolutely can not figure out how to do a simple 
printing to TK function!@@!#  For example, I would have a program that 
does something like:

for (1 .. 10) {
   print "$_\n";
}

Well, I need to print that into the canvas in TK.  How the hell do I do 
this?! It seems like something so trivial, yet not even the Perl/TK 
tutorial talks about something as simple as this.


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




More Bidirectional Sockets w/ Win32 Client

2002-04-16 Thread James Taylor

I have figured out how to set up bidirectional communication through 
sockets by forking the server and the client - The client forks just 
fine under Linux, but if I take the script to Win32 fork doesn't seem to 
work.  This is the code for both the server and client:

Here's the server:

#!/usr/bin/perl

use IO::Socket;
$SIG{CHLD} = sub {wait ()};

$main_sock = new IO::Socket::INET (LocalHost=> 'shell',
   LocalPort=> 1200,
   Listen   => 5,
   Proto=> 'tcp',
   Reuse=> 1,) or die "Couldn't 
create socket: $!\n";

while ($new_sock = $main_sock->accept()) {
   $pid = fork();
   die "Cannot fork: $!\n" unless defined($pid);

   if ($pid == 0) {
  # Child Process
  while (defined ($buf = <$new_sock>)) {
 chomp($buf);
 print "Client said: $buf\n";
 print $new_sock "You said: $buf\n";
  }
  exit(0);
   }
}

close ($main_sock);


And here's the client:

#!/usr/bin/perl

use IO::Socket;
$client = new IO::Socket::INET (PeerAddr => 'shell',
  PeerPort => 1200,
  Proto => 'tcp'
 ) or die "Couldn't create socket: $!\n";


my $pid = fork();  die "Cannot fork\n" unless defined $pid;

if ($pid) {
write_sock();
waitpid($pid, 0);
} else {
read_sock();
}

sub write_sock {
   for (1 .. 10) {
  print $client "$_\n";
   }

}

sub read_sock {
while (my $line = <$client>) {
print $line;   # report to stdout
}
}



Like I said, this works just fine on Linux->Linux.  When the client is 
Win32 however - it writes to the server just fine, but will just sit 
there and never read.  When I press control-C to escape out of the 
program, it THEN reads the data from the server.   I tried reading into 
IO::Select to see if that would fix my problem with the client, but I 
just can't figure it out. Can someone help me with this??




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




Bidirectional Sockets

2002-04-15 Thread James Taylor

I'm sure this is frequently asked, and I am truly sorry if it is, but 
reading through my mail I don't see this question anywhere:

Curious as to how I would go about creating bidirectional sockets, ie. 
client sends information to the server, then server responds to the 
client.  I need to know how to do this so that I can tell whether or not 
an operation was successful or not. The server is currently set up like:

while ($new_sock = $sock->accept()) {
   while (defined ($buf = <$new_sock>)) {
   (do something);
}
}

I tried printing to $new_sock, but the client obviously isn't listening 
- Do I have to create a client/server for both the actual client, AND 
the server? Can someone point me in the right direction here? Thanks


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




Fidning the index of an array

2002-04-11 Thread James Taylor

How can I get the current index of an array while processing the array 
in a loop? I know I can do it with a counter type function, but I was 
curious if there was a better way of doing this.

For example:

my @array = (1 .. 100);
my $counter = 0;

for (@array) {
   print "index -> $counter   element -> $_\n";
   $counter++;
}

Well, how do I do that without the counter?



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




Re: Regex!

2002-04-10 Thread James Taylor


There's a few problems with your script. This one works:

$money = '$27.50';
$money =~ s/\$//;

Use single quotes instead of double, and don't forget the =~ instead of =

Daniel Falkenberg wrote:

>Hi Tim,
>
>I just tried running $money = s/\$//: over
>
>$money = "$21.80";
>
>And my returned result was nothing!  I.e it removed everything?
>
>Any ideas,
>
>Dan
>
>On Wed, 2002-04-10 at 09:34, Timothy Johnson wrote:
>
>>You have to escape the dollar sign in your regex just like you did in the
>>assignment.
>>
>>$money = s/\$//;
>>
>>-Original Message-
>>From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]]
>>Sent: Tuesday, April 09, 2002 5:10 PM
>>To: [EMAIL PROTECTED]
>>Subject: Regex!
>>
>>
>>Hello All,
>>
>>Just wondering how I can remove unwanted characters from a simple
>>variable.
>>
>>$money = "\$21.85";
>>
>>Now I simply want to strip the $ sign from that variable.
>>
>>Easy?  Well I thought it would be :)
>>
>>$money = s/$//; # Well thats what I thought!
>>
>>Regards,
>>
>>Dan
>>
>>
>>
>>-- 
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>>
>>This email may contain confidential and privileged 
>>material for the sole use of the intended recipient. 
>>If you are not the intended recipient, please contact 
>>the sender and delete all copies.
>>



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




Looping over Hashes of Arrays

2002-04-03 Thread James Taylor

How do you get a list of all keys in a hash of arrays?  I'll have a hash 
where the data would look something
like:

%myhash = ('client19' => [ 'client2', 'client5', 'client7' ],
 'client20' => ['client3', 'client4', 'client8']);


I need to basically get a list of the hash values and display the array 
values for each one.

Thanks for your help!


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




Re: Converting Unix time...

2002-04-02 Thread James Taylor

Look into Time::Local



Daniel Falkenberg wrote:

>G'day all,
>
>What would be the best way of converting Unix time into a ddmmyy format?
>I am a little stuck with this so any ideas would be greatly appriciated.
>
>Dan
>



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




Re: random word from array

2002-03-27 Thread James Taylor

Hrm, try this:

@tea = "Meba", "Shaun", "Mark", "Jason", "Rick", "Dan";
srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
print "$tea[rand(5)]\n";



On Wednesday 27 March 2002 03:25 pm, you wrote:
> I decided to write a little script to help choose who will make the tea on
> our gaming night [there is always an argument!]
>
> I thought I was doing quite well but it seems I am picked on by the
> [non]random script I wrote! It seems to default to the first word in the
> array.
>
> I used rand @array;
>
> I think perhaps that I am thinking about it too simply and perhaps I need
> to involve more math - but I am not good at maths [though I am willing and
> a quick learner...lol] ! so can anyone point me in the right direction?
>
> #!c:/perl/perl.exe
>
> @tea = "Meba", "Shaun", "Mark", "Jason", "Rick", "Dan";
>
> #below is the problem area I think - perhaps rand is not appropriate here?
> #or I haven't phrased it right?
> #I have looked through masses of documentation and faqs but can't find a
> thing.
> #Am I blind or just dim?
>
> $get = rand @tea;
> $who = $tea[$get];
>
> $affirm = "The lucky tea maker is ";
>
> $result = $affirm.$who;
>
> $fail = "Sorry I wasn't listening. Try again!\n";
>
> print "Enter y to see who will make the tea: ";
> $input = ;
> chomp $input;
>
>
> if ($input eq "y") {
>   $a= true;
>   }
>
> if ($a) {print $result
> }
> else
> {
>  print "$fail" };

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




DBI really quick question

2002-03-19 Thread James Taylor

CPAN is running exremely slow (as per usual) and I just have a quick 
question.  How do I CREATE a database from within perl with MySQL? Generally 
the first command you give for DBI will be a statement to connect to a db, 
but what if I have to have the db created first?

This is for a script that will automate the installation of a set of 12 
scripts, and sets up 6 tables, and I don't want to have to tell users to 
first have to run mysql, type in "create database blah", quit, and then run 
the script.

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




Re: what's the point of Foreach?

2002-03-01 Thread James Taylor

Oops, sorry it was just pointed out to me today that this was already asked 
today :) There are over 1000 unread messages in my Perl folder and I didn't 
think to look through them all

On Friday 01 March 2002 11:52 am, you wrote:
> I'm really curious what the point of foreach is considering for does the
> same exact thing? For example:
>
> @myarray = (1 .. 10);
>
> for (@myarray) {
>print "$_\n";
> }
>
>
> Or, you could swap the for for a foreach and the same thing would get
> accomplished...  The only difference I can think of is a slightly different
> handling of hashes.  Is this the only benefit of foreach?  What am I
> missing here

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




what's the point of Foreach?

2002-03-01 Thread James Taylor

I'm really curious what the point of foreach is considering for does the same 
exact thing? For example:

@myarray = (1 .. 10);

for (@myarray) {
   print "$_\n";
}


Or, you could swap the for for a foreach and the same thing would get 
accomplished...  The only difference I can think of is a slightly different 
handling of hashes.  Is this the only benefit of foreach?  What am I missing 
here

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




Fwd: Re: Sending email via Postfix

2002-02-20 Thread James Taylor

Hmm, I'm not 100% sure whether or not it comes with this in Mandrake or not,
but if you download postfix and compile it (or install the package I suppose)
it comes with a binary called 'sendmail' which is basically used for this
purpose.  So, you might want to just do a 'locate sendmail'. Maybe you'll be
lucky

On Wednesday 20 February 2002 02:38 pm, you wrote:
> Hello all,
>
> I have a Mandrake 8.1 box running Postfix.  I have a few CGI's that need to
> send email.  I have always used Sendmail and have been come stumped with
> this line in my script after swtiching to postfix:
>
> # * NAME (AND LOCATION) OF THE SERVER MAIL PROGRAM *
> # Enter the name of your server's mail program.  Most servers are
> # configured with a program called 'sendmail'.  You may, depending on the
> # server settings, have to enter the complete path in addition to the name.
> $mailprog = '/usr/sbin/sendmail';
>
> What should I put here?
>
> All help is appreciated,
> Kevin

---

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




Re: Very Basic Help

2002-02-14 Thread James Taylor

You should probably read about about the CGI module before attempting to 
create CGI programs... BUT, to answer your question, you would do something 
like this:

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

my $test = 1000;

print header;
print start_html;
print "$test\n";
print end_html;

On Thursday 14 February 2002 07:54 am, you wrote:
> Why do I keep getting a premature end of script headers error when I try to
> run this script?  I am going crazy!
>
> #!usr/bin/perl
> #hmres1.pl
> print "Content-type:text/html\n\n";
>
> $test = 100;
>
> print "Test\n";
> print "\n";
> print "$test\n";
> print "\n";
> print "\n";
>
> Thanks,
> Andrew

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




Re: Help can't figure this one out

2002-02-14 Thread James Taylor

Just because you CAN take shortcuts in Perl doesn't necessarily mean that you 
should.  Even though it's less typing, it might be more difficult to 
understand what's going on to someone else reading your code, or to yourself 
after looking at the code some time later.  

That's what I always believed, but that's just me. 

On Thursday 14 February 2002 05:47 am, you wrote:
> > -Original Message-
> > From: Bruce Ambraal [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, February 14, 2002 1:24 AM
> > To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> > Subject: Help can't figure this one out
> >
> >
> > I have written following coding to produce a triangle
> > pattern(see below);
> > I now want to  produce following paterns I can't figer this out
> >
> > ...
> >
> > # indent by printing num_rows - r spaces
> > for ($i = 1; $i <= $num_rows - $r; $i++) {print ("  \n");}
>
> A suggestion: if you want to write Perl programs, you should
> resist the temptation to write them like C programs. This kind
> of thing can be simplified to something like:
>
>print "  \n" for 1 .. ($num_rows - $r);
>
> or better yet:
>
>print "  \n" x ($num_rows - $r);
>
> If you haven't done so already, grab a copy of Schwartz'
> Learning Perl and work through it. That will show you some
> of the idioms that can greatly simplify your programs.
>
> (BTW, are you aware that this statement does not do what the
> comment says it does. You should fix one or the other.)

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




Re: [PHP] Browse and Upload file

2002-02-13 Thread James Taylor

Oh Jesus, I'm on too many mailing lists. Ignore this


On Wednesday 13 February 2002 05:44 pm, you wrote:
> There are scripts like this all over the net, but here's one for you to
> save you searching time:
>
> use CGI qw(:standard);
>
> $| = 1;
> $i=param('fileuploadname');
>
> open(OUTPUT, ">/lists/$i") or die "cannot find output: $!";
>
> while ($bytes = read($i,$buffer,1024)) {
>$bytesread += $bytes;
>print OUTPUT $buffer;
> }
>
> close(OUTPUT);
>
> print header;
> print "\n"
> print "File Uploaded\n"
> print end_html;
>
> of course, the form will call this script in the form action, and
> 'fileuploadname' is the name of the field in your form where they browse to
> a file.  This script doesn't really have any error checking, it's just
> assuming everything works, except for the open statement.
>
> On Wednesday 13 February 2002 05:38 pm, you wrote:
> > Hi,
> > Does anyone know how to upload file using Web Browser as the interface?
> >
> > I want to do a web page, where you can click on a button, and then you
> > can browse the local directories of the person who are browsing the page,
> > and upload a selected file to the web server. Any pointer on how to do
> > that will be greatly appreciated.
> >
> > Thanks.
> > Reuben D. Budiardja

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




Re: [PHP] Browse and Upload file

2002-02-13 Thread James Taylor

There are scripts like this all over the net, but here's one for you to save 
you searching time:

use CGI qw(:standard);

$| = 1;
$i=param('fileuploadname');

open(OUTPUT, ">/lists/$i") or die "cannot find output: $!";

while ($bytes = read($i,$buffer,1024)) {
   $bytesread += $bytes;
   print OUTPUT $buffer;
}

close(OUTPUT);

print header;
print "\n"
print "File Uploaded\n"
print end_html;

of course, the form will call this script in the form action, and 
'fileuploadname' is the name of the field in your form where they browse to a 
file.  This script doesn't really have any error checking, it's just assuming 
everything works, except for the open statement.


On Wednesday 13 February 2002 05:38 pm, you wrote:
> Hi,
> Does anyone know how to upload file using Web Browser as the interface?
>
> I want to do a web page, where you can click on a button, and then you can
> browse the local directories of the person who are browsing the page, and
> upload a selected file to the web server. Any pointer on how to do that
> will be greatly appreciated.
>
> Thanks.
> Reuben D. Budiardja

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




Re: foreach loop problems

2002-02-13 Thread James Taylor

Ha, Ok well that was interesting.  I ran this script on a different machine 
and it works fine... Weird. 
So, nevermind :) 

On Wednesday 13 February 2002 03:35 pm, you wrote:
> I'm curious how you got this script to work, I re-wrote his with something
> like this:
>
> my @hosts = ("1.com", "2.com", "3.com", "4.com");
>
> foreach my $key (@hosts) {
>system("ssh -l @ARGV[0] $key");
> }
>
> and it will SSH to 1.com ONLY.  After the session with 1.com is ended, it
> doesn't continue on to 2.com, or 3.com, etc.   What's wrong here?
>
> On Wednesday 13 February 2002 03:21 pm, you wrote:
> > I was actually surprised to see that ssh worked like this!  I don't
> > think you can always get away with it, but I just tested it out and was
> > able to call up ssh for 4 different machines using a script similar to
> > that one.  I don't think all programs are going to be that nice.
> >
> > Can anyone explain how ssh got the keyboard input?!  Doesn't perl have
> > control of  or does it pass that off to the spawned process
> > during a call to 'system'?
> >
> > - Johnathan
> >
> > James Taylor wrote:
> > >I don't believe this is what he's asking - What the problem is in this
> > > code is that after the first instance of SSH runs, and then exits, it
> > > will not continue on to the next key in the array.
> > >
> > >I can't figure out why it won't do it, I don't generally write programs
> > > using system calls :)

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




Re: foreach loop problems

2002-02-13 Thread James Taylor

I'm curious how you got this script to work, I re-wrote his with something 
like this:

my @hosts = ("1.com", "2.com", "3.com", "4.com");

foreach my $key (@hosts) {
   system("ssh -l @ARGV[0] $key");
}

and it will SSH to 1.com ONLY.  After the session with 1.com is ended, it 
doesn't continue on to 2.com, or 3.com, etc.   What's wrong here?


On Wednesday 13 February 2002 03:21 pm, you wrote:
> I was actually surprised to see that ssh worked like this!  I don't
> think you can always get away with it, but I just tested it out and was
> able to call up ssh for 4 different machines using a script similar to
> that one.  I don't think all programs are going to be that nice.
>
> Can anyone explain how ssh got the keyboard input?!  Doesn't perl have
> control of  or does it pass that off to the spawned process
> during a call to 'system'?
>
> - Johnathan
>
> James Taylor wrote:
> >I don't believe this is what he's asking - What the problem is in this
> > code is that after the first instance of SSH runs, and then exits, it
> > will not continue on to the next key in the array.
> >
> >I can't figure out why it won't do it, I don't generally write programs
> > using system calls :)

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




Re: foreach loop problems

2002-02-13 Thread James Taylor

I don't believe this is what he's asking - What the problem is in this code 
is that after the first instance of SSH runs, and then exits, it will not 
continue on to the next key in the array.

I can't figure out why it won't do it, I don't generally write programs using 
system calls :) 

On Wednesday 13 February 2002 02:58 pm, you wrote:
> # Create array @hosts...  So far so good.
> my @hosts=qw( lunar solar venus mars saturn pluto );
>
> # \@hosts creates a reference to @hosts.  You just want @hosts.
> #
> # The way you've written it, the elements in @hosts will be
> # assigned to the special variable $_.  This is all right, but
> # tends to get confusing, especially for non-veterans.  It may
> # even cause problems down the line if you forget you are
> # already using $_ and nest another loop that uses it.  Instead
> # try declaring your variable as I show below.
> #
> # Also foreach -> for.  I think it reads better.
> #
> for my $host (@hosts) {
> # system("/usr/bin/ssh @hosts $ARGV[0]");
> # @hosts is still the array.  You want $_ or $host, see above.
> system("/usr/bin/ssh $host $ARGV[0]");
> }
>
> dan radom wrote:
> >Hi,
> >
> >
> >I've got a problem with the following code...
> >
> >my @hosts=qw( lunar solar venus mars saturn pluto );
> >
> >foreach (\@hosts) {
> >system("/usr/bin/ssh @hosts $ARGV[0]");
> >}
> >
> >
> >
> >What I'm wanting to do is call foo.pl uname (for example) and have the
> > script ssh host uname for each host defined in the @hosts array.  What's
> > currently happening is that it does ssh lunar solar and dies trying to
> > execute the next @hosts as the ssh commend.  Any ideas?
> >
> >dan

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