Re: How to pass string in command line argument.

2006-10-26 Thread Mumia W.

On 10/26/2006 05:47 AM, perl pra wrote:

hi ,

I want to pass a command argument to perl script with double quotes ( );


below is my scenario

my xml file is something like this ..


root

reff
   var1123/var1
var2this is my name/var2
/reff
reff
   var1234/var1
var2this is others name /var2
/reff
/root

my perl script is something like this



my $xmlfile = ./samp1.xml;
my $ref = eval { XMLin($xmlfile) };

if ($@){

   print XML Read ERROR;

} else {

foreach my $item (@{$ref-{reff}}) {

system(perl C:\\Document and settings\\Desktop\\search.pl -n
\$item-{var2}\);

the search.pl file consists of .

print AGRV[1];



my out put is

this is my name

this is others name



i understand that the string is getting passed to the perl script with out
quotes ..



just a straight string is geeting passed (like this  this is my name)

but i need to send the entire string including  double quotes to the
script.,something like this ( this is my name)

Waiting for your solutions

thanks in advance

perl guy




Under Linux, you could separate the arguments in the system() call, like so:

system('perl','C:\\Document and settings\\Desktop\\search.pl',
 '-n', '' . $item-{var2} . '');

Obviously, you're not running under Linux, so try this:

system(qq{perl C:\\Documents and Settings\\Desktop\\search.pl -n 
\\$item-{var2}\\});


I'm unsure of how many backslashes you need to escape those quotes.



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




Re: Is that I can do something like that ?

2006-10-25 Thread Mumia W.

On 10/25/2006 06:12 AM, Mug wrote:

Hi all,

I don't know if that anyway I can know what should I pass back
from right hand side to left hand side, like :

my $x = qw/a b c d e / ; # so I have $x = 5
my ($x) = qw / a b c d e / ; # then I have 'a'

or like

$data = F ; # reads 1 line from file;
@data = F ; # reads all line from the file

I actually want to write a piece of code like that :

my %u_info = user_detail ( $ENV{QUERY_STRING} );
# I have $u_info{id} = 'foo' , $u_info{pass} = 12345

my @attribs = user_detail ( $ENV{QUERY_STRING} );
# I have @attribs = ( 'foo', 12345 );

while I am asking %u_info , the user_detail will return a hash ,
and while I am asking @attribs, I got an array return.

Just note, I don't want to pass / ask reference.

Any pointers ? Thanks!


regards,
mug






Let your user_detail subroutine build up a hash within itself and return 
that hash.


sub user_detail {
   my %hash;
   ... stuff ...
   $hash{id} = '...';
   $hash{pass} = '';
   return %hash;
}




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




Re: Spam from this list

2006-10-25 Thread Mumia W.

On 10/25/2006 06:45 AM, Ron Goral wrote:

Is anyone else receiving spam from this list? I use this email address only
for this list, so it must be originating from someone on it. Any ideas?





Spammers harvest e-mail addresses from mailing lists and their archives. 
If this list is archived on the web, spammers can and will grab the 
e-mail addresses and spam them.





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




Re: tracing Subroutine ** redefined at warnings

2006-10-20 Thread Mumia W.

On 10/20/2006 06:35 AM, Ramprasad A Padmanabhan wrote:

I am getting warnings like ( when I run perl -wc )

Subroutine foo redefined at  bar.pm.
I am sure these functions are not redefined anywhere. I would like to 
trace the source of these warnings.


How do I do this.
BTW I am using perl 5.8.3 on linux


Thanks
Ram



If you load a perl module with do (do 'mymodule.pm') rather than use 
(use mymodule) then this can happen.


Look into the Carp module.


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




Re: RREAD CONSECUTIVE LINES

2006-10-20 Thread Mumia W.

On 10/20/2006 07:16 AM, Luba Pardo wrote:

Dear all,
I am trying to write a script that reads in two or three consecutive lines
to process those. [...]


Do you want to show some sample data? Do you want to show what the input 
data is supposed to look like and what the output is supposed to look like?




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




Re: Where are These Carriage Returns Coming From?

2006-10-20 Thread Mumia W.

On 10/20/2006 05:35 AM, Xavier Noria wrote:

On Oct 20, 2006, at 11:54 AM, Chris Share wrote:

In the output of the following code there's a carriage return between 
the $name variable and the !. Where is this coming from? Doesn't the 
chomp get rid of this?

[...]


Looks like CGI.pm puts STDIN in binmode on Windows:

  $needs_binmode = $OS=~/^(WINDOWS|DOS|OS2|MSWin|CYGWIN)/;
  # ...
  if ($needs_binmode) {
$CGI::DefaultClass-binmode(\*main::STDOUT);
$CGI::DefaultClass-binmode(\*main::STDIN);
$CGI::DefaultClass-binmode(\*main::STDERR);
  }

If that is correct the CRLF - LF translation of the I/O layer is 
disabled and chomp does not remove CR (because $/ is \n by default). 
Once you see why it is working that way I guess you can change your code 
accordingly.


-- fxn



IOW, Chris would set $/ to \r\n before performing the chomp.



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




Re: remote login using perl

2006-10-19 Thread Mumia W.

On 10/19/2006 01:11 AM, Sayed, Irfan (Irfan) wrote:

I need to login on remote machine which is windows , and i think windows
doesent support ssh login unless ssh server installed.
 
Either i have to use VNC , remote desktop shairing etc.
 
I need to automate this using script.
 
Please help.
 
Regards

Irfan.
 
 [ rest of TOFU snipped ]


Bottom-posting is a much better way to get responses than top-posting. 
To bottom-post, place your reply beneath the other person's quoted text.


Go to http://search.cpan.org/ and search for remote.


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




Re: Plz HELP

2006-10-18 Thread Mumia W.

On 10/18/2006 12:14 AM, Dharshana Eswaran wrote:

Hi All,

I am a student who is working on Perl on my project.

I am a beginner in Perl.

I know how to read the data from files into a variable or array. I mean, i
know to read the data line by line into a varaiable or teh full file
contents into an array.

But, i have stored few hex bytes in the file and i need to read a pair of
character one by one which is seperated using spaces.
For eg:
The file contents are stored in the following fashion,
00 01 a0 ab 55 76 ff cb etc

How should i read number by number?

Thanks and Regards,
Dharshana



Option 1: Remove the spaces and use the pack function (documentation: 
perldoc -f pack)


Option 2: Use the substitution operator and the hex() function 
(documentation: perldoc perlop and perldoc -f hex)


Options 3-65535: ?



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




Re: .wav and mp3 length.

2006-10-14 Thread Mumia W.

On 10/14/2006 09:14 AM, Sara wrote:

Need to determine the .wav and mp3 file length not in bits or bytes, but in 
minutes.

It's for a dictation recording service who needs to invoice the clients as per 
the minutes of files uploaded to their servers.

I searched the CPAN but of no help.

Thanks,
Sara.




The CPAN shell says that there are from 50-100 modules that deal with 
either WAV or MP3 files.



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




Re: Automatied downloads

2006-10-14 Thread Mumia W.

On 10/14/2006 06:05 AM, Mike Blezien wrote:

Hello,



Hello


[ php script snipped ]
###

I've been trying to convert this to a Perl script with not much luck. 
Was hoping to get some tips on how to convert this to Perl or a similar 
method using Perl so when the link is clicked on, the file will be 
automatically downloaded instead of clicking on the link to do a Save As.




Can you show us your Perl program for doing this?


Most likely it's just a matter of setting the Content-Disposition the 
way you did before.



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




Re: if you use a module does this happen?

2006-10-14 Thread Mumia W.

On 10/14/2006 12:03 PM, Jesse Engel wrote:

[...]
when i would call $ftp-rget() i would get an error that said basically there 
is no rget method
with net::ftp.
so my question is this: by using net::ftp::recursive, do you get all of the methods 
[...]



Read the documentation for Net::FTP::Recursive to find out what methods 
are there.




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




Re: Automatied downloads

2006-10-14 Thread Mumia W.

On 10/14/2006 02:57 PM, Mike Blezien wrote:

Hello,
- Original Message - From: Mumia W. 
[EMAIL PROTECTED]

To: Beginners List beginners@perl.org
Sent: Saturday, October 14, 2006 12:09 PM
Subject: Re: Automatied downloads



On 10/14/2006 06:05 AM, Mike Blezien wrote:

Hello,



Hello


[ php script snipped ]
###

I've been trying to convert this to a Perl script with not much luck. 
Was hoping to get some tips on how to convert this to Perl or a 
similar method using Perl so when the link is clicked on, the file 
will be automatically downloaded instead of clicking on the link to 
do a Save As.




Can you show us your Perl program for doing this?


Most likely it's just a matter of setting the Content-Disposition the 
way you did before.


This is what I've come up with so far, not tested yet tho:
# code snip


Why not test it?


[...]
# Not sure if this should be a 'inline' or 'attachement' here
print header(-type='application/octet-stream', 
'Content-Disposition'=inline; filename=$original_file);

[...]


Why not try it one way and if that doesn't work, try it the other way?



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




Re: consecutive lines in a file

2006-10-13 Thread Mumia W.

On 10/13/2006 07:57 AM, Luba Pardo wrote:

Dear sir/madam:
I am trying to write a script to process to consecutive lines at a time and
compare elements of between two consecutive lines.


I don't understand this sentence.



I tried something like:
$i=0;
while (IN){
chomp;
@a1_s= split/\/, $_{$I];
@a2_s= split/\/,$_[$i+1];

if ($a1_s[1] =~ /HG-Stats_gi1/){

@temp  = split//, $a1_s[1];
@temp1 = split//, $a2_s[1];

 print  line is $i, array is @a1_s, array 2 es @a2_s\n;
}
$i++;

}

close IN;

but it does not work. I guess the $_[$i] and $_[$i+1] does not work, but I
do not exactly how.



This is another slightly confusing sentence. I hope you mean that, using 
$_[$i] and $_[$i+1] does not work, and you don't know how to get it to work.


The answer would be to use Tie::File to make your file look like an 
array. If you are using ActiveState Perl on Windows, start a command

prompt and type perldoc Tie::File


Could anyone give any idea why?

Thanks in advance



Luba Pardo



You're welcome.



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




Re: http to https

2006-10-13 Thread Mumia W.

On 10/13/2006 11:50 AM, Andrew Kennard wrote:

Hello all

We have recently moved to a new hosting company that also provides us with 
an SSL service.


The scenario:

I have a form located at url http://www.mydomain.co.uk/myfolder/page1.htm 
which on submission, uses a sub routine that opens the file that is being 
passed to it (a .htm file - the 'next page'), reads it into an array and 
prints it back out.


However, the 'next page' is located at url 
https://www.mydomain.co.uk/myfolder/nextpage.htm


Currently all that happens is that I get a blank white screen instead of the 
'next page', knowing that if I were to paste the url 
(https://www.mydomain.co.uk/myfolder/nextpage.htm) into the internet browser 
it definitely appears!!


Any help or advice much appreciated.

Kind regards

Seaman



I'm confused about what you want, and I also think you're confused about 
what you want. If nextpage.htm already exists, then you don't need to 
read in in from the form on page1.htm; you would just redirect to it or 
read it and output it.


A page that contains a form (e.g. page1.htm) posts (*) that form to a 
CGI script that will process it (e.g. page2.cgi). The the script can 
either output the data itself or redirect to the page that has the 
correct data.



--
(*) a simplification


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




Re: nice regular expression

2006-10-13 Thread Mumia W.

On 10/13/2006 12:14 PM, I.B. wrote:

this is the problem:

use regular expressions to prove that word Bug
is in the 3 row from the end of table in the html tagged file:

shell cat file1.txt
[...]


Don't use regular expressions to parse HTML. Use an HTML parsing module 
to parse HTML.


Now to answer your next questions:

Where can I find an HTML parsing module?
http://search.cpan.org/

Why is parsing with HTML::Parser so complicated?
It's because HTML is very complicated.




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




Re: Subroutine returning 2 arrays

2006-10-12 Thread Mumia W.

On 10/12/2006 10:55 AM, Gallagher, Tim F (NE) wrote:

From a subroutine I would like to return 2 separate arrays like this
 
sub TEST

{
 @a = (a1,a2,a3,a4,a5,a6,a7);
 @b = (b1,b2,b3,b4,b5,b6,b7);
 return (@a, @b);
}
 
my(@lala,@baba) = TEST;

print @lala;
 
 
The problem is that @lala will return a1a2a3a4a5a6a7b1b2b3b4b5b6b7 and

@baba will return nothing. How can I return 2 arrays and have the info
look like this:
print @lala would return a1a2a3a4a5a6a7
print @baba would return b1b2b3b4b5b6b7
 [...]


Return references to the arrays:

sub TEST {
  my @a = (a1,a2,a3,a4,a5,a6,a7);
  my @b = (b1,b2,b3,b4,b5,b6,b7);
  return ([EMAIL PROTECTED], [EMAIL PROTECTED]);
}

my ($aref, $bref) = TEST();
print A array: @$aref\n;
print B array: @$bref\n;

Read the docs:
perldoc perlreftut
perldoc perllol



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




Re: Subroutine returning 2 arrays

2006-10-12 Thread Mumia W.

On 10/12/2006 11:23 AM, Moon, John wrote:

-Original Message-
From: Gallagher, Tim F (NE) [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 12, 2006 11:55 AM

To: Perl Beginners
Subject: Subroutine returning 2 arrays


From a subroutine I would like to return 2 separate arrays like this
 
sub TEST

{
 @a = (a1,a2,a3,a4,a5,a6,a7);
 @b = (b1,b2,b3,b4,b5,b6,b7);
 return (@a, @b);
}
 
my(@lala,@baba) = TEST;

print @lala;
 
 
The problem is that @lala will return a1a2a3a4a5a6a7b1b2b3b4b5b6b7 and

@baba will return nothing. How can I return 2 arrays and have the info
look like this:
print @lala would return a1a2a3a4a5a6a7
print @baba would return b1b2b3b4b5b6b7
 
Please try... 
sub TEST {

...
return ([EMAIL PROTECTED],[EMAIL PROTECTED])
...
}
my ($lala, $baba) = TEST;
print join(',', @$lala); 


Hope this helps...

jwm



Mr. Moon, I can't tell what you wrote and what the person you're 
responding to wrote. Please install OE-quotefix (or Outlook-quotefix) to 
improve the quoting style of your posts.


http://search.yahoo.com/search?p=oe+quotefix



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




Re: Modules for printing the content of an array

2006-10-11 Thread Mumia W.

On 10/11/2006 10:42 AM, Sami FANTAR wrote:

[...]
I have read the Data::Dumper related doc.


Including the part where it tells you how to substitute the correct 
variable names for $VAR1,$VAR2,... ?



But, after having written your example, the output seems quite weird.
I got $VAR1,$VAR2, and so on.
Is it possible to personalize this output?



use Data::Dumper;
my @myarray = qw(blah blahblah blllah);
print Data::Dumper-Dump([EMAIL PROTECTED],[qw(myarray)]);

WARNING: UNTESTED CODE


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




Re: Including a file with common variables...

2006-10-08 Thread Mumia W.

On 10/08/2006 12:15 PM, Shawn Hinchy wrote:


Thank you Mumia and Ovid.  I appreciate both of your responses.  I agree 
with you Ovid, you make some very good points.  The point I forgot to 
include is that these variables are actually configuration-type 
constants.  I misnamed them by calling them variables.

[...]


If you want to put some constants in a module, one of the many options 
is to use the constant and Exporter modules like so:


# file: AppConstans.pm
use strict;
use warnings;
package AppConstants;
use base 'Exporter';
use constant DB_HOST = 'my.host.example.com';
use constant DB_USER = 'my_user';
use constant DB_PASS = 'my_pass';
use constant LIST_OPTIONS = {
recursive = 1,
classes = 'd,s',
};

our @EXPORT = qw(DB_HOST DB_USER DB_PASS LIST_OPTIONS);

1;

__END__


In your main program you might do this:

use AppConstants;
...
my $dsn = DBI:mysql:database=mydb;hostname= . DB_HOST;
my $dbh = DBI-connect($dsn, DB_USER, DB_PASS);
...

Here is some useful documentation:
perldoc constant
perldoc Exporter
perldoc base
perldoc perlmod

P.S.
It's usually best to not export things by default, but I decided to make 
this example simple.



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




Re: Large DBI query filling up memory

2006-10-07 Thread Mumia W.

On 10/07/2006 04:11 AM, Robin Sheat wrote:

I have the following to open a database:

my $dbh = DBI-connect(DBI:$dbconn, $dbuser, $dbpass) or
die Couldn't connect to db $dbconn: . DBI-errstr;

and then later I'm doing:

my $query=select user_id, preference from $opt{table};
$sth = $dbh-prepare($query);
print Executing query\n;
$sth-execute();
print Executed\n;

this query will return (literally) millions of rows. More than can fit into 
memory. When the execute() method is called, it seems to want to put all the 
data into RAM, which causes issues. I've tried playing with 
$dbh-{RowCacheSize}, but it seems to be ignored. I'm using the MySQL driver.


Is this expected behaviour, and what can I do about it?



Use a LIMIT clause to restrict the number of records that are returned, 
e.g.:


SELECT id, first_name from users LIMIT 100, 200;

...returns records 100 through 200 of the results.

You would use LIMIT to process the data page by page.



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




Re: Cleaning smart quotes, etc from data pasted to a form

2006-10-05 Thread Mumia W.

On 10/05/2006 08:47 AM, Kevin Old wrote:

Hello everyone,

I have a set of web based admin tools that users in my company use to
update various pieces of a website.  I've never been able to write
enough regexes, clean routines, etc. to clean out all of the bad
characters that users put in.  The big culprit is of course, good ole
cut and paste.

Like I said, I have several sanitize routines that clean control
characters, etc. out of the input fields.  Just wondering if others
have found the solution for stuff like this.

Thanks for any help,
Kevin


Perhaps you could look at the problem in reverse. Strip out all 
characters that are not in a certain set; e.g., you might take anything 
that is not a digit, space, tab, alphanumeric character, period, or 
comma and delete it.




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




Re: Cleaning smart quotes, etc from data pasted to a form

2006-10-05 Thread Mumia W.

On 10/05/2006 09:48 AM, Chad Perrin wrote:

On Thu, Oct 05, 2006 at 09:06:11AM -0500, Mumia W. wrote:

On 10/05/2006 08:47 AM, Kevin Old wrote:

Hello everyone,

I have a set of web based admin tools that users in my company use to
update various pieces of a website.  I've never been able to write
enough regexes, clean routines, etc. to clean out all of the bad
characters that users put in.  The big culprit is of course, good ole
cut and paste.

Like I said, I have several sanitize routines that clean control
characters, etc. out of the input fields.  Just wondering if others
have found the solution for stuff like this.
Perhaps you could look at the problem in reverse. Strip out all 
characters that are not in a certain set; e.g., you might take anything 
that is not a digit, space, tab, alphanumeric character, period, or 
comma and delete it.


That won't work so well for characters that are garbage versions of good
characters that are actually needed.  Generally, quotes are there for a
reason, for instance -- so just throwing away smart quotes rather than
replacing them with standard vertical ASCII quotes might not be
desirable.



You're right and figuring out what is truly garbage and what are garbled 
bytes that need to be converted is not trivial. Maybe there's a module 
on CPAN...





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




Re: an easy way to know if a module is installed or not

2006-10-05 Thread Mumia W.

On 10/05/2006 11:34 AM, Johnson, Reginald (GTI) wrote:

To piggy back off of this question... Is there a way to just list out
the modules you have installed?



Make sure that perldoc is installed on your system and do this at a 
command prompt:


perldoc -q installed


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




Re: Can't get Sudo.pm to run my command but it works from a prompt

2006-10-05 Thread Mumia W.

On 10/05/2006 03:23 PM, RICHARD FERNANDEZ wrote:
if the user has never signed in and the admin never ran 
passwd user passwd -f user and then that user never went into 
make his/her password permenant then yes it would matter b/c 
the passwd is not set.





I've gone in and set a passwd for the user. Then I actually logged in as
the user for grins.
Still no good. And, BTW, I'm restarting the webserver after every change
to the user to make sure the environment is what I think it is.

If a missing passwd was the issue, it should not have worked from the
command line either, or am I missing something?



Does the webserver have the proper permissions to invoke that sudo entry?



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




Re: Can't get Sudo.pm to run my command but it works from a prompt

2006-10-05 Thread Mumia W.

On 10/05/2006 07:10 PM, RICHARD FERNANDEZ wrote:
 

From: Mumia W. [mailto:[EMAIL PROTECTED] 


Does the webserver have the proper permissions to invoke that sudo

entry?

AFAIK, yes. I don't think it would be asking for a password if it
couldn't run the binary. It just doesn't seem to be pulling the right
entry (webuser) out of the sudoers file, even though it's running as
webuser. I don't know what else I should be checking...

As a test, I temporarily replaced the call to Sudo.pm with a
system(/usr/local/bin/sudo...) and it failed the same way. Hmmm. Works
from the command line. Doesn't work from cgi-bin.

Looks like this may not, strictly speaking, be a Perl question any more,
but can anyone point me in the right direction?
I can definitely run things out of cgi-bin, otherwise I wouldn't have
gotten this far.

Thanks again!
richf 



Go into sudoers and replace the name of the binary with the name of a
script that echoes the real and effective user and group ids.




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




Re: Dumping all vars

2006-10-03 Thread Mumia W.

On 10/03/2006 09:19 PM, J. Alejandro Ceballos Z. -JOAL- wrote:


The variables created during a cgi, are stored in some kind of hash, 
like the %ENV enviroment variables?


I want to create in some points, a var dump of all variables existed, in 
order to track errors.




Perhaps the Data::Dumper module will help you.


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




Re: Smart assignment

2006-10-03 Thread Mumia W.

On 10/03/2006 11:37 AM, Derek B. Smith wrote:

returns true or false (1 or '') and in list
context it returns the
contents of any capturing parentheses in the
pattern.

The expression:

( $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i
)[ 0 ]

is a list slice so the regular expression is in list
context but the slice is
a single value so the expression is a scalar.

The || operator will only work with scalar values,
not with lists, so this
works because the list has been converted to a
scalar with the list slice.




John



the list context represents everything between the / /
and the slice context represents [ 0 ] which is
assigned as a scalar to $ptypeline.

Correct?
[...]


No, $ptypeline is the string that is being searched.




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




Re: Smart assignment

2006-10-02 Thread Mumia W.

On 10/02/2006 01:54 PM, Rob Dixon wrote:

Bryan R Harris wrote:


**
$ptypeline = #movableortProjortho0.0000.000;

($ptype) = ($ptypeline =~ /movable.+(sine|geo|radial|ortho)/i) || 
(missing);


print $ptype, \n;
**


The above code prints 1, where I want it to print ortho.  Is that
possible?

(Preferably in one line, since I'm a *big* fan of perl golf.  =)


$ptype = $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i ? $1 : 
(missing);


Rob



Yes, and here is another way:

$ptype = (($ptypeline =~ /movable.+(sine|geo|radial|ortho)/i)[0]) || 
'(missing)';




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




Re: Problem dynamically sign array a name

2006-09-29 Thread Mumia W.

On 09/29/2006 11:49 AM, Shiping Wang wrote:
Hi, I have a big array, I need re-arrange it then put into sub array, 
after that do something on each sub array. I have a problem to 
dynamically give sub array a name. Any help? Maybe I should use 
anonymous array?


Thanks,

Shiping

Here is my code:

use strict;
use warnings;

my @big_arr = ( 
0.06,0.04,0.98,0.12,0.02,0.98,0.11,0.25,0.36,0.01,0.01,0.01,0.02,0.01,0.05,0.056, 
0.046, 0.98, 0.12, 
0.002,0.06,0.04,0.98,0.12,0.02,0.98,0.11,0.25,0.36,0.01,0.01,0.01,0.02,0.01,0.05,0.056, 
0.046, 0.98, 0.12, 
0.002,0.06,0.04,0.98,0.12,0.02,0.98,0.11,0.25,0.36,0.01,0.01,0.01,0.02,0.01,0.05,0.056, 
0.046);


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

my @q_$i = ($P_array[$i], @P_array[8*$i+10 .. 8*$i+17]);

for (@q_$i){
print join \t, @_$i, \n;
}
}




Create an anonymous array and put it into a hash. Read perldoc perldsc

E.g.
my %q;
...
$q{$i} = [ ($P_array[$i], @P_array[8*$i+10 .. 8*$i+17]) ];
...
print join(\t, @{$q{$i}}), \n;
...


WARNING: UNTESTED CODE



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




Re: interpoliation within regexp

2006-09-29 Thread Mumia W.

On 09/29/2006 12:15 PM, Derek B. Smith wrote:

--- D. Bolliger [EMAIL PROTECTED] wrote:


Derek B. Smith am Donnerstag, 28. September 2006
22:28:

Why not just specify a non-digit for the first
character:

my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');

my $password = join '', $a[ 10 + rand( @a - 10 )

],

map $a[ rand @a ], 1 .. 5;



John

Ok great, but I do not fully understand this. Will

you

explain in English?

Join with '':
a) a randomly selected entry from @a excluding the
digits
   at positions 0..9 [the part between the 1st and 
   2nd comma]

b) five randomly selected entries from @a
   [the map part]

Note: @a is used in scalar context both times,
meaning the number of entries 
in @a.


perldoc -f map
perldoc -f join
perldoc -f rand


My tip for cases where you get a working solution
you don't understand fully:
a) Try to find out what belongs together (imagine
'()'s)
b) Try to break the solution apart according to the
findings in a)
c) examine the parts: print them out, dump them with
Data::Dumper, modify
   them, read the man pages
d) put them together again, eventually one by one
part, using examination 
   techniques as in c)



Hope this helps!

Dani


I reread the docs and I am still unclear with the
code:
$a[ 10 + rand( @a - 10 )
I do understand everything but $a[ 10 + rand( @a - 10
)

b/c you say subtract 10 from each element occurrance
= @a - 10 then add 10 to the result of rand (@a - 10)
To me this is offsets itself which is why I am
confused. Will you explain again?
I think you missed an explanation step between a and
b?

Reagardless it work so thank you.




Does this slice help demonstrate it?

my @a = (0..9,'a'..'z','A'..'Z');
my @b = @[EMAIL PROTECTED];
print @a, \n;
print @b, \n;

# OUTPUT:
#0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ
#

BTW, placing print statements in the right places is a great way to 
learn how someone's program works. Anyway, I hope this is easier to digest:


my @a = (0..9,'a'..'z','A'..'Z');
my @b = @[EMAIL PROTECTED];

my $password = $b[int rand (@b)];
$password .= join '', map $a[int rand (@a)], (1..5);
print $password, \n;

__HTH__


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




Re: interpoliation within regexp

2006-09-29 Thread Mumia W.

On 09/29/2006 01:44 PM, Rob Dixon wrote:

Derek B. Smith wrote:

--- Mumia W. [EMAIL PROTECTED]
wrote:


What is the purpose of this program?


To generate a random 6 character string.
 
If the first character starts with a # then I just

ignore the new string and tell it to goto LABLE, b/c
for 0-32 on the ASCII table cannot be used as a 1st
character in a user password.

## generate random 8 char password.
PASSWD: my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');
my $password = join '', map { $a[int rand @a] } 0 ..
5;

#if first char is a-z then print it else warn
#chop string into individual characters

my @chars  = unpack (A1 x length($password),
$password);
if ($chars[0] =~ /^\D/) {
  print Your new password is:\t,@chars,\n;
}
else {
  #print string starts with number:\t,@chars,
\trestarting\n;
  #substr($chars[0],0,1) =~ s/$chars[0]/chr ($1)/e);
## execute with regexp substitute ?/?   goto PASSWD;
}


This will do what you want. It shuffles all of the possible characters 
and joins
them into a string, and then finds the first substring of six characters 
that
starts with a non-numeric character. The only proviso is that a password 
can
never have the same character twice, which isn't true of the general 
solution.


  use List::Util qw/shuffle/;

  my $chars = join '', shuffle (0..9, 'a'..'z', 'A'..'Z');
  my ($password) = $a =~ /(\D.)/;

HTH,

Rob



Aren't you concerned that this is random in a completely wrong way? Only 
one of each character can appear in the password, and that's kind of weak.


It's also a /very/ minor issue that you assign to $chars but then use $a 
after; the main problem is that this password generating algorithm is 
that it is, to steal a phrase from Lo Wang, weaker than a baby's 
[passing gas].


:-)




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




Re: using local when appropriate

2006-09-29 Thread Mumia W.

On 09/29/2006 01:28 PM, Charles K. Clarkson wrote:

Derek B. Smith wrote:

: ## Below is better pratice ##
: 
: sub getfile {

:  my $filename = shift;
:  open F,  $filename or die open failed  $!
:  my $contents;
:  { local $/ = undef;  # Read entire file at once
:$contents = F;   # Return file as one line
:  }
:  close F;
:  return $contents;
: }
: 
: 
: I read an excerpt from

: http://perl.plover.com/local.html#2_Localized_Filehandles

Curiously, you do not actually localize the file
handle in getfile().

 
: and was wondering if this holds true regarding

: localizing $/ and setting it to undef in Perl 5.8.x?

If you do not localize the $/ operator then you will
change it for the rest of the script. That might be a
problem for other I/O operations which fail to set it.

In 5.8.x this function might better be written like
this, but I lack the experience to call it a best
practice.

sub slurp_file {

# open file for read or die
my $file = shift;
open my $fh, '', $file or die qq(Cannot open $file: $!);

# slurp file
local $/ = undef;

# return file as scalar
return $fh;
}


HTH,

Charles K. Clarkson


Uri Guttman has already written File::Slurp:

my $slurped = read_file 'mylogfile.log'

I use this module quite frequently. Thanks Uri.


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




Re: Problem dynamically sign array a name

2006-09-29 Thread Mumia W.

On 09/29/2006 02:24 PM, Shiping Wang wrote:

Hi Charles,

At 13:08 2006-9-29, Charles K. Clarkson wrote:

Shiping Wang wrote:

: Hi, I have a big array, I need re-arrange it then put into sub
: array, after that do something on each sub array.

How do you want to split it into sub arrays? Like items,
number of items, random items, ...?

: Here is my code:
[snip]

It is really hard to tell what you are attempting. We don't
know what is in @P_array, for example, because it is never defined
and @q_$i isn't a valid perl variable name. Working code would be
better.

Tell us what you want to do to the big array.


Here is my real working code:

use strict;
use warnings;

# actually this array has 90 elements, I cut it for short. I have 
several thousands of this kind of arrays.

=pod
the way I need re-arrange in this way:
array0: 0, 10..17
array1: 1, 18..25
array2: 2, 26..33
...
...
array9: 9, 82..89
=cut [...]


Use splice() to suck off eight elements at a time. Put the elements into 
an anonymous array and put that array into a hash.


use strict;
use warnings;
my @P_array = ( 
0.06,0.04,0.98,0.12,0.02,0.98,0.11,0.25,0.36,0.01,0.01,0.01,0.02,0.01,0.05,0.056, 
0.046, 0.98, 0.12, 
0.002,0.06,0.04,0.98,0.12,0.02,0.98,0.11,0.25,0.36,0.01,0.01,0.01,0.02,0.01,0.05,0.056, 
0.046, 0.98, 0.12, 
0.002,0.06,0.04,0.98,0.12,0.02,0.98,0.11,0.25,0.36,0.01,0.01,0.01,0.02,0.01,0.05,0.056, 
0.046, 0.90);


my %q;

my @pcopy = @P_array;
my $count = 0;
while (my @part = splice(@pcopy, 0, 8)) {
$q{$count++} = [ @part ];
}
my $numeric = sub { $a = $b };
printf %2d: [EMAIL PROTECTED], $_ for (sort $numeric keys %q);


__HTH__



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




Re: question about web site interaction script

2006-09-29 Thread Mumia W.

On 09/29/2006 04:08 PM, Alexander Sirotkin wrote:

What is the best module to use when writing web site interaction scripts ?

The script would have to login sending username and password and after
that follow a few links and do some more http posts.

Any suggestions ?

Thanks



WWW::Mechanize



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




Re: interpoliation within regexp

2006-09-28 Thread Mumia W.

On 09/28/2006 08:16 AM, Derek B. Smith wrote:

--- Derek B. Smith [EMAIL PROTECTED]
wrote:


I need to substitute a conversion using chr, but
have
failed on multiple attempts.  Basically if the first
element contains a # then convert it. Will anyone
advise?

thank you
derek

#if first char is a-z then print it else warn
#chop string into individual characters

my @chars  = unpack
(A1 x length($password),$password);

if ($chars[0] =~ /^\D/) {
  print Your new string is:\t,@chars,\n;
}
else {
  print string starts with number, now
converting\n,
@chars, \n;
  substr($chars[0],0,1) =~
s/\Q{$chars[0]}/{chr($chars[0]}\E/;
  print @chars;
}



I will try to use the /e modifier as such:

s/(\$\w+)/$1/e;

An explanation is below:
/e
 Righthand side of a s/// is code to eval
 
/ee

 Righthand side of a s/// is a string to eval, then
run as code, and its return value eval'led again.
 



What does your input data look like, and what do you want the output to 
look like?




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




Re: interpoliation within regexp

2006-09-28 Thread Mumia W.

On 09/28/2006 12:04 PM, Derek B. Smith wrote:

**
The input data is a 6 character randomized string that
could start with a # such as 6FhJ9Z.  If it does start
with a number then I need to convert this character
into its cooresponding alpha char, [a-z,A-Z].

The output data from the string 6FhJ9Z should be
[a-z,A-Z]FhJ9Z I guess what I am asking for is not
plausible after looking at the ASCII table b/c there
is no cooresponding letter for number 6. Silly me, ok
then maybe grab any [a-z,A-Z] character.

my $foo = pack(C*, 6); print $foo;
or
chr ('6'); 




What is the purpose of this program?



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




Re: Standard input Question

2006-09-26 Thread Mumia W.

On 09/26/2006 07:10 AM, elite elite wrote:


If i going to write a script with a standard input how
would it look like?My perl book don't talk about it.


Craig



If the perl documentation has been properly installed onto your 
computer, you should be able to open a command prompt and type perldoc 
perl to get some more information about perl.


You can potentially learn a tremendous amount about perl using perldoc.


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




Re: Matching a sub pattern and processing results

2006-09-25 Thread Mumia W.

On 09/24/2006 07:04 PM, David Gilden wrote:

Greetings,

I am having a little trouble understanding matching and getting the sub pattern 
saved to a Var. so that I can do a munge. I want to take the line returns and change them into 
pipe characters '|'   
All data records start with a date i.e. 01/01/2006  
But there are fields in between that are one multiple lines. Sample data is below the script.


Here's what I have so far 


#!/usr/bin/perl -w


open(FI,test.txt) || die Read in, Could not find File, $!;
my @files = FI;
close(FI);

for (@files){

chomp($_);

$_ =~m|(\d+/\d+/\d+)(?s)(.+?)\d+/\d+/\d+|;

$2 =~tr/\n/|/;

print $1$2\n;

# save out modified result...
}

Given this data:

09/01/2006|03:29AM Password for qsocordovam reset by Self Reset utility 
Username: qsocordovam 
ClientNumber: 77927 
IP address: 24.248.1.241  
09/01/2006|07:53AM Failed reset attempt 
Username: tmpcollic03 
ClientNumber: 110330 
IP address: 152.121.16.7 
Failed challenge question(s)  
09/01/2006|07:55AM Failed reset attempt 
Username: tmpcollic03 
ClientNumber: 110330 
IP address: 152.121.16.7 
Failed challenge question(s)  
09/01/2006|08:03AM Failed reset attempt 

Desired result: 
09/01/2006|03:29AM Password for qsocordovam reset by Self Reset utility|Username: qsocordovam|ClientNumber: 77927|IP address: 24.248.1.241  
#Next record starts with a date of format : 09/01/2006



Thanks for any input on my output :)

Dave Gilden  
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, TX, USA)







If the file is small enough to slurp into memory, you could do something 
like this:


#!/usr/bin/perl

use strict;
use warnings;

my $data = join '', DATA;
my @blocks = $data =~ m/^([0-9\/]+.*?(?=^[0-9\/]+))/gsm;
print \n;

s/\n/\|/g for @blocks;
print $_\n\n for @blocks;


__DATA__
09/01/2006|03:29AM Password for qsocordovam reset by Self Reset utility
Username: qsocordovam
ClientNumber: 77927
IP address: 24.248.1.241
09/01/2006|07:53AM Failed reset attempt
Username: tmpcollic03
ClientNumber: 110330
IP address: 152.121.16.7
Failed challenge question(s)
09/01/2006|07:55AM Failed reset attempt
Username: tmpcollic03
ClientNumber: 110330
IP address: 152.121.16.7
Failed challenge question(s)
09/01/2006|08:03AM Failed reset attempt



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




Re: Matching a sub pattern and processing results

2006-09-25 Thread Mumia W.

On 09/25/2006 06:47 AM, John W. Krahn wrote:

Mumia W. wrote:

On 09/24/2006 07:04 PM, David Gilden wrote:

I am having a little trouble understanding matching and getting the
sub pattern saved to a Var. so that I can do a munge. I want to take
the line returns and change them into pipe characters '|'   All data
records start with a date i.e. 01/01/2006  But there are fields in
between that are one multiple lines. Sample data is below the script.

If the file is small enough to slurp into memory, you could do something
like this:

#!/usr/bin/perl

use strict;
use warnings;

my $data = join '', DATA;
my @blocks = $data =~ m/^([0-9\/]+.*?(?=^[0-9\/]+))/gsm;
print \n;

s/\n/\|/g for @blocks;
print $_\n\n for @blocks;


Your code puts a | at the end of the record as well as between the fields and
it doesn't remove trailing whitespace from the fields and it skips the last
record.  To fix:

my $data = do { local $/; DATA };
chomp( my @blocks = $data =~ m!^([\d/]+.*?(?=^[\d/]+|\z))!gsm );
print \n;

s/\s*\n/|/g, s/\s*\z// for @blocks;
print $_\n\n for @blocks;




John


Uhhh. I should've looked more closely at my output. Thanks.



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




Re: about perltoot

2006-09-24 Thread Mumia W.

On 09/24/2006 12:35 PM, chen li wrote:


--- Mumia W. [EMAIL PROTECTED]
wrote:


On 09/22/2006 07:50 AM, chen li wrote:

--- Mumia W.

[EMAIL PROTECTED]

wrote:
That redundancy allows you to use inheritance. 
If 
you have a class 
Employee, with an expanded set of fields, this 
method makes it possible 
to add the fields without having to modify each 
method that uses them.



Where can I find more about this kind of syntax?
[...]

Read the Class Data section in perltoot.


Hi Mumia,

I don't think I get the point.  


Write an example. Create a superclass and a subclass where the 
superclass has class data that you want to be able to override in the 
subclass (but *without* having to override every method that uses that 
data).


If my purpose of using 
AUTOLOAD is to handle 1) many attributes in construct 
2) create an un-predined method on the fly, what will 
happen if I make the following changes:


in sub new change 
 my $self  = {_permitted = \%fields,%fields,};
 
to my $self =\%fields;



in  sub AUTOLOAD comment out the unless statement.

Do you think these change will affect inheritance?



Why didn't you test what happens when you do that? What happens when you 
create three different objects and manipulate them? What happens with 
those object when you go back to the original code?



Thanks in advacne,

Li


### copy from perltoot
package Person;
 [...]






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




Re: CGI: How do I populate a form field based on the value entered in a different field

2006-09-23 Thread Mumia W.

On 09/23/2006 01:21 PM, RICHARD FERNANDEZ wrote:

Hi folks,
 
I'm trying to create an HTML form that will refresh itself based on user

input. In the POD for CGI it says that you can set the value of a named
parameter by using something like:
 
$query-param(-name='foo', -value='the value');
 
But it doesn't say (or at least I didn't see) anything about how to

redisplay the form with the new value in the textbox (or a different
textbox for that matter).
 
The sample script at the top of the doco (perldoc CGI) creates a blank

form that takes some input, a name, a combination, and a color and
displays the user input in the bottom half of the page.
 
I would like to edit the value entered into the name textbox and

display my edited value in the same, or possibly a different textbox.
I've tried a bunch of things including the call to param() above,
without success.
 
For example, if the user types Wilma into the textbox, the script

should populate the target textbox with my edited value, say, Betty.
 
As always, Thanks in Advance  for any help!
 
richf




Did you test it? It is my impression that CGI.pm works this way normally:

use strict;
use warnings;

my %nmap = (
wilma = 'betty',
fred = 'barney',
bambam = 'pebbles',
);

  use CGI qw/:standard/;
  print
  header,
  start_html('Simple Script'),
  h1('Simple Script'),
  start_form,
  What's your name? ,textfield('name'),p,
  What's the combination?,
  checkbox_group(-name='words',
 -values=['eenie','meenie','minie','moe'],
 -defaults=['eenie','moe']),p,
  What's your favorite color?,
  popup_menu(-name='color',
 -values=['red','green','blue','chartreuse']),p,
  submit,
  end_form,
  hr,\n;

   if (param) {

# Replace the parameter.
my $temp = param('name');
if ($nmap{$temp}) {
# param('name',$nmap{$temp}); # This also works.
param(-name = 'name', -value = $nmap{$temp});
}

  print
  Your name is ,em(param('name')),p,
  The keywords are: ,em(join(, ,param('words'))),p,
  Your favorite color is ,em(param('color')),.\n;
   }
   print end_html;




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




Re: selecting a part of a string

2006-09-23 Thread Mumia W.

On 09/23/2006 07:07 PM, Rob Dixon wrote:

[...]
If you want to do what you said, and put everything up to the pipe into a
variable (scalar $tex?) then

  /([^|]+)/;
  $tex = $1;
[...]


No, you should always only use the match variables after you've 
determined that the match was successful:


/^([^|]+)/  $tex = $1;
 or this:
$tex = $1 if /^([^|]+)/;




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




Re: about perltoot

2006-09-22 Thread Mumia W.

On 09/21/2006 07:08 PM, chen li wrote:

Hi all,

I read some sections in perltoot. In section
Autoloaded Data Methods I see some line codes as
following:

 package Person;
use Carp;
our $AUTOLOAD;  # it's a package global

my %fields = (
name= undef,
age = undef,
peers   = undef,
);

sub new {
my $class = shift;
my $self  = {
_permitted = \%fields,
%fields,
};
bless $self, $class;
return $self;
}

It looks like that  _permitted = \%fields and %fields
are redundant. [...]


That redundancy allows you to use inheritance. If you have a class 
Employee, with an expanded set of fields, this method makes it possible 
to add the fields without having to modify each method that uses them.





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




Re: problem with stat?

2006-09-22 Thread Mumia W.

On 09/22/2006 02:58 AM, Mathew Snyder wrote:

[...]
my $mod_time = (stat($file))[9];
[...]



If $file is not in the current directory, this won't work.



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




Re: about perltoot

2006-09-22 Thread Mumia W.

On 09/22/2006 07:50 AM, chen li wrote:


--- Mumia W. [EMAIL PROTECTED]
wrote:

That redundancy allows you to use inheritance. If
you have a class 
Employee, with an expanded set of fields, this
method makes it possible 
to add the fields without having to modify each

method that uses them.



Where can I find more about this kind of syntax?
[...]


Read the Class Data section in perltoot.



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




Re: AUTOLOAD in perltoot

2006-09-22 Thread Mumia W.

On 09/22/2006 08:30 AM, chen li wrote:

Hi all,

I copy some codes from perltoot and write some lines
to see how AUTOLOAD works. 


test.pl
#!C:/Perl/bin/perl.exe

use strict;
  use warnings;  
  use Data::Dumper;

  use Person;
  
  my $obj=Person-new();
  
  print $obj-name();  
  
  print Dumper $obj;


# Person.pm in the same folder(copy from
perltoot###

 package Person;
use Carp;
our $AUTOLOAD;  # it's a package global

my %fields = (
name= 'Li',# I define the value
age = 'X', #I define the value
peers   = 'O',#I define the value
);

sub new {
my $class = shift;
my $self  = {
_permitted = \%fields,
%fields,
};
bless $self, $class;
return $self;
}

 sub AUTOLOAD {

my $self = shift;
my $type = ref($self)
or croak $self is not an
object;

my $name = $AUTOLOAD;
$name =~ s/.*://;   # strip
fully-qualified portion

unless (exists
$self-{_permitted}-{$name} ) {
croak Can't access `$name' field in
class $type;
   }

if (@_) {
return $self-{$name} = shift;
} else {
return $self-{$name};
}
} 

1;   



1) If I call the pre-defined methods there is not
problem with this script.

2) If I call a method undefined by this module ,

such as adding a line code
print $obj-author('Chen');

I will get this wrong message:

Can't access `author' field in class Person

3) If I follow the step 2) and at the mean time
comment out the following line codes 


unless (exists $self-{_permitted}-{$name} )
{
  croak Can't access `$name' field in
class $type;
}

I also get what I expect: create a new method on the
fly.

My question: What is the purpose for the  condition
statement unless here? It looks like it will prevent
creating a new method on the fly. Any comments?



Yes, it will prevent creation of a new method on the fly if the method 
name is not in the permitted fields list.


Try this:
$obj-name('Roger');
print $obj-name(), \n;

Although you didn't create a static name method, autoload created 
one on the fly[0]. It did this because name is in the list of 
permitted fields.



Thank you very much,

Li



You're welcome.

--
0: This is a simplification. AUTOLOAD doesn't create new methods unless 
you tell it to; here, AUTOLOAD just performed the desired operations.




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




Re: system call issues

2006-09-21 Thread Mumia W.

On 09/21/2006 04:52 AM, Saurabh Singhvi wrote:

Hi all,

The following code block



is written without strictures and warnings enabled. If you place these 
lines,

  use strict;
  use warnings;
at the top of your program, you'll catch errors much more quickly. In 
particular, use strict will force you to declare your variables before 
using them, which can prevent some kinds of bugs.



foreach $protein (@pdbs) {
   $rmsd[$i] = 0;
   foreach $protein2 (@pdbs2) {
   system(./TMalign $protein $protein2 | cgrep -i rmsd 
temp) == 0 or die $?;


# Replace the above line with the:
		open (TEMP, -|, ./TMalign $protein $protein2 | cgrep -i rmsd) or 
die $!;



   chomp($line = TEMP);
   close TEMP;
   ($length,$rmsd,$tm_score,$id) = split(/\,/,$line);
   $rmsd =~ s/RMSD\=//;
   $rmsd =~ s/\s//g;
   $rmsd[$i] += $rmsd;
   }
   $i++;
}

is giving error :

open: null file name
apparent state: unit 10 named
last format: (A100)
lately reading sequential formatted external IO



What OS and filesystem is this?


Now if i use exec instead of system, things work. But then the code ends
because of exec, and that isn't what i need.

if som1 can plz tell me what the problem is :(

thanks
Saurabh



Try the open command I wrote, and see if that works. I hope this helps.


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




Re: system call issues

2006-09-21 Thread Mumia W.

On 09/21/06 07:30, Mumia W. wrote:


Try the open command I wrote, and see if that works. I hope this helps.




s/open command/code/

No I didn't write the open command ;-)


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




Re: PACK statement compile error

2006-09-21 Thread Mumia W.

On 09/21/2006 10:25 AM, Tony Frasketi wrote:

Hello list.
I'm getting the following error message when compiling the program 
listed below ...


  Bad name after c' at /test/test1.cgi line 22.

line 22 is  '   s/%(..)/pack('c', hex($1))/eg;'

Need help in eliminating this error!
thnx
tony

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

use strict;

# Enable HTTP output
print(Content-type: text/html\n\n);

my $url = nice.cgi?a=b+c+dx=a+m;
my $x = decodeURL($url);
print 'x[$x]br;



Use a programmer's editor that has syntax highlighting. The /second/ I 
pasted your code into VIM, I saw the problem. That print statement's 
string is not terminated correctly. You start the string with a 
single-quote, but you end it with a double-quote--so the string never 
really ends until you get to the single-quote in the pack statement below.



exit;


#-
# Decode the URL
# decoded_url = decodeURL($url);
#-
sub decodeURL {
  $_ = shift;
  tr/+/ /;
  s/%(..)/pack('c', hex($1))/eg;
  return($_);
}



HTH


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




Re: Modules aiming at displaying mathematical functions on screen?

2006-09-20 Thread Mumia W.

On 09/20/2006 05:24 AM, SFantar wrote:

Hello

After searching the cpan.org site for mathematical modules, I did not 
find a module which can display graphically

the result of a function.
I want to see a function curve displayed in a graphical window?

How can I make it possible in Perl?
Thanks in advance for your help.



Install PDL (perl data language). On Debian when I installed 'pdl' I got 
PDL::Graphics::PLplot which is a rather nice, perl-native way to 
generate graphs.


use strict;
use warnings;
use PDL;
use PDL::Graphics::PLplot;

my $pl = PDL::Graphics::PLplot-new (DEV = pbm, FILE = test.pbm);
my $x  = sequence(10);
my $y  = $x**2;
$pl-xyplot($x, $y);
$pl-close;



test.pbm.gz
Description: GNU Zip compressed data
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response


Re: File::find with no_chdir

2006-09-19 Thread Mumia W.

On 09/18/2006 10:11 AM, Emilio Casbas wrote:

Hi,

I have this script;

---
use File::Find;

$File::Find::no_chdir = 0;
find(\wanted, @ARGV);

sub wanted {
   print $File::Find::name\n if(-d);
   }

---

I want to do a directory search for a given ARG, but no a recursive 
search, for example

this script show this;

[EMAIL PROTECTED] tmp]# perl script.pl /tmp
/tmp
/tmp/.ICE-unix
/tmp/test_directory
/tmp/test_directory/directory1
/tmp/test_directory/directory1/directory2
/tmp/test_directory/directory1/directory2/directory3
/tmp/lost+found
/tmp/.font-unix

But i want a behaviour like this command;
[EMAIL PROTECTED] tmp]# find /tmp -type d -maxdepth 1
/tmp
/tmp/.ICE-unix
/tmp/test_directory
/tmp/lost+found
/tmp/.font-unix

Any help?

Thanks
Emilio C.



File::Find wants to make it recursive by default, so use File::Slurp 
instead:


use File::Slurp;
my @files;
push @files, read_dir for (@ARGV);
print (join \n, @files), \n;

WARNING: UNTESTED CODE


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




Re: changing the group that files are created with

2006-09-18 Thread Mumia W.

On 09/18/2006 02:06 AM, Ken Foskey wrote:

I have a lot of files created by a (much too) complex script and the
user I am running with has a default group of 'staff' but I want all
files created to have clientgrp which we create to ensure that only
authorised people have access to a particular clients data.  I have a
command in Linux that does this but I am running on AIX  (I want it
portable so a pure perl method is better...)

MY solutions are chgrp on the file after creation.  Great initially but
then someone will forget for a new file and besides it adds a lot more
code and the complexity goes up.  I ended up adding the group to the
directory with g+s to force the group but there may be a time were we
use common directories and the file should be protect there as well.

I cannot google an answer because there are too many answers and I
cannot figure out how to fine tune my query.


I want to change the group files are created with and I cannot google an
answer because I get too many answers.

Thanks
Ken Foskey




In a shell, I might use the newgrp command before running programs that 
create files; however, in a script, this would only work for Expect 
invoked scripts and sub-shells. You might be able to create a stub 
script that changes into the new group (using 'sg'--switch group) then 
invokes your main script like so:


system(sg client-grp -c 'perl main.1.pl');

You asked how to do this in a platform-independent way. I have no 
earthly idea how to do that.



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




Re: extracting several text from logs using regex

2006-09-15 Thread Mumia W.

On 09/14/2006 11:04 PM, Michael Alipio wrote:

Hi,

A log file contains several of these lines:

session.blablahbla
blablabla proto:6 blablabla srcip:90.0.0.1 blablabla
blablabla srcport:3243 blablabla dstport:23 blablabla

session.blablahbla
blablabla proto:6 blablabla srcip:90.0.0.1 blablabla
blablabla srcport:3243 blablabla dstport:23 blablabla

session.blablahbla
blablabla proto:6 blablabla srcip:90.0.0.1 blablabla
blablabla srcport:3243 blablabla dstport:23 blablabla

basically, for each session, I need to obtain:
srcip, srcport, dstip, dstport, then do something with
it, say put it in a table;

So far here's what I got: :-)


my $sessionlog = shift @ARGV;
my $sessioncounter = '0';
my $start;
my $srcip;
my $srcport;
my $dstip;
my $dstport;

open SESSIONLOGS, $sessionlog or die $!;
while (SESSIONLOGS){
  if (/^session/){
 $start = true;
 ++$sessioncounter;
  }

}
[...]


This is how I might do it; however, the dstip's are not in the 
 data you posted:


use strict;
use warnings;
use IO::Scalar;
my $data = q{
session.blabfirst
blablabla proto:6 blablabla srcip:90.0.0.1 blablabla
blablabla srcport:3243 blablabla dstport:23 blablabla

session.blabsecond
blablabla proto:6 blablabla srcip:90.0.0.2 blablabla
blablabla srcport:3244 blablabla dstport:23 blablabla

session.blabthird
blablabla proto:6 blablabla srcip:90.0.0.3 blablabla
blablabla srcport:3245 blablabla dstport:23 blablabla
};

local $/ = '';
my $fh = new IO::Scalar \$data;
while (my $record = $fh) {
my %extr;
for (qw(srcip srcport dstport dstip)) {
$extr{$_} = '';
$extr{$_} = $1 if $record =~ /$_:([\d.]+)/;
}
print $extr{srcip}|$extr{srcport}|$extr{dstip}|.
$extr{dstport}\n;
}
$fh-close;

--end program---

Notice that I set $/ to '' so that entire records would be 
grabbed at once.



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




Re: removing characters

2006-09-15 Thread Mumia W.

On 09/15/2006 12:54 AM, ubergoonz wrote:

Hi,

I have a certain variables of emplyee number which comes in the format of
[a000]  or [u000] {whereby 000 is some serial numbers}.

I would like to remove the enclosed [  ]  see if it is belong to class 
a or

u , i can do it as follow

$var = /\[//; $var = /\]//;
if ($var =~ '^a) {
  print $var is class A;
} elsfi ($var =~ '^u) {
  print '$var is class U;
}
$var = /a//; $var = /u//;

How can i remove the chars all in a single line? and write the code in a
more perl manner ?


regards
rexo



I can think of two good ways of doing this:

use strict;
use warnings;
use Data::Dumper;
my $string = '[a000] [u000]';

# Method 1:
my $str = $string;
$str =~ s/[][]//g;
print $str, \n;

# Method 2:
my @data = grep length, split /[][ ]/, $string;
print Dumper([EMAIL PROTECTED]);

I can't remember from where I got the [][] syntax. Perhaps it 
was from FMTEYEWTK for the perl faqs. Thank you whoever you are.







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




Re: Problem with GD::Graph

2006-09-15 Thread Mumia W.

On 09/15/2006 02:24 AM, john wrote:

Hi all

 

I have installed the GD::Graph module and I tried to run the example using 
this code

[...]
my $graph = GD::Graph::chart-new(400, 300);
[...]


I haven't installed GD::Graph yet, but the description 
provided by 'aptitude' doesn't describe a GD::Graph::chart 
class, so there might not be a chart class. Try one of 
lines, bars, points, linespoints, mixed or pie.





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




Re: How to create XML files from simple plain text files?

2006-09-15 Thread Mumia W.

On 09/15/2006 07:12 AM, sfantar wrote:

Hello All!

I would like to know how possible it is to create XML files from plain text 
files.
I have a huge number of text files I want to convert into XML format.
Is there any Perl modules for this purpose?
[...]


XML::Simple can do it.



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




Re: hash access

2006-09-14 Thread Mumia W.

On 09/14/2006 01:18 AM, Xavier Mas i Ramón wrote:

Hi all!,

I'm trying to create a sorted (ASCII) hash file but get all time a syntax 
error in line my $abreviatures{$clau} = 1; at  $abreviatures{ --. Sure 
is an stupid mistake but I'm not able to see it even checking with my 
Learning Perl book.


Pls, can someone tell me where is the syntax error?

...
while (ABREVIATURES) {
chomp;
my $clau = $_;
my $abreviatures{$clau} = 1;
}
close ABREVIATURES;
...

Many thanks,



The my command doesn't work that way. You have to my the 
entire hash like so:


...
my $abreviatures;
while (ABREVIATURES) {
  chomp $_;
  my $clau = $_;
  $abreviatures{$clau} = 1;
}
close ABREVIATURES;
...


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




Re: hash access

2006-09-14 Thread Mumia W.

On 09/14/2006 07:17 AM, John W. Krahn wrote:

Mumia W. wrote:

The my command doesn't work that way. You have to my the entire hash
like so:

...
my $abreviatures;


That is not a hash, that is a scalar.  ITYM:

my %abreviatures;



John


Oops, thanks :-)



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




Re: Archive::Zip and hash issues

2006-09-14 Thread Mumia W.

On 09/14/2006 09:20 AM, Derek B. Smith wrote:

[...]
sub zipit {

##-- Add all readable files below $oldir --##
##-- and write them into a file. --##

my $zip = Archive::Zip-new();
my $entry = $zip-addDirectory ($oldir/$word/)
 or die Failed to add file for archive zip $!;
$entry-desiredCompressionLevel(9);
my @entries = $entry-membersMatching('log.*');


Huh?

MembersMatching should return an empty list because the new 
zip file (object) is empty, and that means that the directory 
entry ($entry) is also empty.



 $zip-writeToFileNamed(@entries)


Huh?

WriteToFileNamed is supposed to take a simple filename 
(string) argument--not an array. Stringification of that array 
would have the effect you complained about.



 or die Failed to write zip file $! if $zip !=
AZ_OK;
}
[...]


Try something like this (but season to taste):

#!/usr/bin/perl
use strict;
use warnings;
use File::Slurp;
use Archive::Zip;
use File::Spec::Functions;

my %subdir_for = (
'fawn-hall' = 41,
'gary-hart' = 59,
'monkey-business' = 81,
);

my $srcdir = catfile($ENV{HOME}, qw(tmp bp));
my $arcfile = catfile($ENV{HOME}, qw(tmp myfile.zip));

my $zip = Archive::Zip-new();
for my $file (keys %subdir_for) {
$zip-addDirectory($subdir_for{$file});
my $source = catfile($srcdir, $file);
my $target = catfile($subdir_for{$file},$file);
$zip-addFile($source,$target);
}
$zip-writeToFileNamed($arcfile);




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




Re: bizarre fractional exponents math

2006-09-14 Thread Mumia W.

On 09/14/2006 06:47 PM, Bryan R Harris wrote:


Can someone explain this behavior?

% perl -e 'print -12.17**0.2, \n'
-1.64838295714428
% perl -e 'print (-12.17)**(0.2), \n'
-12.17% perl -e 'print ((-12.17)**(0.2)), \n'
nan%


Yes, the \n isn't getting printed for some reason on the 2nd two examples.
Bottom line:

-12.17**0.2  == -1.65
(-12.17)**(0.2) == -12.17
((-12.17)**(0.2)) == nan

I have absolutely zero idea what could be going on here...  Please help!

- B






$ perl -e 'print (-12.17**0.2, \n)'
-1.64838295714428
$ perl -e 'print ((-12.17)**0.2, \n)'
nan
$ perl -e 'print (-1*(12.17)**0.2, \n)'
-1.64838295714428
$ perl -e 'print ((-1)**0.2, \n)'

The \n was outside of print's parenthises, and, evidently, 
perl does not like applying fractional exponents to negative 
numbers.



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




Re: Command line vs. cron

2006-09-13 Thread Mumia W.

On 09/12/2006 11:28 PM, James Marks wrote:

Hi folks,

I don't know if this is a Perl or UNIX problem and I'm hoping you can 
help me figure that out.


I wrote a script that checks to see if the httpsd and mysqld processes 
are running on my server and to log the results of those tests.


When I run the script from the command line, the script prints to a log 
file the number of each of those processes that are running at the time 
of the script execution. When I run the same script from cron, however, 
it only prints a 1 for httpsd and mysqld.


[...]
my $httpsd_count = `ps -aux | grep -c httpsd`;
my $mysqld_count = `ps -aux | grep -c mysqld`;
[...]

Any ideas on why the same script has different results when run from the 
command line vs. from cron?


Thanks,

James




I don't know if this would affect the output, but ps -aux 
gives me this in addition to the normal output: Warning: bad 
syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html;


Perhaps ps hcax would suffice.

Also, watch what the grep -c ... is doing. Perhaps the 
counting isn't going as planned. I would count from within Perl.


This is how I might write the script:

#!/usr/bin/perl
use strict;
use warnings;

local $\ = \n;
local $, =  ;
my $ps = `ps hcax`;
my $logfile = '/tmp/counts-ma.log';
my $tty = `tty`;
chomp $tty;
my $mysqlc = () = $ps =~ m/\bmysqld\b/g;
my $httpdc = () = $ps =~ m/\bapache2\b/g;

open (STDOUT, '', $logfile) or die(Couldn't write to
$logfile\n);
my $date = `date +%Y-%m-%d %H:%M:%S`;
chomp $date;
print $date, httpd = $httpdc, mysql = $mysqlc;




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




Re: Command line vs. cron

2006-09-13 Thread Mumia W.

On 09/13/2006 06:07 PM, James Marks wrote:


What turned out to work — although I haven't figured out why yet — is to 
to use 'acx' rather than 'aux' and to include that within the single 
quotes as in:


open PS, '-|', '/bin/ps acx' or die Cannot open pipe from ps: $!;

The above line results in the script running fine from cron.

If I don't enclose the ps command with full path and options in the 
single quotes as in '/bin/ps acx' the script returns an error.


If I use 'aux' instead of 'acx' the result is a '1' or 'NOT RUNNING' for 
the process count.


- James




#!/usr/bin/perl
use strict;
use warnings;

local ($\, $,) = (\n,  );
my $logfile = '/tmp/counts-ma.log';
my $ps = `ps aux`;
my @group = (
`date +%Y-%m-%d %H:%M:%S`,
httpd = scalar (() = $ps =~ m{/usr/sbin/apache2\b}g),
mysql = scalar (() = $ps =~ m{/usr/sbin/mysqld\b}g),
);
chop $group[0];
open (STDOUT, '', $logfile) or die(Couldn't write log: $!\n);
print @group;

__END__

It's important to examine the output of ps to see what you 
need to extract, and it's best to let ps give you the 
smallest, simplest output possible to reduce the chances that 
you'll extract the wrong things.


For example, when I changed from using ps hcax to ps aux, 
I got 51 mysql processes returned by my script--which was 
clearly wrong; my problem was that I was counting the number 
of mysqld strings found, but the u option to 'ps' outputs 
too much data--the entire command lines for all processes, and 
'mysqld' appears several times on the command lines of each of 
the mysqld processes.


Keep it simple.





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




Re: Downloading a file through a filehandle

2006-09-12 Thread Mumia W.

On 09/11/2006 05:58 PM, Robin Sheat wrote:

On Tuesday 12 September 2006 10:27, Rob Dixon wrote:

[...]
What may help is that LWP allows for a callback to be specified in the 
get() call, so that the downloaded data can be passed in chunks to a 
user-written subroutine as it arrives. Use

   $agent-get($url, ':content_cb' = \callback);
Hmm, that looks promising. But it would require making a significant bit of my 
code a lot less generic.

[...]


I'm also out of my depth here, but you might be able to 
subclass IO::Handle to create a class that makes a LWP 
connection look like a file handle.





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




Re: Position Weight Matrix of Set of Strings with Perl

2006-09-06 Thread Mumia W.

On 09/06/2006 04:02 AM, Wijaya Edward wrote:

Dear Experts,
 
I am looking for a really efficient way to compute a position weight matrix (PWM) from a set of strings. In each set the strings are of the same length. Basically PWM compute the frequency (or probabilities) of bases [ATCG] occur in each position/column of a string. For example the set of strings below:
 
AAA

ATG
TTT
GTC

Note that the length of these strings in the set 
maybe greater than 3. 

Would give the following result: 
 
$VAR1 =  {

'A' = [2,1,1],
'T' = [1,3,1],
'C' = [0,0,1],
'G' = [1,0,1]
 };
 
So the size of the array is the same with the length of the string.
In my case I need the variation of it, namely the probability of the 
each base occur in the particular position:


$VAR = {
'A' = ['0.5','0.25','0.25'],
'T' = ['0.25','0.75','0.25'],
'C' = ['0','0','0.25'],
'G' = ['0.25','0','0.25']
  }
 
In this link you can  find my incredibly naive and inefficient code. 
Can any body suggest a better and faster solution than this:
 
http://www.rafb.net/paste/results/c6T7B629.html
 
 
Thanks and Regards,

Edward WIJAYA
SINGAPORE



Although I'm sure that smarter posters than I will turn this 
into a one-liner, I think that my solution is not so atrocious:


use strict;
use warnings;
use Data::Dumper;
local our @deep;
local $; = ','; # A vestige of a previous version

my @data = qw(AAA ATG TTT GTC);
my @d2 = map [ split // ], @data;

my (%hash);
for my $entry (@d2) {
*deep = $entry;
for my $nx (0..$#deep) {
$hash{$deep[$nx]}[$nx]++;
}
}
foreach my $entry (values %hash) {
$entry = [ map defined $_ ? $_ : 0, @$entry ];
}
print Dumper(\%hash);

__HTH__


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




Re: regular expression question

2006-09-06 Thread Mumia W.

On 09/06/2006 09:49 PM, chen li wrote:

Hello all,

I need a regular expression to process some data but
get stuck. I wonder if anyone here might have a clue.

 input: 
 my $line='group A 1 2 3 4';# separated by space


 results:
 my @data=(group A ,1,2,3,4);



As Adriano Ferreira said, you don't need a regex for this, but 
here it goes:


local $\ = \n;
local $, = \n;
my $line='group A 1 2 3 4';# separated by space
my @data = $line =~ m/(group A|\d+)/ig;
print @data;


Thanks,

Li




You're welcome.


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




Re: Position Weight Matrix of Set of Strings with Perl

2006-09-06 Thread Mumia W.

On 09/06/2006 05:41 AM, Mumia W. wrote:

On 09/06/2006 04:02 AM, Wijaya Edward wrote:

Dear Experts,
 
I am looking for a really efficient way to compute a position weight 
matrix (PWM) [...]


Although I'm sure that smarter posters than I will [...]


do it right.

Ugh, I forgot about Wijaya's requirement that the PWM be 
calculated in probabilities, and I also forgot that the 
lengths of the base-pair strings can be different. Here is my 
updated code:


use strict;
use warnings;
use Data::Dumper;
local our @deep;
local $ = ', ';

my $length = 5;
my @data = qw(AAA ATG TTT GTC);
@data = map [ split // ], @data;

my (%hash);
for my $entry (@data) {
*deep = $entry;
for my $nx (0..$#deep) {
$hash{$deep[$nx]}[$nx]++;
}
}

my $count = keys %hash;
while (my ($key, $values) = each %hash) {
$#{$values} = $length;
@$values = map defined $_ ? $_ / ($count) : 0, @$values;
@$values = map sprintf('%4.2f',$_), @$values;
print $key = [ @{$hash{$key}} ]\n;
}

__END__

Output:
A = [ 0.50, 0.25, 0.25, 0.00, 0.00, 0.00 ]
T = [ 0.25, 0.75, 0.25, 0.00, 0.00, 0.00 ]
C = [ 0.00, 0.00, 0.25, 0.00, 0.00, 0.00 ]
G = [ 0.25, 0.00, 0.25, 0.00, 0.00, 0.00 ]
End output.

Note: I use $length to set the maximal array index value.


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




Re: can't print to STDOUT on 5.8.4

2006-09-05 Thread Mumia W.

On 09/05/2006 12:50 AM, Michael Alipio wrote:

Hi,

I was running this command on my perl program,

open FLOWTOOLS, |/usr/bin/flow-cat $start |
/usr/bin/flow-nfilter -f filter.tmp -F $direction
|/usr/bin/flow-stat -Pf8 | le
ss or die $!;

It does output something on the screen when I run it
on FreeBSD 6.1/perl 5.8.8 (while on csh)

However, when I run it on another machine Linux
version 2.6.8-2-386 Debian 1:3.3.5-13, with This is
perl, v5.8.4 built for i386-linux-thread-multi (while
on bash)

a blank screen appears shortly and then the program
immediately exits..

Any idea why this is happening?

Thanks.



First of all, FLOWTOOLS is not STDOUT.

You can't use less this way. Less is supposed to be used 
on an interactive terminal. I know nothing about the 
flow-tools. What are you trying to do?






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




Re: word counting

2006-09-05 Thread Mumia W.

On 09/05/2006 03:47 AM, Andrew Kennard wrote:

Hi all

I'm looking for a good word counting module/sub routine

I've found this so far 
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=562lngWId=6


but it counts things like the Item1,Item2,Item3 as one word

I've had a search on CPAN but that did not result in any at all ? did I miss 
something ?


I need a word counter to count the number of words in a scientific paper. I 
know it wont be 100% accurate due to formulas etc but has anyone got a 
better solution than the one above ? It's to check it is under a max word 
count


Thanks in advance

Andrew 






This is untested ($data should contain the text with the words):

my $count = () = $data =~ m/[[:alpha:]]+/g;




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




Re: process data into an array using CGI script

2006-09-03 Thread Mumia W.

On 09/02/2006 08:09 PM, chen li wrote:

Dear all,

I paste some data into textarea in a CGI script and
use param('data')to retrieve the data. I want to pass
the data into an array but what I find is that I only
one dimensional array. Can someone here give me a
hand?

Thanks,

Li

data pasted into textarea:

1 1 1
2 2 2
3 3 3

(each column separated by tab and each row ended with
\n)

after passed into script and processed the expected
result is 
my @data=(

  [1,1,1],
  [2,2,2],
  [3,3,3],
   );




Perldoc perllol shows you how to create lists of lists 
(arrays of arrays).





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




Re: Trouble with variable scoping

2006-08-31 Thread Mumia W.

On 08/31/2006 08:19 AM, Roman Daszczyszak wrote:

In my perl script, I have a global variable called
@excludedIPAddresses, [...]

my @excludedIPAddresses = qw# 192.168.0.142 192.168.3.118 #;#
[...]
local @excludedIPAddresses = @excludedIPAddresses;
[...]
When I run this, I get an error Can't localize lexical variable.  I 
understand that it's because the variable is declared using my; what 
I don't understand is why, or what I should declare the variable as, 
since if I leave out my I get an error using use strict.




Declare it using 'our':

our @excludedIPAddresses;



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




Re: Totally lost - need a starting point

2006-08-31 Thread Mumia W.

On 08/31/2006 08:24 AM, Helen wrote:

- Original Message -
From: Charles K. Clarkson [EMAIL PROTECTED]
To: beginners@perl.org
Sent: Wednesday, August 30, 2006 10:16 PM
Subject: [Bulk] RE: Totally lost - need a starting point



Helen wrote:

I am starting from scratch again reading the manual more 
completely. I am just running out of time on my deadline.


Break down your task into small pieces and solve for 
those pieces. The first piece I can see is running an Expect 
script from a perl program. Do you know how to do that?


I have no idea what Expect is, but searching for 
'expect' and 'perl' in Google revealed a perl module for 
expect.


The other pieces of your problem might include getting 
form values from an HTML form. CGI.pm can help with that.



HTH,

Charles K. Clarkson


Yes I have a perl script running inside of the expect script, which works 
fine.  I need to find a way to call the expect script and output the perl 


What perl?


to the html page that is calling it.  I found a version of expect for perl, but 
it didn't seem to be able to get the results that I was looking for, being 
able to telnet into a terminal and offer up passwords and such. then run 
another perl script that was picked as an option.


Helen



Hello Helen. First, you're confusing me; please don't 
top-post, and [Bulk] RE: should not have been added to the 
subject line; tame your mail-reader.


Second, Expect.pm can do telnet:

use strict;
use warnings;
use Expect;


my $exp = Expect-spawn(telnet = qw(localhost 80))
or die (Spawn failed: $!\n);

my $data = '';
my $tosend = q{GET / HTTP/1.1
Host: localhost
Connection: close

};

$exp-expect(4,
[ '^Escape char' = sub {
$exp-send($tosend);
}],
);

$exp-expect(4,
[ '^HTTP/1.1' = sub {
$data = $exp-match . $exp-after;
}],
);

$exp-soft_close;
print --\n;
print $data;

__END__

On my system, the output from my local web-server appears.

HTH



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




Re: split function help

2006-08-29 Thread Mumia W.

On 08/29/2006 08:23 AM, Sayed, Irfan (Irfan) wrote:

Hi All,
 
I need to use the split function in perl script.
 
* /vobs/apache_log4j

/usr/add-on/puccase_vob01/ccvob01/apache_log4j.vbs public (replicated)
 
Above line i need to split in following order
 
* 
/vobs/apache_log4j
/usr/add-on/puccase_vob01/ccvob01/apache_log4j.vbs 
public 
(replicated)
 
 
I tried the following command 
 
my @vob_path = split(/ /, $vob_list); where $vob_list contains the

actual line.
 
but i am not getting the output as i want.
 
can anybody please help.
 
Regards

irfan
 


You didn't say what was wrong with your output, but I think 
that you can fix it by creating a character class containing 
both space and newline and splitting on that:


use Data::Dumper;

my $vob_list = q{* /vobs/apache_log4j
/usr/add-on/puccase_vob01/ccvob01/apache_log4j.vbs public 
(replicated)};


my @vob_path = split (/[ \n]/, $vob_list);
print Dumper([EMAIL PROTECTED]);

__END__

Next time, rather than to say I am not getting the output as 
I want, instead say something like The output is wrong 
because I am getting /vobs/apache_log4j inside the same 
element as /usr/add-on/


HTH

PS.
Thanks for spelling words properly.


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




Re: STDOUT and STDERR to same file

2006-08-29 Thread Mumia W.

On 08/29/2006 09:06 AM, Ken Foskey wrote:

I have a daemon process that works but I am currently running it with

 script.pl  error.log 21

and I want to do the same thing without using the redirection,, remove
the human error when starting the program.

I can `open( STDERR, '', 'error.log') ...` but is there a piece of
magic to duplicate that to STDOUT as well (ie same file output)

Ta
Ken Foskey




Perldoc -f open shows you how to create duplicate file 
handles, e.g.:


use strict;
use warnings;
open (FH, 'out') or die(Failure:$!\n);
open (STDOUT, 'FH') or die (Dup failure: $!\n);
open (STDERR, 'FH') or die (Dup failure: $!\n);
print STDOUT text is here.\n;
print STDERR This might be an ERROR message.\n;
close (FH);

__END__

HTH



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




Re: Cgi with GD grap, and displaying graphs

2006-08-29 Thread Mumia W.

On 08/29/2006 11:05 AM, Patrick Rice wrote:

Hi all

I'd like some advice,
set up; Red hat Enterprise 4
Perl 5.8


I am trying to create a web page, which takes data from a file and 
builds a graph with GD, these are then saved as pictures, I then use the 
cgi script to call the pics using dynamically generated HTML page, using 
a system call to another perl script.


When I do this, I get a 500 internal error and I've traced this down to 
a permissions problem, as the apache user doesn't have the permissions 
to write the pic's in the /var/www/html file.

[...]


Perhaps you could create a directory, /var/www/cgi-img/, and 
make sure that the web-server can write in that directory and 
change your script to write in that directory.


Since you are using RHEL, you should also make sure that 
SELinux is not interfering with Apache.



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




Re: hash lookup table

2006-08-29 Thread Mumia W.

On 08/29/2006 01:46 PM, Derek B. Smith wrote:

[...]
If I change $number to $word is obviously does the
copy correctly, but what is the point of 
my $number = $subdir_for{$word};


???



Forget it. Do what works. :-)




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




Re: help with awk command in perl

2006-08-29 Thread Mumia W.

On 08/29/2006 10:40 AM, Sayed, Irfan (Irfan) wrote:

Hi All,
 
I have a following script in perl in which i am using awk command but it 
is not getting executed properly.
 
 
# /usr/atria/bin/Perl -w
 
use strict;

use warnings;
 
my $fname  = /tmp/checkvob_log;

open(FILE,$fname);
 


Check if the open failed. Read perldoc -f open.



my $CT = /usr/atria/bin/cleartool;
 
my @vob_list = `$CT lsvob -s`;
 
my @vob_list1 = `$CT lsvob`;
 
print FILE @vob_list1;
 
my $cmd1 = awk '{print $3}' /tmp/checkvob_log;
[...] 


That $3 is expanded inside the perl interpreter--long before 
awk gets it. Put a backslash in front of it to delay expansion.





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




Re: splitting strings

2006-08-29 Thread Mumia W.

On 08/29/2006 06:52 AM, Hien Le wrote:

[...]
# Method 2
print( \nMethod 2\n );
my @bar2 = split( /([a-z]{5})/, $foo );# Captures white-spaces ?!?
[...]


The comments made by Dr. Ruud and John W. Krahn are correct. 
Split is returning the empty strings between delimiter 
segments in the original string. To zap these out, do this:


my @bar2 = grep length, split (/([a-z]{5})/, $foo);

Any substrings with a length of zero will be removed by grep 
length.




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




Re: Print to new file for each results

2006-08-29 Thread Mumia W.

On 08/29/2006 06:32 PM, Ron McKeever wrote:

I am try to use part of someones elses code that creats the data file which 
prints out like this:

ip|result|deptA|data
ip|result|deptB|data
ip|result|deptC|data

My goal instead of having all the data in one big file is to loop this and create a file for each result. 
So I would have a deptA.out file with deptA info then a deptB.out 
file with dept b info and etc...

[...]


Although this is very different from your program, it should 
give you the general idea:


use strict;
use warnings;
use File::Slurp;
use File::Spec::Functions;

my @departments = q{
192.168.14.0|88|Sales|Richard Throop
192.168.16.0|90|Accounting|Juliet Rosenblatt
192.168.20.0|91|Logistics|Mark Mane
192.168.24.0|94|Security|Marlon Johnson
} =~ m/^\s*(.*)$/mg;

# print join \n, @departments;
my $dir = catfile($ENV{HOME}, qw(tmp tmp));

foreach my $info (@departments) {
my $fname = (split /\|/, $info)[2];
$fname = catfile($dir, $fname);
print $fname, \n;
write_file $fname, $info . \n;
}



__HTH__
:-)


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




Re: splitting strings

2006-08-29 Thread Mumia W.

On 08/29/2006 05:02 PM, Dr.Ruud wrote:

Mumia W. schreef:

Hien Le:



[...]
# Method 2
print( \nMethod 2\n );
my @bar2 = split( /([a-z]{5})/, $foo );# Captures white-spaces
?!? [...]

The comments made by Dr. Ruud and John W. Krahn are correct.
Split is returning the empty strings between delimiter
segments in the original string. To zap these out, do this:

my @bar2 = grep length, split (/([a-z]{5})/, $foo);

Any substrings with a length of zero will be removed by grep
length.


Huh? Why not just remove the capturing ()?

Again: perldoc -f split



Without the capturing parentheses, split will remove every 
sequence of five alphabetic characters from the output. Only 
'pq' will remain:


use Data::Dumper;
my $foo = 'abcdefghijklmnopq';
my @foo = split /[a-z]{5}/, $foo;
print Dumper([EMAIL PROTECTED]);

__END__

That program prints this:

$VAR1 = [
  '',
  '',
  '',
  'pq'
];



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




Re: Can't create 2d array in Perl

2006-08-29 Thread Mumia W.

On 08/29/2006 07:01 PM, Gregg Allen wrote:

Hi:


I would like to read a tab delimited text file created in Excel into a 
2d array.  I don't understand why the following doesn't work.  The $i 
and $j, along with the print statement, are only for debugging purposes.


It prints:


Can't use string () as an ARRAY ref while strict refs in use at 
file_vars.pl line 30, FH line 2.


Gregg Allen

*
#!/usr/bin/perl -w


use strict;


my @arr ;

my $i = $ARGV[0];
my $j = $ARGV[1];

print $i .  \t . $j . \n;


open(FH,0817L.txt) or die cannot open !$\n;

while(FH)
{

push  @arr , split /\t/ ;

}


print $arr[$i][$j];




I'm really confused about what $i and $j are supposed to be, 
but I might do it this way:


use strict;
use warnings;
use File::Slurp;
use Data::Dumper;

my @arr = map [ split /\t/ ], read_file('0817L.txt');
print Dumper([EMAIL PROTECTED]);

__END__

WARNING: UNTESTED CODE


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




Re: hash lookup table

2006-08-28 Thread Mumia W.

On 08/28/2006 08:37 AM, Derek B. Smith wrote:
All, 

I am trying to run logic that will copy/delete  3 
versions of log.\d+ files to their respective 
directories.  Because there are so many directories, I 
have built a hash table instead of using a bunch of 
if else conditions with reg exps. 
[...]


So instead of doing the code below because the subdirs 
are unique but all log file names are the same, 
log.\d+,  I want 
to use a hash table to decide what log files to copy 
where based on the subdir names or the key/value 
relationship.


if (@NBlogs2) {
  for my $log(@NBlogs2) {
  if ($log =~ 'bpcd') {
 qx(cp $log $oldir/bpcd/);   
  }

  elsif ($log =~ 'bpdbm') {
 qx(cp $log $oldir/bpdbm);
  }
  elsif ($log =~ 'bptm') {
 qx(cp $log $oldir/bptm);
  }
 } 
}




This was the only code in your post that I was able to 
understand because I wasn't able to figure out what 
words_to_num() was supposed to do. Here are two ways to go 
about something like what you want to do:



# This is ultra-simple and doesn't do
# what you want.

if (@NBlogs2) {
  for my $log (@NBlogs2) {
if ($log =~ m{([[:alpha:]]+)/log.\d+}) {
  my $word = $1;
  qx(echo cp $log $oldir/$word);
}
  }
}


# This might come closer to what you want.

foreach my $log (@NBlogs2) {
  if ($log =~ m{([[:alpha:]]+)/log.\d+}) {
my $word = $1;
my $number = $subdir_for{$word};
qx(echo cp $log $oldir/$number);
  }
}

I decided to echo the command rather than to execute it. ALL 
CODE UNTESTED.



thank you
derek



You're welcome.



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




Re: additonal notes - to: subroutine in LWP - in order to get 700 forum threads - some explanations

2006-08-26 Thread Mumia W.

On 08/26/2006 10:57 AM, jobst müller wrote:

[...]
first of - i have to explain something; I have to grab some 
data out  of a phpBB in order to do some field reseach. I 
need the data out of  a forum that is runned by a user 
community. I need the data  to analyze the discussions.




Use LWP::* to retrieve the data.
Use HTML::Parser (or similar) to parse the HTML pages retrieved.
Use DB_File (or similar) to put the extracted data into a 
database.


This is not necessarily simple stuff to do, but it can be done.




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




Re: CGI redirect question, slightly OT

2006-08-25 Thread Mumia W.

On 08/25/2006 02:58 PM, Michael Weber wrote:

Greetings, perlers!



Greetings, Michael.


[...]
# Now that we're done, redirect the user to an all done page...

print Location:
file:///Y:/Public_Info/IS/whitelist_done.html\r\n\r\n;



You can only redirect to web-servers. Redirection to locations 
on the user's local filesystem is not guaranteed to work.







E-MAIL CONFIDENTIALITY NOTICE: This communication and any associated 
file(s) may contain privileged, confidential or proprietary 
information [...]


This is a public mailing-list.

This portion of the message should probably be either not 
present, or should appear after a signature delimiter -- 




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




Re: Using a regular expression to remove all except certain characters.

2006-08-25 Thread Mumia W.

On 08/25/2006 04:26 PM, Jim Schueckler wrote:

Hi,
I need to remove all characters from a string except 'a'..'z', 'A'..'Z',
and '0'..'9'.
[...]


$newstring = $oldstring;
$newstring =~ s/[^[:alnum:]]+//g;

Everything that's not alphanumeric gets zapped to nothing.


HTH


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




Re: How do I do this on Perl ...

2006-08-23 Thread Mumia W.

On 08/22/2006 11:24 PM, [EMAIL PROTECTED] wrote:

Hi all,

I used to do this on UNIX scripts ...

#!/usr/bin/ksh
vowels=a e i o u
for letter in $vowels
do
   echo $letter
done

How do I do the same in Perl?

Is it possible to do this in Perl without having to put vowels into an array and
use foreach, i.e., using only a FOR-LOOP, but not necessarily having to hardcode
the ending number as for($start=1;$start=5;$start++)? vowels may change into
letters=a b c d e f g h in which case for($start=1;$start=5;$start++) may
not be valid anymore.

Any feedback will be very much appreciated  Thanks in advance ...




for my $letter (qw(a e i o u)) {
  print $letter, \n;
}


Take a look at perldoc perl and perldoc perlsyn.


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




Re: Accessing TCL api via perl

2006-08-23 Thread Mumia W.

On 08/23/2006 01:03 AM, Bobby Jafari wrote:

[...]
Every TCL API instruction that I use, would create a handle of some sort 
(i.e. a value that can be use to destinguish the call in a unique 
fashion).

[...]


I don't know what you mean by this.


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




Re: Intersection for each pair of arrays

2006-08-23 Thread Mumia W.

On 08/23/2006 09:58 AM, Andrej Kastrin wrote:

Hi,

below is simple solution for union and intersection for a pair of arrays 
(@a and @b). How to modify this example that I can calculate union and 
intersection for each pair of n arrays.




You could turn your code into a function and call it for each 
one of the pairs of arrays.



Thanks in advance for any suggestion, Andrej
[...]


You're welcome.




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




Re: How to do this sed one-liners inside Perl?

2006-08-23 Thread Mumia W.

On 08/23/2006 04:43 PM, [EMAIL PROTECTED] wrote:

Hi all,

I found the following sed one-liner trick that strips out the spaces that I run
as follows:

sed 's/^[ \t]*//;s/[ \t]*$//' /tmp/file.txt  /tmp/filea.txt
[...]


It's pretty much exactly the same except for the -pe:

perl -pe 's/^[ \t]*//; s/[ \t]*$//' /tmp/file.txt  /tmp/filea.txt



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




Re: How to grep $string from a file? How to run sed-like commands from Perl?

2006-08-23 Thread Mumia W.

On 08/23/2006 05:09 PM, [EMAIL PROTECTED] wrote:

[...]
Am guessing that I have to take out the array bit and just modify this line
here:

@match=grep{/$lookfor/[EMAIL PROTECTED];

But I am not sure how or what I should change it to. How do I tell grep to
search from a file instead of from an array? [...]


You could use the 'Tie::File' module.




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




Re: is there a path enviroment parameter that can tell perl where to find files?

2006-08-23 Thread Mumia W.

On 08/23/2006 02:30 PM, zhihua li wrote:

Dear all,

now when I'm writing some perl script that needs to open some files, I 
alwayse have to put the script in the same directory of these files, or 
I'll have to give the full path to these files in my script. if I do not 
do so, perl wouldn't be able to find the files I called up in the script.


is there some way to change some enviromental parameter so that when I 
call up a file in the script, perl will go to the directories I 
specified in searching for the file?


thanks a lot!





Change into the directory containing the scripts using the 
chdir function.


perldoc -f chdir



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




Re: XML::Simple help request

2006-08-22 Thread Mumia W.

On 08/21/2006 11:32 PM, Owen Cook wrote:

I am trying to get email addresses out of a Sylpheed address book. The
output of Dumper is;

$VAR1 = {
  'attribute-list' = [
  {}
],
  'first-name' = '',
  'uid' = '158149473',
  'cn' = 'Julie Jumper',
  'address-list' = [
{
  'address' = [
   {
 'email' = '[EMAIL PROTECTED]',
 'uid' = '158149474',
 'remarks' =[1] '',
 'alias' = ''
   }
 ]
}
  ],
  'last-name' = '',
  'nick-name' = ''
};

I cannot get my head around extracting the 'email' it seems be be buried
deep inside an array and a hash

Here is an attempt;

#!/usr/bin/perl

use XML::Simple;
use Data::Dumper;
use strict;

my $xml = new XML::Simple (KeyAttr=[], ForceArray = 1);

my $data = $xml-XMLin(ab6.xml);

foreach my $d (@{$data-{person}}) {
  print $d-{cn};#- that works
print \t;
  print $d-{address-list} # -need to get down to address and email.
 # most attempts failed but some gave a
 # hash reference [...]


print $d-{address-list}[0]{address}[0]{email};

or try this:

use Alias;
alias 'addresses' = $d-{address-list}[0]{address}
foreach my $ar (@addresses) {
  print email = $ar-{email}\n;
}

WARNING: UNTESTED CODE




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




Re: Simple-Yet Trivial Problem - Copy files from directory

2006-08-19 Thread Mumia W.

On 08/19/2006 02:19 AM, I BioKid wrote:

I have a simple - yet trivial problem -

I 2000 directory at /home2/foo/foodir/ .
I need to copy all files with extension *.atm and *.ali to another 
directory

called temp (say  /home2/foo/foodir/temp )
After that I need to run a program in each of this directory - (say joy
*.ali )
If am suppose to do it it will take a hell lot of time - so I have 
written a

small perl
script - but am not able to get what i need ...
Here is my script :

@a=`cat list`;


What is 'list'?


foreach $a(@a)
   {
   `mkdir $a`;


Why not use Perl's mkdir command?


# it is working fine up to this end -
   `cd $a`;


Why not use Perl's chdir command?


   `cp ../../$a/ *.ali .`;
   `cp ../../$a/ *.atm .`;
   }
am getting error / warning like this

cp: missing destination file
Try `cp --help' for more information.
sh: /: is a directory
but when am doing it manualy all the comments are working fine

Please help me with some inputs -


OT
Why use Perl at all?

Assuming that 'list' is a list of *.atm and *.ati files 
(without path names) in /home2/foo/foodir, you could try this:


cd /home2/foo/foodir/
cat ~/list | xargs -n1 -i cp \{\} /home2/foo/foodir/temp/
cd /home2/foo/foodir/temp
cat ~/list | xargs -n1 joy

WARNING: UNTESTED CODE



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




Re: Designing forms/tables in CGI

2006-08-18 Thread Mumia W.

On 08/18/2006 08:23 AM, Nath, Alok (STSD) wrote:

Hi Guys,
My question is can I create more that one form in the same page.



Yes


If yes , do I need to create separate cgi object for each form
or one object 
	for one page is sufficient.How do I design ? Which is advised ?




One cgi object is enough. Use start_form and end_form.



The reason for asking is I have created few tables in the same
page.
In my current implementation I have single form which creates
multiple
tables.Bcos of some unknown reason none of the tables are
getting displayed.
I was wondering if I can create separate forms isolating
the
error will be easier for me.

Please advise.

Thanx,
Alok





Run your script through the w3c's tidy utility to see what's 
messed up.


Or you could use the w3c's web page validator: 
http://validator.w3.org/





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




Re: Comparing two files of 8million lines/rows ...

2006-08-17 Thread Mumia W.

On 08/16/2006 04:35 PM, [EMAIL PROTECTED] wrote:

Hi all,

I have two database tables, one is local and one is on a WAN. They are supposed
to be in-sync but they at the moment, they are not. There are 8million+ plus
rows on this table.

I tried to do SELECT EMPNO FROM EMP WHERE EMPNO NOT IN ( SELECT EMPNO FROM
[EMAIL PROTECTED] ), leave that running for hours and all thru the night and 
guess
what, am still waiting for the result to come out ...

So what I decided is I want to extract the records into a flat file and then
write a Perl script to skim thru each line and check whether it exists on the
other file. While there will be 8million+ lines, the file will not be big
beacuse am only extracting one-column from the table.

Does anyone have an existing Perl code that does a similar thing like this
already? It will be much appreciated if you can send it to me and then I will
just modify it accordingly.

Example logic that I have is this:

FILE1:
MICKEY
MINNIE
DONALD
GOOFY
PLUTO

FILE2:
MICKEY
MINNIE
DONALD
GOOFY
PLUTO
BUGS-BUNNY

So search FILE1 for all line entries of FILE2 then output whoever does not exist
into FILE3. So after running the script, I should have ...

FILE3:
BUGS-BUNNY

What I currently have is that I read all of FILE2's entries into an array? Read
FILE1 one line at a time using m/// and if there is no m///, print that to
FILE3.

It seems to work fine for 1000 lines of entries, but am not particularly sure
how long will that take for 8million+ rows, not even sure if I can create an
array to contain 8million+ plus rows, if I can't, then am back to doing this on
the database instead. Another option am looking at is just to read FILE1 one
line at a time and do a grep $string_to_search FILE2 but I do not know how to
do a grep-like syntax against a file on Perl especially if the search string is
a variable.

Why I prefer using a script is so am not putting loads into the database not to
mention that I can put more logic into the script than on the SQL statement.

Any advise or other options will be very much appreciated  Thanks in
advance.






Obviously, you want to do this as efficiently as possible 
because of the humongous size of the data. Hashes are the 
fastest structures for letting you know if some data has 
already been seen.


Your problem is core. Do you have enough core memory to read 
all of the data one of the table columns into memory? If so, 
then the solution be almost trivial; if not, then it's 
probably not trivial, but also not hard.


My advice is to attempt to suck the entire column for one 
table into memory; FILE1 should become hash keys (with empty 
values). Then you would open FILE2, loop through the lines 
(records) and output any record that does not appear in the hash.


However, if you can't get the entire FILE1 into memory, then 
I'd suggest converting FILE1 into a berkeley database and 
using DB_File to tie it to a hash; from there on, the solution 
would be like the above.



HTH



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




Re: Improving script listing Perl modules installed

2006-08-15 Thread Mumia W.

On 08/14/2006 06:54 PM, SFantar wrote:

Hello everyone

I want to list all the Perl modules installed on my system. The script 
below does it well.

Unfortunately, it displays the name of each installed Perl module twice.
How can I get rid of them? [...]


For me it only displays each module once. Perhaps some of the 
directories appear twice in your PERL5INC environment variable.


Anyway, you can use a hash to remove duplicates.

What exactly are you trying to do? If it's to print out the 
base file name for all of the modules on your system, you 
could do this:


use File::Find;

find (sub {
print $_\n if (-f _  /\.pm$/);
}, @INC);





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




Re: extracting NAME and DESCRIPTION sections from pod text file

2006-08-13 Thread Mumia W.

On 08/13/2006 08:36 AM, Ken Perl wrote:

what's correct regular expression on extracting only NAME and
DESCRIPTION section from pod text file?
I have tried this, but failed!

perl -e '$c=`pod2text /data/WebGUI/lib/WebGUI/User.pm`;$c =~
s/(NAME.*)SYNOPSIS/$1/;print $c'



foreach $_ (`pod2text /usr/bin/pod2text `) {
if (/^NAME|SYN/../^$/) { print }
}


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




Re: Dynamic variables - from INI files ...

2006-08-12 Thread Mumia W.

(Re-directed to the list)
On 08/12/2006 05:44 AM, [EMAIL PROTECTED] wrote:

Hi Mumia,

Thanks for your tip, that's a good one ... just need to make
some more
modifications as below:

if ($path =~ m/\Q$ini{SOURCE_DIR$count}\E/i) {
$TARGET_DIR = $ini{TARGET_DIR$count};
} else {
   $TARGET_DIR = $DEFAULT_TARGET_DIR;
}

Am not an advanced Perl programmer but am slowly getting
very interested with
it, can you please kindly explain what the ones in the your
code does or
whether I understand them correctly as such

This piece of code enclose the string FTP_USER to
TARGET_DIR2=C:\Dir2 in
single quote and assign to $data?


Yes. Naturally, in your own code, you would read all of the 
data from the INI file and assign it to $data, perhaps like so:

$data = join ('',INIFILE);


 my $data = q{
 FTP_USER=FTPUser
 FTP_PASSWORD=FTPUser
 FTP_MODE=binary
 FTP_TARGET_SERVER=FTPSERVER
 FTP_ACTION_DIR=C:\FtpAction
 FTP_LOGPATH=C:\Temp
 NUM_OF_DIRS=2
 DEFAULT_TARGET_DIR=C:\Temp
 SOURCE_DIR1=D:\Study\Perl\MyFtp
 SOURCE_DIR2=D:\Study\Perl
 TARGET_DIR1=C:\Dir1
 TARGET_DIR2=C:\Dir2
 };

What does these two lines of code do?
 $data =~ s/^\s+|\s+\z//;


The line above strips off spaces at the beginning and end of 
$data. Read perldoc perlre; I should've split it into two 
statements for clarity:


  $data =~ s/^\s+//;
  $data =~ s/\s+\z//;


 my %ini = split /[ \n=]+/, $data;



The line above splits $data, and it splits on spaces, newlines 
or equal signs. The resulting array is a bunch of NAME VALUE 
pairs, and that's perfect for assigning to a hash (%ini).



I know the first one does a search and replace but I can't
work out what pattern
it is replacing. The second one creates an array %ini out
of $data with
[space][return line][=][spaces] as the delimiter?
Am I correct?



%ini is a hash, not an array.


And this line
 print Dumper(\%ini);

prints the content of the array %ini?



Yes

I just want to know whether I understand it correctly or 
not. Thanks in 
advance!




You're welcome.




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




Re: escape charachters

2006-08-11 Thread Mumia W.

On 08/11/2006 01:13 PM, Adriano Allora wrote:

hi all,

I use use HTML::Entities; and the functions decode() and encode(), but 
I'd prefer working with escape characters (egrave;, for example) than 
working with exadecimal (or what they are: #143 for example).


Must I use a regexp to substitute each or I can use some other function?

Thank at all,

alladr
[...]


From the manual page, it seems that HTML::Entities handles 
HTML entities properly. Could you show some (small) code 
demonstrating your problem?




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




Re: Hide code and user interfaces

2006-08-11 Thread Mumia W.

On 08/11/2006 10:51 AM, Kevin Viel wrote:

[...]
  Second, is there a way to keep my code private, like providing only 
the compiled program?  [...]


I did a search on CPAN for Obfuscate, and 
PAR::Filter::Obfuscate was returned. It's possible that PAR 
from CPAN is what you need.




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




Re: Dynamic variables - from INI files ...

2006-08-11 Thread Mumia W.

On 08/11/2006 09:37 PM, [EMAIL PROTECTED] wrote:

Hi,

I am writing a Perl script that reads some kind of INI file. I cannot use
Config::INI or install any new modules due to some restriction so am reading
the whole INI text file one line at a time and storing them into an array. Here
are what on my INI files:

FTP_USER=FTPUser
FTP_PASSWORD=FTPUser
FTP_MODE=binary
FTP_TARGET_SERVER=FTPSERVER
FTP_ACTION_DIR=C:\FtpAction
FTP_LOGPATH=C:\Temp
NUM_OF_DIRS=2
DEFAULT_TARGET_DIR=C:\Temp
SOURCE_DIR1=D:\Study\Perl\MyFtp
SOURCE_DIR2=D:\Study\Perl
TARGET_DIR1=C:\Dir1
TARGET_DIR2=C:\Dir2

Because I cannot install new modules, am not using Net::Ftp as well and instead
creating an FTP batch file which I then execute as #system ftp -v -n -i
-w:8192 -s:$FTP_BATCHFILE;

So far so good. Now I want to change my Perl script so that I can parse the path
of the source file and whether it matches SOURCE_DIR1 or SOURCE_DIR2 and if so
use TARGET_DIR1 or TARGET_DIR2 respectively on the FTP Server otherwise use
DEFAULT_TARGET_DIR.

I am running the script as MyFtp.pl D:\Study\Perl\Myftp\Test1.JPG, so I check
if ARGV[0] matches the string of SOURCE_DIR1 and if so use C:\Dir1 as the
target directory when I create the FTP batch file.

At the moment, I am hardcoding the checks as something like ...

if path = $SOURCE_DIR1 then TARGET_DIR=$TARGET_DIR1
elif path = $SOURCE_DIR2  TARGET_DIR=$TARGET_DIR2
else TARGET_DIR=$DEFAULT_TARGET_DIR

Of course, the above is not the program code but am sure the gurus understand
what I mean. Unfortunately, if I have to add two more directories to check for
example, SOURCE_DIR3, SOURCE_DIR4  SOURCE_DIR[N] and TARGET_DIR3,
TARGET_DIR4 ... TARGET_DIR[N], then I have to check my Perl script. So, what I
want to be able to know is if it is possible to load the values of SOURCE_DIR1
to SOURCE_DIR[N] into an array, and if so, how? I want to know if I can create
a dynamic variables $SOURCE_DIR$[N] that I can load into the array, I know what
is  the final [N] since I have NUM_OF_DIRS=2. I am wanting to do something that
will look like this:


   my $count=1;
   my $source_array=()
   my $target_array=()
   while ( $count le $NUM_OF_DIRS )
   {
  $source_array[$count]=$SOURCE_DIR$count;
  $target_array[$count]=$TARGET_DIR$count;
  #print $count . \n;
  #print $regex . \n;
  #if ($path =~ m/$regex/) {
  #  print 'match';
  #} else {
  #  print 'no match';
  #}
  $count++;
   }

Then somewhere down the code, I do

   my $count=1;
   while ( $count le $NUM_OF_DIRS )
   {
  if ($path =~ m/$source_array[$count]/) {
TARGET_DIR=$target_array[$count];
  } else {
TARGET_DIR=$DEFAULT_TARGET_DIR;
  }
  $count++;
   }

Obviously, this is not working at the moment, can someone on the list please
advise if what I am trying to achieve is possible or not. If it is possible but
am not creating or parsing the variables correctly, please advise on how I
should be doing it. I have no problem evaluating each value of the INI files,
i.e. I can parse $SOURCE_DIR1, $SOURCE_DIR2, $NUM_OF_DIRS etc., I just want to
know how I can dynamically create a variable $SOURCE_DIR1 to $SOURCE_DIR[N] and
store them into an array or perhaps how to check if a variable has been defined
or not?

Thanks in advance.






If you get the entire ini file into a string then you can 
split it so that it's easy to put into a hash:



use Data::Dumper;

my $data = q{
FTP_USER=FTPUser
FTP_PASSWORD=FTPUser
FTP_MODE=binary
FTP_TARGET_SERVER=FTPSERVER
FTP_ACTION_DIR=C:\FtpAction
FTP_LOGPATH=C:\Temp
NUM_OF_DIRS=2
DEFAULT_TARGET_DIR=C:\Temp
SOURCE_DIR1=D:\Study\Perl\MyFtp
SOURCE_DIR2=D:\Study\Perl
TARGET_DIR1=C:\Dir1
TARGET_DIR2=C:\Dir2
};

$data =~ s/^\s+|\s+\z//;
my %ini = split /[ \n=]+/, $data;
print Dumper(\%ini);

__END__

Then you could say this:

if ($path =~ m/$ini{SOURCE_DIR$count}/) {
  $TARGET_DIR = $ini{TARGET_DIR$count};
} else {
  $TARGET_DIR = $DEFAULT_TARGET_DIR;
}


A hash is the best way to store dynamic variable names.


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




<    1   2   3   4   >