Re: Does Regex help in this case ?

2003-09-07 Thread Li Ngok Lam
Thanks John, and Rob.

This reply is quite close to what I am going to do,
but some critical point is wanted here  I'll try to explain
my question further


  That's about the whole story, but I'll make it short.
  For example, I have a list like this :
 
  123ABCDEF456
  123456
  654WXYZ321
  987654321
  ABCDEF123456
  WXYZ321
 
  By user's INTEGER input , I will have to find how many similar
  patterns are matched within the list according to certain chars (user's
  input ) :
 
  For example, I input '3', then I will get the result like this :
 
  Res1: 123ABCDEF456 is similar to 123456
  Res2: 123ABCDEF456 is similar to ABCDEF123456
  Res3: 654WXYZ321 is similar to 987654321
  Res4: 654WXYZ321 is similar to WXYZ321
 
  In case , if a pattern match happens, then the elem in list will not
  be shown again even another match happens. Okay, thaz my
  homework for how to deal with the output.
 
  The question I want to ask is how to tell ( or is this a good starting
  point ) the regex to compare the patterns freely ? So I can get
  654WXYZ321 match 987654321 and also match WXYZ321 ?
 
  I hope I can explain my question well.

 I'm not sure exactly what you want but maybe this will give you some
ideas:


It does, and thaz about my coding currently up to.

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

 my @data = qw(
 123ABCDEF456
 123456
 654WXYZ321
 987654321
 ABCDEF123456
 WXYZ321
 );

 for my $x ( @data ) {
 for my $y ( @data ) {
 next if $x eq $y or length( $x )  length( $y );
 my $count = () = $x =~ /[\Q$y\E]/g;
 my $perc = ( $count / length $x ) * 100;
 printf %-12s %-12s  %2d %2d  %6.2f %%\n, $x, $y, length $x,
$count, $perc;
 }
 }

 __END__

 Produces this output:

 123ABCDEF456 12345612  6   50.00 %
 123ABCDEF456 654WXYZ32112  6   50.00 %

For what I want, this is not a match.
if my input is 3, than, the scanning process is like this :

123 compare 654WXYZ321 = false
23A  compare 654WXYZ321 = false
3AB  compare 654WXYZ321 = false
ABC  compare 654WXYZ321 = false
...
...
456 cmp 654WXYZ321 = false

In case, 3 means,  each 3 chars from the string formed a pattern
and trying to compare with elems in the list.


 123ABCDEF456 987654321 12  6   50.00 %
 123ABCDEF456 ABCDEF123456  12 12  100.00 %
 123ABCDEF456 WXYZ321   12  3   25.00 %
 654WXYZ321   12345610  6   60.00 %
 654WXYZ321   987654321 10  6   60.00 %
 654WXYZ321   WXYZ321   10  7   70.00 %
 987654321123456 9  6   66.67 %
 987654321WXYZ3219  3   33.33 %
 ABCDEF123456 123ABCDEF456  12 12  100.00 %
 ABCDEF123456 12345612  6   50.00 %
 ABCDEF123456 654WXYZ32112  6   50.00 %
 ABCDEF123456 987654321 12  6   50.00 %
 ABCDEF123456 WXYZ321   12  3   25.00 %
 WXYZ321  123456 7  3   42.86 %



Evaluate from the result, matching is by char based. So,
ZXCVBNM is 100 % match MNBVCXZ.. but for
what I am trying to compare will treat this 0 % match.
unless my input is '1'

I hope I can explain my question well this time, thanks for
any further advise. =)




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



Does Regex help in this case ?

2003-09-06 Thread Li Ngok Lam
Hi all, 

That's about the whole story, but I'll make it short.
For example, I have a list like this :

123ABCDEF456
123456
654WXYZ321
987654321
ABCDEF123456
WXYZ321

By user's INTEGER input , I will have to find how many similar
patterns are matched within the list according to certain chars (user's
input ) :

For example, I input '3', then I will get the result like this :

Res1: 123ABCDEF456 is similar to 123456
Res2: 123ABCDEF456 is similar to ABCDEF123456
Res3: 654WXYZ321 is similar to 987654321
Res4: 654WXYZ321 is similar to WXYZ321

In case , if a pattern match happens, then the elem in list will not
be shown again even another match happens. Okay, thaz my 
homework for how to deal with the output.

The question I want to ask is how to tell ( or is this a good starting
point ) the regex to compare the patterns freely ? So I can get
654WXYZ321 match 987654321 and also match WXYZ321 ?

I hope I can explain my question well.

Thanks in advise,
Li





I don't understand why this happen

2003-08-18 Thread Li Ngok Lam
 open my $fh, , items/list.db;
 print while ($fh);
 close $fh;

This is suppose to printout the content in items/list.db , 
but why I get somthing like GLOB(0x162aca7) ??

Thanks in advise.


Re: I don't understand why this happen

2003-08-18 Thread Li Ngok Lam
 
 my $fh;
 open $fh, '', 'items/list.db' or die File error:  $!;

It just the same as open my $fh =)

 print while $fh;

Hmm. I guess this is not a 'read' argument

Thanks in advise anyway =)


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



Re: I don't understand why this happen

2003-08-18 Thread Li Ngok Lam
Thank you very much Beau. However, my question is not how to solve,
there are many ways in deed, but why this happen and what's that actually?
=)

The only problem I can bet here is because I use the Switch.pm in my script.

TIA, again


- Original Message - 
From: Beau E. Cox [EMAIL PROTECTED]
To: Li Ngok Lam [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, August 18, 2003 7:38 PM
Subject: Re: I don't understand why this happen


 - Original Message - 
 From: Li Ngok Lam [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, August 18, 2003 1:10 AM
 Subject: I don't understand why this happen


 open my $fh, , items/list.db;
  print while ($fh);
  close $fh;

 This is suppose to printout the content in items/list.db ,
 but why I get somthing like GLOB(0x162aca7) ??

 Thanks in advise.

 Try:

 open my $fh, items/list.db;
 -or-
 open my $fh, items/list.db;

 Aloha = Beau;
 == please visit ==
 http://beaucox.com = main site
 http://howtos.beaucox.com = howtos
 http://PPM.beaucox.com = perl PPMs
 http://CPAN.beaucox.com = CPAN
 == thank you ==



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





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



Re: Split NewLines

2003-08-18 Thread Li Ngok Lam

 $string=1
 blabla;

 When Im printing $string I get a new line between 1 and blabla, now I
needt o
 split that.. in

 my($number, $real_string) = split...

my($number, $real_string) = split /\n/, $string;

HTH



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



Re: data not pushing to list

2003-08-14 Thread Li Ngok Lam
 Is there any reason why this doesn't print the @missing?
 Ive also tried unless ($myhash{$elem} == 1) { push(@missing, $frame) }
 Any insight into what I'm doing wrong would be greatly appreciated.

 @missing = ;

Wrong assignment, should be:
my @missing = ();
my %myhash = ();

 @framelist= (1, 2, 3, 6, 10);
 $startFrame= 001;
 $endFrame = 0010;
 
 @fullList = (int $startFrame .. int $endFrame);
 print FULL RANGE @fullList\n;
 foreach $item(@fullList) {
  $myhash{$item} = 1;
 }
 
 foreach $elem(@framelist) {

do you want $elem(@fullList) or @framelist ??

  print $elem\n;
  if ($myhash{$elem} == 1) {
   print $elem found!\n;
  }else{
   push(@missing, $elem);
  } 
 }
 
 print Missing Frames @missing; ##Doesn't print this!
 
As your output tells, everything are found !! So, of cause no missing..
Also, you assign all the values for any keys in %myhash are 1.
So you won't get any missing result even you assing @framelist = (1..10)

HTH

 --
 OUTPUT :
 
 FULL RANGE 1 2 3 4 5 6 7 8 9 10
 1
 1 found!
 2
 2 found!
 3
 3 found!
 6
 6 found!
 10
 10 found!
 Missing Frames



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



Fw: Can Perl dealing with PID ?

2003-08-07 Thread Li Ngok Lam
Is there any module in Perl can dealing with Procession ID on Win32?
And does Perll able to stop or start a services / application? 
Any pointers where I can start from ?

Thank you very much...

Re: Simple question

2003-08-07 Thread Li Ngok Lam
You method does work !
However, you can write as :
$line[1] /= 1000; 
# which is the same as $line[1] = $line[1] / 1000;

HTH

- Original Message - 
From: Sommer, Henrik [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, August 05, 2003 11:05 PM
Subject: Simple question


 Hi, 
 How do I divide a variable in an array ?
 Lets say element one need to be divided by 1000?
 
 $line[1] = $line[1]/1000; 
 
 Thanks, 
 Henrik
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


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



Re: print HTML code; in NETSCAPE

2003-08-04 Thread Li Ngok Lam
You are possibly missing this line :

print Content-type: text/html\n\n;

HTH
- Original Message - 
From: mario kulka [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, August 05, 2003 2:32 AM
Subject: print HTML code; in NETSCAPE


 I'm using the following to print HTML to the browser:

 print HTML code;

 my html here

 HTML code

 It works fine in IE but when I execute the script under Netscape it
displays
 the source instead of loading the page based on the source. Please help.
 Mariusz

 _
 Help STOP SPAM with the new MSN 8 and get 2 months FREE*
 http://join.msn.com/?page=features/junkmail


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





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



I just work this out.. but seems no point to use it

2003-08-03 Thread Li Ngok Lam
$x = sub { $y = shift; print $y };
$X = $x;
$X - (123); # prints 123;
undef $X;
$Z = $x;
$Z - (234); # prints 234

Question : 
1. When will you use this kind of style in your code ?
2. Any name for this kind of coding style ?

TIA




Re: Uploading files

2003-08-02 Thread Li Ngok Lam

- Original Message - 
From: K. Parker [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, August 02, 2003 12:00 PM
Subject: Uploading files


 On a site I'm developing, I'm trying to create a script that uploads
 encrypted files and saves them in a particular directory.

You will do in this way :
1. Create a html form which have a file type input.
2. Then write a CGI program to pick up the form
3. Read the Data from what you get.
4. Write the data to anywhere in your host as whatever file.
5. Done


 While the CGI mod
 had documentation about how to get an upload field up, I don't know how to
 actually upload the file entered by a user and save it in
Uploaded_Files/.

you will write a html form like this :
form method=post enctype=multipart/form-data action=yourscript.pl
input type=file name=file
input type=submit
/form

You will then use CGI to pick up the file, while I will use my own GetForm
module.
Anyway, those data are just going as a scalar data, so you can write them to
anywhere
(If you have the rights to do so) with a file handle which is open for
write.


 And secondly, I'm clueless as to how I can ensure that I'm not uploading a
 virus.  Like I said, all the files will be encrypted, and that by a third
 party whose encryption I (obviously) can't crack.  So there is no
 Content-type or similar denotation.

As you've wrote on the top, you are going to receive an encrypted  file,
so the
encryption is done on the users side, Is that right ? Maybe I don't
understand well,
so I would like to ask what kind of encryption you are using and what kind
of
file you would likely to be received(Binary or Text). For my knowledge,
encrypted
stuff are being somewhat like text, at least no exectutive stuff. So, there
is nothing
to deal with about virus


HTH



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



Re: use lib problem

2003-08-02 Thread Li Ngok Lam

- Original Message - 
From: awarsd [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, August 02, 2003 10:01 PM
Subject: use lib problem


 Hi,

 I have a problem maybe it is normal.
 My problem is with using lib
 now to retrieve my module i do this
 use lib /path/to/Module;
 it works just fine
 but created a configuration file.
 with $dir = '/path/to';
 and when i do
 use lib $dir/Module;
 it give me an error I also tried use lib qw() but same problem is there a
 way to fix the problem??

 regards
 awards


I am not sure, but I bet a guess, use is activated at comiple time, that
means
use $dir/Module is still going earlier than $dir = path/to even the
declaration
of $dir is going earlier than use lib...

In case if you want to do this, you may try ;
package blah;

BEGIN{ $dir = path/to }
use lib $dir/Module;

1;





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



Re: I'm a Nebie to PERL

2003-07-31 Thread Li Ngok Lam
 I'm still puzzled as to how Kenneth managed to get a listing of his
 program out of a Perl command. Let us know how you're getting
 on Kenneth, if you're still watching this thread.

Hi Rob and Kenneth,

I still watching in this thread, but I am not sure did I missed something in
this thread. Because I host my domain and the server had shut down for 
electricity out today.

Kenneth did give me a personal reply and told me he don't want to download
the Perl from activestate because it have to be charged. And my reply was telling 
him that he might looking at something wrong, those charging stuff are KDE, 
making Perl to exe and something like that, but not Perl. Perl is FREE in all versions.

So, thaz more important does Kenneth still is looking in this thread, rather than
me. I am not sure if he gave me further reply or not. But I sure that if he think
have to pay for Perl and giving it up, thaz a LOSS.

Are you still here Kenneth? Feel free to go on if you need any help =)

Cheers


Re: How does CGI.pm handles Content-type: text/html\n\n ?

2003-07-30 Thread LI NGOK LAM
What I actually trying to do is to make the error send to my mail
box ( at this moment ) while my script is running in public. So it does 
a little more then die, but I still trying to keep the command line simple.
looks like unless $something or die  

My code is some what like this :
package CGI::Fatals;

require Exporter;
our @ISA = qw (Exporter);
our @EXPORT = qw /die warn/;

use strict;
use mail2me; # my pm
use ContentType; # my pm

sub die
{ContentType ('text/html') unless $ENV{contenttype};
print @_;
mail2me (@_);
exit (0);
}

sub warn
{ .. }

$main::SIG{__DIE__} = \die;
$main::SIG{__WARN__} = \warn;

 EOS 

I don't know if that's similar to pass the die message to a sub
or which is better. As a beginner (me), I would like to ask, 
which is better, or does my concept or direction is going wrong 
or not.

- Original Message - 
From: drieux [EMAIL PROTECTED]
To: cgi cgi-list [EMAIL PROTECTED]
Sent: Wednesday, July 30, 2003 10:37 AM
Subject: Re: How does CGI.pm handles Content-type: text/html\n\n ?


 
 On Tuesday, Jul 29, 2003, at 18:36 US/Pacific, LI NGOK LAM wrote:
 [..]
 
  So.. if I create my own style of fatalsToBrowser.
  Is that possible to do in this way :
 
 [..]
 
 The reason that 'fatalsToBrowser' and the rest came about
 is because many perl modules are built on 'die' or 'Carp'.
 
 And that 'die' would make the foo.cgi code 'exit abruptly'
 and that would generate a 500 error.
 
 So if the code you are building on does not do a 'die',
 'Carp', 'Croak' - then you really do not need to 'worry about it'.
 
 What you will want to learn about is how to set a local
 signal handler - if you want to write your own. I built
 some stuff ontop of some code that I knew had a series
 of places where it would invoke 'die' - since that code
 was not 'designed for the web' and in those case 'dying'
 was a good thing - so the wrapper call solves it:
 
   sub wrapper_call
   {
 my ($me,$host_port,$uri,$q) = @_;
 
 our ($page,$h) ;
 our $wrapper_flag = 0;
 our $bytes_read = 0;
 
 eval {
 
 local $SIG{'__DIE__'} = sub { $wrapper_flag = 1;} ;
 
 ($bytes_read, $page, $h ) =
 get_from_server($host_port, $uri, $q);
 };
 
 return({ run_time_error =
 Problems connecting to $host_port got status: $@ }
 ) if ( $wrapper_flag );
 
 return({ run_time_error =
 Server $host_port Returned: $h-{dtk_status}})
 if ($h-{dtk_status} !~ /OK/);
 
 return $page if ($bytes_read);
 \$page;
 
   } # end of wrapper_call
 
 In this case the caller either gets the reference to the
 page, or a reference to a hash, that has the 'run_time_error'
 message in it...
 
 This way if the caller wants to report out the error case
 then they can do that, or they can also decide that they
 do not care that the error occurred, and go on to some
 other strategy...
 
 ciao
 drieux
 
 ---
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


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



Re: I'm a Nebie to PERL

2003-07-30 Thread LI NGOK LAM
First, your Perl is not a complete version of Perl. You just have the
compiler of Perl.
You almostly missed some very important modules such as strict, warnings,
CGI..etc.

And second, your Perl is out of dated. for Win32 OS, Perl is up to 5.8.0
now.
So go to
http://www.activestate.com/Products/Download/Register.plex?id=ActivePerl
to download the newest, complete version of Perl.

If you use all default settings of Perl, your Perl is installed at C:\Perl.
Also, some
parameters (PATH) is stored to Windows too (After reboot). So to run your
script,
just start like :

perl C:\somewhere\perlscripts\helloworld.pl

or you can use the direct mode ( I name it ) :

perl ( Press Enter )
print HelloWorld\n;
( Press F6 then Enter, or Ctrl-Z Enter)

your codes will run.

HTH


- Original Message - 
From: KENNETH JANUSZ [EMAIL PROTECTED]
To: PERL Beginners [EMAIL PROTECTED]
Sent: Thursday, July 31, 2003 12:27 AM
Subject: I'm a Nebie to PERL


Platform:  DELL 8200 with XP Prof. SP1 and Oracle 9.2 with the test DB.

I'm new to PERL and need some guidance on getting to run on my PC.  The PERL
files were installed when I implemented Oracle 9.2.  I didn't add any other
code.

My PERL files are located at:

C:\oracle\ora92\Apache\perl\5.00503\bin\MSWin32-x86\
a2p.exe
perl5.00503.exe
perl95.exe
perl.dll
perl.exe
perlglob.exe

The helloworld.pl file is located at:
C:\IDSHome1\j2ee\home\default-web-app\examples\perl\

I copied the helloworld.pl file to the same directory as the perl.exe files.
Then at the C:\ command line I entered:
C:\oracle\ora92\Apache\perl\5.00503\bin\MSWin32-x86\perl helloworld.pl
It ran and just listed the contents of the helloworld.pl file.  PERL ran but
the .pl program didn't.

Any idea how to get this to work?

TIA,
Ken Janusz, CPIM





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



Re: How to read multiple files in the same time ?

2003-07-30 Thread LI NGOK LAM

Not really have any new ideas, I still using looping process to get job
done.
But I have a new direction for this  but still digging. ( feel
chocking just
really like mining ;-) )

perldoc -f fork
perldoc -f pipe
perldoc -m Thread
perldoc perlipc

HTH


- Original Message - 
From: Daniela Silva - Absoluta.net [EMAIL PROTECTED]
To: LI NGOK LAM [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Thursday, July 31, 2003 1:12 AM
Subject: Re: How to read multiple files in the same time ?


 Hi,

 I want to do something similar, read multiple files and
 extract some piece of readed lines for a file or screen,
 to generate te output file could be used unix redirection.

 Do you have new ideas how to work with multiple files ?

 Thanxs


 - Original Message -
 From: LI NGOK LAM [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Saturday, July 26, 2003 3:13 PM
 Subject: How to read multiple files in the same time ?


 How can I do this ? Or could it be done ?

 Open some files ( unknown number of files ), depends on users demand.
 Then start looking for some desired line ( use regex ).

 I have an array to carry the info of matched data ( from which file, which
line ).
 while the $#array is 99 and all files would be closed Result is then print
to screen.

 However, I am trying not to use looping process like :
 open all files, then read a line from file A and try matching,
 then read a line from file B and try matching,,
 then read a line from file C and try matching,
 until eof of all files or $#result == 99.
 and close all file handles...

 I hope folks here can understand what I am asking about.
 Thanks in advise

 Esta mensagem foi verificada pelo E-mail Protegido Terra.
 Scan engine: VirusScan / Atualizado em 24/07/2003 / Versão: 1.3.13
 Proteja o seu e-mail Terra: http://www.emailprotegido.terra.com.br/






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



Re: I'm a Nebie to PERL

2003-07-30 Thread Li Ngok Lam

- Original Message - 
From: Rob Dixon [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, July 31, 2003 5:44 AM
Subject: Re: I'm a Nebie to PERL


[snap]
   It ran and just listed the contents of the helloworld.pl file.  PERL
ran but
   the .pl program didn't.
  
   Any idea how to get this to work?
  
 
  First, your Perl is not a complete version of Perl. You just have the
  compiler of Perl.

 You can't install 'just the compiler'. The compiler and interpreter are
 inseperably joined at the hip.

Sorry, I am just trying to focusing on the missing parts, something like
how to run a perl script without installing Perl... That's not a complete
Perl.


  You almostly missed some very important modules such as strict,
warnings,
  CGI..etc.

 I doubt that strict.pm or warnings.pm would be missing, and there's no
indication
 of that from what Kenneth says. Besides, CGI is of very little importance
outside
 the web hosting world.

Hmm.. I have Oracle 9.2 too, and I found there no else more modules are
bundled.


  And second, your Perl is out of dated. for Win32 OS, Perl is up to
5.8.0
  now. So go to
  http://www.activestate.com/Products/Download/Register.plex?id=ActivePerl
  to download the newest, complete version of Perl.

 Several installations of V4.1 are working fine. Also, reinstalling a later
 version of Perl in a different place (or even the same place) may well
upset
 Oracle.


My opinion is on the Hello World level. The point is no more Oracle, or
Apache or whatever, but Perl herself. If the simplest perl line can't run
correctly,
Whatelse could be on the furture ? Again, that's my opinion. =)

  If you use all default settings of Perl, your Perl is installed at
C:\Perl.
  Also, some parameters (PATH) is stored to Windows too (After
  reboot). So to run your script,
  just start like :

 Do you mean the default for the ActiveState version? Anyway there's no
 reason in general for the installation path to cause problems.


Yes, and Yes, in general.

If one can tell the path or adding path correctly, then no problem in any
case
for sure. So, my starting point is for the simplest, defaultest starting.
Breaking
down the problem's combinations.

[snap]

Sorry if my comments are not Pro enough. But on the way I starting Perl,
unlink Delphi, Turbo C Perl is just looking like an silence army, stand
by
for action, but nothing more is signaled. All the way I was trying, was to
make
the Hello World get success, at my very beginning start time =)

Regards





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



How does CGI.pm handles Content-type: text/html\n\n ?

2003-07-29 Thread LI NGOK LAM
I have read throught the CGI::Carp::fatalsToBrowser...
not quite understand all, but I wonder how does this script
handles the Content-type: text/html\n\n..
So in the some case s(such as warnings) this header line won't re-print ?

TIA


I want to confirm the figure of a form data .

2003-07-29 Thread LI NGOK LAM
While I hit the submit the Submit button on a form ( in a normal way ),
my cgi script is of cause going to read the data.

My question is that does the data I read are all in the same context format ?
Actually my target point is about the CRLF stuff...

Is that what I read are the same even I am using 2 different web server / OS ?
( Apache, Sambar on Win32, Apache on *nix )
and does what I read are all the same whatever the browser I submitting the form?
( Netscape, IE on Win32, Netscape on *nix )

TIA

Re: How does CGI.pm handles Content-type: text/html\n\n ?

2003-07-29 Thread LI NGOK LAM
So.. if I create my own style of fatalsToBrowser.
Is that possible to do in this way :

Make PrintContentT.pm, which is just a simple sub to print the
Content-type:blah but pushing a contenttype =1 to %ENV.

At all the other CGI scripts, use PrintContentT.pm to print the header,
instead, and PrintContentT, it check if exists of contentype. If exists,
won't priint the header again, else, print the header.

Is that Okay  logically ?

TIA


- Original Message - 
From: Wiggins d'Anconia [EMAIL PROTECTED]
To: LI NGOK LAM [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Wednesday, July 30, 2003 8:20 AM
Subject: Re: How does CGI.pm handles Content-type: text/html\n\n ?


 LI NGOK LAM wrote:
  I have read throught the CGI::Carp::fatalsToBrowser...
  not quite understand all, but I wonder how does this script
  handles the Content-type: text/html\n\n..
  So in the some case s(such as warnings) this header line won't re-print
?
 

 Read the docs or the source? Remember this is open source and in this
 case the module is Perl so don't forget you can have a look there too.

 Essentially the module caches the warnings, etc. until either you
 explicitly request they be printed, or until a simulated 'die' (a
 fatalToBrowser) is called at which time if there are warnings and you
 asked for them they are also printed.

 I assume from looking at the source there is no way to prevent a double
 header print on a 'die' after a header, except just don't do it.
 theoretically anything coming after the header is printed shouldn't call
 die anyways, to me that would be an uncaught/unhandle exception which
 shouldn't happen, that is what testing is for :-)...

 http://danconia.org

 On warnings from the docs:

 MAKING WARNINGS APPEAR AS HTML COMMENTS


 It is now also possible to make non-fatal errors appear as HTML
 comments embedded in the output of your program.  To enable this
 feature, export the new warningsToBrowser subroutine.  Since sending
 warnings to the browser before the HTTP headers have been sent would
 cause an error, any warnings are stored in an internal buffer until
 you call the warningsToBrowser() subroutine with a true argument:


 use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
 use CGI qw(:standard);
 print header();
 warningsToBrowser(1);


 You may also give a false argument to warningsToBrowser() to prevent
 warnings from being sent to the browser while you are printing some
 content where HTML comments are not allowed:


 warningsToBrowser(0);# disable warnings
 print script type=\text/javascript\!--\n;
 print_some_javascript_code();
 print //--/script\n;
 warningsToBrowser(1);# re-enable warnings


 Note: In this respect warningsToBrowser() differs fundamentally from
 fatalsToBrowser(), which you should never call yourself!



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





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



Re: Error Variable in Package

2003-07-28 Thread LI NGOK LAM
Sorry I don't understand your question well, but from overall,
I guess that's all about what you want...

###
# Main.pl
use MyGoodies;
my $fedback = $MyGoodies::Error();

###
# MyGoodies.pm
package MyGoodies;
use strict;

sub Error
{check smth and do smth
return 1 if (everything goes fine)
}
1; # Don't miss it, or your package won't run.
###

But that's quite confuse you return 1 while everything
alright, but, your sub name is Error. So the 1 means
OK or Error ?

HTH

- Original Message - 
From: Dan Muey [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, July 29, 2003 12:58 AM
Subject: Error Variable in Package


Howdy List!

Quick question about Packages and an Error Variable.

I have a little package I made and can do;

 use MyGoodies;

 and can export the $MyGoodies::Error from it as well as a function.

What I'm trying to figure out is the best way to have a function return 0 on
failure and set the Error Variable for me to use.

Is this the best way to do that:
package MyGoodies;
...
my $MyGoodies::Error; # declare the variable in the package and Export it
and function().
...
sub function {
undef $MyGoodies::Error; # incase it was given a value before, right?
my $r;
...
...
if(everythign worked) { $r = 1; }
elsif(it failed miserably) { $MyGoodies::Error = It failed Miserably you
loser - $@; }

return $r;
}



In the script:

use MyGoodies;

if(!function()) { print The Sky is falling - $MyGoodies::Error; }
else { print It seems to have worked ok in spite of your ignorance; }

Is all of that the way that should work or am I missing something?

TIA

Dan

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




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



How to read multiple files in the same time ?

2003-07-26 Thread LI NGOK LAM
How can I do this ? Or could it be done ?

Open some files ( unknown number of files ), depends on users demand.
Then start looking for some desired line ( use regex ). 

I have an array to carry the info of matched data ( from which file, which line ).
while the $#array is 99 and all files would be closed Result is then print to screen.

However, I am trying not to use looping process like :
open all files, then read a line from file A and try matching, 
then read a line from file B and try matching,, 
then read a line from file C and try matching,
until eof of all files or $#result == 99.
and close all file handles...

I hope folks here can understand what I am asking about.
Thanks in advise


\r\n\r\n or \n\n or \r\n or \n... What is the term / name for this?

2003-07-26 Thread LI NGOK LAM


How to pass CODE reference in hash?

2003-07-26 Thread LI NGOK LAM
I hope to design an interface of a function like this (not in OO way) :

sub tell_error
{ print Error for @_ }

sub Check_err
{ my %argv = @_; 


 }

Check_err  ( TYPE = [1, 1, \tell_error('Type')], DATA = [ 1, 2, \tell_error 
('Data')] );

In Check_err, I want tell_error ('Type') runs when ${argv{TYPE}}[0]  
${argv{TYPE}}[1] both == 1
but do nothing if that's not the case... $argv{DATA} also doing the same thing...
What I've wrote make tell_error directly run before I go inside Check_err... Any 
pointers ?
Must I pass in a $scalar code and eval it ?

Thanks in advise.




Re: regex problem

2003-07-24 Thread LI NGOK LAM

 I have a number $page = 500;
 now i want to check that if $page matches a word character then make $page
 =1;

$page = 1 unless ( $page =~ /\d/ );
or
$page = 1 if ($page =~ /\D/ );


 so originally i did this
 my $page =500;
 if(($page =~ /\w/) || ($page = 0)){
 $page=1;
 }
 print$page;

\w means [a-zA-Z0-9], 5 is one of them.


 since it always returns $page = 1; then i did this
 if(($page =~ /(\w)/) || ($page = 0)){
 $page=$1;
 }
 so it displayed the word 5, how come 5 is considered as a word??

Since in string 500, the regex catch 5 as a word at the very first,
and the regex action is ended and so $1 carries 5. You then assing
$page =  $1, so $page = 5;


 so to fix it i just did
 if(($page =~ /(\D)/) || ($page = 0)){
 $page=$1;
 }
 And everything worked ok!!

It doesn't ok... since \D means [^0-9], so the block doesn't
run at all, so $page still = 500 So, if $page = END, then,
you will fine $page = E after this block.

Note : The $DIGIT means the sequence for results from catching
matched pattern in the blankets you assigned. It means, $1 is the
first match , $2 is the second match, and so on...

$page = 500;

$page =~ /(\d)(\d)(\d)/;
$page = $3 . $1;
print $page ; # you got 05, the last and first digit...

HTH




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



Re: Checking for a directory

2003-07-24 Thread LI NGOK LAM
if ( -d $path ) { print Directory }
elsif ( -f $path ) { print File }
else { print Not exist }

HTH

- Original Message - 
From: Rus Foster [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, July 24, 2003 8:39 PM
Subject: Checking for a directory


 Hi All,
 Just trying to work out the code to test if a path is a directory or file.
 Looked over the stat function but doesn't quite seem right. Can someone
 give me a clue

 thanks

 Rus

 -- 
 www: http://jvds.com   | Virtual Servers from just $15/mo
 MSNM: [EMAIL PROTECTED] | Totally Customizable Technology
 e: [EMAIL PROTECTED]   | FreeBSD  Linux
10% donation to FreeBSD.org on each purchase

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





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



Re: Checking for a directory

2003-07-24 Thread LI NGOK LAM
Yep ! =)

Even though I can't imagine what a path is not file or directory would imply
more then not exist. But I agree to check the existence for a path by -e
is the safest operation.


- Original Message - 
From: [EMAIL PROTECTED]
To: LI NGOK LAM [EMAIL PROTECTED]; Rus Foster [EMAIL PROTECTED];
[EMAIL PROTECTED]
Sent: Thursday, July 24, 2003 11:06 PM
Subject: Re: Checking for a directory



 
 On Thu, 24 Jul 2003 23:00:17 +0800, LI NGOK LAM [EMAIL PROTECTED] wrote:

  if ( -d $path ) { print Directory }
  elsif ( -f $path ) { print File }
  else { print Not exist }
 

 Not exist is misleading, just because a file is not a 'plain' file or a
'directory' does *NOT* indicate non-existence.  Existence should be checked
explicitly with the -e operator.

 http://danconia.org

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





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



Re: Checking for a directory

2003-07-24 Thread LI NGOK LAM
Thanks for this great lesson, I will take account for this on my furture =))


- Original Message - 
From: [EMAIL PROTECTED]
To: LI NGOK LAM [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Friday, July 25, 2003 12:17 AM
Subject: Re: Checking for a directory


 
 On Thu, 24 Jul 2003 23:20:20 +0800, LI NGOK LAM [EMAIL PROTECTED] wrote:

  Yep ! =)
 
  Even though I can't imagine what a path is not file or directory would
imply
  more then not exist. But I agree to check the existence for a path by -e
  is the safest operation.
 

 Since you asked ;-) from perldoc -f -e 

 -l  File is a symbolic link.
 -p  File is a named pipe (FIFO), or Filehandle is a pipe.
 -S  File is a socket.
 -b  File is a block special file.
 -c  File is a character special file.

 -f implies that a file is 'plain' aka not really special in any way. Files
come in many different flavors not only based on their contents, though this
is largely system dependent. Most windows and old Mac OS users will go their
whole life not knowing about these (I said not knowing about and most,
not that they don't exist there, personally I am not sure they do or don't,
but then I don't much care either :-) )...

 If you have access to a fairly standard unix system try:

 perl -e 'if (-f /dev/tty0) { print File is plain.\n; } else { if (-e
/dev/tty0) { print File is not plain, but does exist.\n } }'

 The issue was not with whether -f will tell you of non-existence, because
it will, but by using your 'else' block you were implying non-existence by
not being a plain file and not a directory, which is an incorrect (strictly
speaking) implication.

 http://danconia.org




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



Re: Comparing two files

2003-07-22 Thread LI NGOK LAM
First, I would ask, how many lines in each file ? under 100 ? above 1 ?
because that effect to choose the tatic for making things done.

Well, I assume there is reasonable to carry 1 names and each name not
longer then 20 character ( consumed about 200KB, still acceptable )
and I will do so :

use strict;
my (@names, @matches) ;

# Reading and record names into @names
open my $A, FileA;
while (my $line = $A)
{ my ($name, $waste ) = split /,/, $line, 2;
push (@names, $name)
}close $A;

# Find matching name in B and record them into @matches
open my $B, FileB;
while (my $line = $B)
{ my ($name, $waste )  = split /,/, $line, 2;
push (@matches, $name ) if ( grep /$name/, @names )
} close $B;

# Print results
print $_br\n for (@matches);
# Omit br if the printout is not returned as HTML format;

Remarks :
1. Code not been tested.
2. I suppose your line format is exactly same as you provided.

HTH






- Original Message - 
From: Cynthia Xun Liu [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, July 22, 2003 11:15 PM
Subject: Comparing two files


 Hi,

 Could anybody help me with the code of comparing files? I have two files
 :
 File A: name, info1, info2...
 FileB: name, info1, info2...
 I want to print out all the lines in File A with the same names as in
 File B.
 Thanks.


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





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



Re: Reg Exp Help...

2003-07-22 Thread LI NGOK LAM
- Original Message - 
From: [EMAIL PROTECTED]
To: James Kelty [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Wednesday, July 23, 2003 1:21 AM
Subject: RE: Reg Exp Help...



 
 On 22 Jul 2003 09:15:29 -0700, James Kelty [EMAIL PROTECTED] wrote:

  I know that this is a common request, but I have a question about
  parsing an email box. I have a UW IMAP box, and I am trying to extract
  all the emails where the line starts with From: blah blah. Now, getting
  those lines isn't the issue, but since each email is a little different,
  I am having a problem. Given this list, how would I extract JUST the
  email address?
 
  From: James Kelty [EMAIL PROTECTED]
  From: [EMAIL PROTECTED]
  From: [EMAIL PROTECTED]
 

 snipped 

 

 This is a relatively complex task since e-mail addresses can come in so
many different forms and contain so many different types of values. Your
best bet may be to either use a module for parsing the whole message which
is always advised, or look at the source for one of the better message
header parsing modules to determine  how they are doing it.  Sorry this is
such a non-specific answer, but rather than suggesting a way to poorly
re-invent the wheel, I prefer suggesting that this should be avoided


Hmm The OP seems not trying to do somewhat Email::Valid,
but to fetch the mail address from a line only... ie, try to cut out
something not expect to left...  I hope I bet it correct..

sub filter
{my $line = shift; chomp ($line);
chop ($line) if ($line =~ /[^\w]$/; # mail must end with tld or
country code
my ($waste, $mailAd) = split / /, $line ; # So 'From: ' is kicked
out
$mailAd =~ s/^[^\w]//; # so '' or '' will be kicked out from head
too...
# Perhaps the regex above can be [^\w|\\] if [EMAIL PROTECTED] is
valid
# I am not sure
return $mailAd
}

Code not tested, but HTH



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



Re: print command help

2003-07-22 Thread LI NGOK LAM

- Original Message - 
From: Josh Corbalis [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, July 23, 2003 2:24 AM
Subject: print command help


 I'm writing a webmin module and I'm trying to add a search function in
right
 now but after I search for it and try to display the output it has a
problem
 with the way the output is formatted.

 print searchtestgimp10; will print searchtest10
 print searchtest gimp10; will print searchtest gimp10

 I don't understand why it will not print any of what is inside the  if
what
 is right next to the  is a letter. Numbers and spaces will print
everything
 on the line but a letter discards everything in the brackets. I've tried
to
 escape the special meaning of the  characters when used with a word but
it
 didn't work. Does anybody out there have any insight into this problem?


In Perl,  means nothing in string, it only means :

open FH, file.txt; $line = FH; close FH;
it reads one line from the file.txt and give the value to $line.

or

open FH, file.txt; @lines = FH; close FH;
it reads all the context to array (@lines) from file.txt,
elems are splitted by each \n ( or \r\n ) from file.txt

So, what your trying to looking for might be :

print `searchtest gimp 10`; # exec a shell command
or
print searchtest $val1 $val2;

HTH




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





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



How to check data type in @_ ?

2003-07-21 Thread LI NGOK LAM
I am going to write a sub accept different types of data type.
My interface is some what like this :

$ret = mySub ( \%hash );
$ret = mySub ( [EMAIL PROTECTED] );
$ret = mySub ( \$calar );
$ret = mySub ( \Sub );
$ret = mySub ( $calar );
$ret = mySub ( %hash );
$ret = mySub ( @rray );

Is there anyway I can check what is the data type 
for each element inside @_ ?

TIA

How to call / push an elem to a hash of array ?

2003-07-18 Thread LI NGOK LAM
my (%LIST, @other_list);

@other_list = ( Unknown Length Data Elems );

foreach my $col (@lists)
{
for (@other_list)
{  
if ( exist $LIST{$col}[0] ) { Do_smth_2 }  # But ERROR either

What should I write here ? So can push vars to $LIST{$col}
}
}


Thanks in advise


Is there anyway to modify my bios clock by perl ?

2003-07-16 Thread LI NGOK LAM
Is there anyway to modify my BIOS clock by Perl ?
and more, is there anyway to adjust my BIOS clock, so
to sync. with other time servers ?

TIA

How to run a shell command but not waiting for the result ?

2003-07-14 Thread LI NGOK LAM
I've tried to use exec, system, and ``. And also with and without $| = 1;
but seems unable to do what I want.

What I want to do is suppose like this :

print Start;
exec notepad;
print End;

but I found my results are :

If I can see End, the notepad won't come,
If I can run the notepad, I can't see the End
until I close the notepad.

So what can I do to make it possible to run the notepad, 
but then just leave it alone and go on with the rest of the
code ?

TIA

Re: silly question

2003-07-09 Thread LI NGOK LAM
I would say the other name of socket programming is network programming.
The socket modules will act as a interface to deal with other machines, such
as
FTP, telnet, smtp, pop, etc.
I would recommand Network Programming with Perl, by Addison Weskey,
but that's a book, not a site =)


- Original Message - 
From: john tarn [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, July 10, 2003 12:09 AM
Subject: silly question


 i am still a novice in perl so forgive me for this simple question.
 what is socket programming? what do sockets do? is there a site
 that can explain them to me? thanks

 john


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





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



Regex or Looping problem ?

2003-06-29 Thread LI NGOK LAM
snipped some annoying code

foreach my $result(@filelist)  # a script snipped was given a file list 
   { chomp ($result); 
my $com_result = $result;
$com_result =~ s/^$root//; 
# $root was a defined var, where using to target the below filter focus 
# on the rest of parameter besides from the common root.

my $skip_this = 0; if (@FFW)  # FFW stands for Filter File With
{  foreach my $filter_key (@FFW)
 { 
  $skip_this = 1 if ($com_result =~ /$filter_key/i);
  last if $skip_this;
} } next if $skip_this;

my $skip_this = 0; if (@FFO) # FFO stands for Filter files without
{  foreach my $filter_key (@FFO)
 { $skip_this = 1 if ($com_result !~ /$filter_key/i);
  last if $skip_this;
} } next if $skip_this;

push @ret, $result if ($result);
   }

snipped rest of code

The problem is if I give @FFW or @FFO a values like ('.txt', '.doc')
the regex won't take care of the '.', I have try to modify like :
$com_result =~ /$-{filter_key}/i
I then get my job done with a new script, but unable to done the job 
when back to this script. So I wonder if there is something wrong 
with the 'next' statement . Anyway, I just can't figure out what's going 
wrong, any pointers ?

Thanks





How to write to a file at certain position?

2003-06-26 Thread LI NGOK LAM
Is there any methods or documents I can refer to learn how to write a file
at any desire position with any length without to write the whole again ?
I mean, I dont want to write to a new file, kill the old file, rename the new file, 
or read the old file, modify it and rewrite the old file etc...

for example, for a mp3 file, I can modify the tags by its header location.
So I just want to overwrite some bytes to the head of the file, then the rest 
are just remain the same

Any suggestion are very apperciate =)
Thanks in advice




Re: How to write to a file at certain position?

2003-06-26 Thread LI NGOK LAM
 
 You want seek(), and possibly tell().
 
 perldoc -f seek
 

Thanks for reply, but seems I have to clarify my question.
'seek' and 'tell' only helping me to target my position within 
a file handle. 

Say, if I have a 1MB file, and I just want to over write
bytes from 0 to 1000 byte then my job is done, file is supposed 
to be saved. I  want to avoid to rewrite the rest 900KBs again. 

Would you imagine what I am asking ?

Welcome for any further suggestions.





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



Re: How to write to a file at certain position?

2003-06-26 Thread LI NGOK LAM


 You will probably want to open the file with a mode of +.


Yes and thank you! That does what I want now. Thank you very much !!

But I found new problem now. I did what I want if I try on a bitmap file,
but for text file, my new contents will overwrite the whole file, what's
that about
or where I should refer to now?





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





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



Re: How to write to a file at certain position?

2003-06-26 Thread LI NGOK LAM

 #/!perl -w
 use strict;
 use IO::File;

 my $offset = 3;
 my $file_binary = fg;
 sysopen(OUTFILE, out.txt, O_WRONLY) or print Couldn't open file for
 read/write ($!)\n;
 binmode OUTFILE;
 sysseek OUTFILE, $offset, 0;
 syswrite OUTFILE, $file_binary, length($file_binary);
 close OUTFILE;


 out.txt goes from 1234567 to 123fg67

Thank you veeery much ! It does what I want too, but I wonder why we have to
make it a binmode
while we are dealing with a text file ? Is that we must treat the FH is a
binary source for
whatever + or sysread/write ?



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



Re: accessing the string from system(ls -al) / browse dir script

2003-04-06 Thread Li Ngok Lam


 I'm trying to put the string from the system(ls -al) into a variable.  

@list = `ls -al`;

 It simply prints to the page and puts 1 in the variable.

What's that mean '1' anyway ?




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



Re: random sub returns same results...

2003-04-05 Thread Li Ngok Lam
perldoc -f srand

- Original Message - 
From: meriwether lewis [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, April 05, 2003 10:09 AM
Subject: random sub returns same results...


 Hi Gurus!
 
 I have the following sub which creates a random 
 string. Each time I call the sub in my perl 
 script it returns a random string which is fine. 
 The problem is every time I run the script the 
 same strings are returned. I'm running perl 
 5.001 on Windows 2000.
 
 sub RandomStr
 {
 my $i=0;
 my $str=;
 foreach(0..9,a..z,A..Z)
 {   $i++;
 $arr[$i]=$_
 }
 for($j=0;$jrand(30);$j++)
 {
 $str.=$arr[rand(58)+1]
 }
 return $str;
 }
 
 So if I run my script calling the above three 
 times I get:
 
 brLNh
 96
 x9k
 
 If I run it again I get the same three strings.
 Why?
 Is there a better way to get a random string?
 
 Thanks!
 
 Meriwether
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

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



Re: How to measure Array or Hash's byte size ?

2003-04-04 Thread Li Ngok Lam



 What's about:

 my @foo = ( '1', '2' ,'3' );
 my $size = $#foo + 1;

you can simplify this by : $size = scalar @foo;

 print table size $size\n;

 Ouput:
 table size 3

TIA, but this is not what I want... because each element is assumpted not in
same length... ie.. I am not going to get the table size...


 Vincent

 -Original Message-
 From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
 Sent: Thursday, April 03, 2003 5:14 PM
 To: [EMAIL PROTECTED]
 Subject: How to measure Array or Hash's byte size ?


 My method  sounds stupid, but still works :

 my @array = ('123', 'abc', 'def',  1..9);
 my $len_of_array =  0 ;
 foreach my $elem(@array)
 {$len_of_array += length($elem) }
 print $len_of_array ; # I got '18'

 my %hash = (1=2, 2=3, 3=4);
 foreach my $key(keys(%hash))
 {$len_of_hash += length($key) + length($hash{$key}) }
 print $len_of_hash ; # I got '6'

 I suppose there should be another better and faster way to done this,
 any suggestion ?

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




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



How to measure Array or Hash's byte size ?

2003-04-03 Thread Li Ngok Lam
My method  sounds stupid, but still works :

my @array = ('123', 'abc', 'def',  1..9);
my $len_of_array =  0 ;
foreach my $elem(@array)
{$len_of_array += length($elem) }
print $len_of_array ; # I got '18'

my %hash = (1=2, 2=3, 3=4);
foreach my $key(keys(%hash))
{$len_of_hash += length($key) + length($hash{$key}) }
print $len_of_hash ; # I got '6'

I suppose there should be another better and faster way to done this, 
any suggestion ?

Re: How to measure Array or Hash's byte size ?

2003-04-03 Thread Li Ngok Lam
 I don't know if it is better or faster, but it is shorter.  :-)
 
 $ perl -le'
 my @array = ( 123, abc, def, 1 .. 9 );
 my $len_of_array = do { local $; length @array };
 print $len_of_array;
 '
 18
 
 $ perl -le'
 my %hash = ( 1 = 2, 2 = 3, 3 = 4 );
 my $len_of_hash = do { local $; length @{[%hash]} };
 print $len_of_hash;
 '
 6
 

if just shorter, I guess I will do in this  way :
print length ( join , @array);
print length ( join , %hash);

But I am not sure if this will eat up (much) more of my memory


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



Re: Trying to block out BGCOLOR

2003-03-21 Thread Li Ngok Lam
What about the user says :

body
text=#123456
bgcolor=#aabbcc

or
body bgcolor='#123456'
or
body bgcolor=
red

Anyway, the bgcolor can be formed or change again via javascript or CSS.
I mean, blocking bgcolor in body tag cannot solve your potential problem.

But you may find someway to put this in your body tag :
background=white_block.jpg,
as wallpaper goes upper than bgcolor or using javascript :
document.bgColor='ff'; // not sure if this run on NS too

In  Perl way, I can't provide any code here because I don't know when you
want to
block that bgcolor .. On the print time ? or at the html file's landing
time...

Anyway, if you just don't want your users to use bgcolor in the body tag,
just simply $line =~ s/bgcolor/whatever_you_like/;

Once the browser don't understand something not in list of its properties,
will be ignored... I mean, don't care on the RHS of =, but the LHS, unless,
you are trying to fulfill W3C's html standard.

Regards,
Perl Beginner

 no, the problem is on the other side of the = token

 eg:
 body bgcolor=#99
 or
 body bgcolor=red
 or
 body bgcolor=red

 and he would like to make that

 body


 I would of course go with say:

 #
 #
 sub un_colour {
 my ($line) = @_;

 $line =~ s/\s*bgcolor=(?)([^\s]+)(?)//gi ;

 $line;
  } # end of un_colour


 since the middle element needs to guard against

 a. 
 b. 
 c. white space

 ciao
 drieux

 ---


 my $l1 = 'bodybgcolor=#99 other=fred
 stuff here
 table bgcolor=blue
 ';
 my $l2 = 'body bgcolor=red other=fred';
 my $l3 = 'body bgcolor=red other=fred';

 foreach my $tag ( $l1 , $l2 , $l3 )
 {

 my $answer =  un_colour($tag);

 print #---\n$answer\nfor $tag \n;
 }

 #
 #
 sub un_colour {
 my ($line) = @_;

 $line =~ s/\s*bgcolor=(?)([^\s]+)(?)//gi ;

 $line;

 } # end of un_colour


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




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



multipart form problem

2003-03-07 Thread Li Ngok Lam
Hi all, I am totally new about CGI and Perl, and now, I've facing my first problem so 
hope  somebody
can help...

I have this html code :

form action=getfile.pl method=post enctype=multipart/form-data
input type=file name=file
input type=submit
/form

and I have this Perl code :

 #!C:/Perl/bin/perl.exe
print Content-type: text/html\n\n;
print OK;

my problem sounds strange ... when I am uploading a text file, result comes fine.
but when I upload a binary file ( *.exe *.jpg), my browser directly point me to 
that Cannot open page die page. 

Note, the Cannot open page die page prompts immediately when I click on Submit,
It doesn't looks like other script errors, some delay  will taking place before take 
me to
that die page.

I also tried the fatalsToBrowser (the piece from CGI.pm), but still no use. The browser
sounds take me to that die page without thinking...  Both IE and NS result the same on 
both ME and Win2K also...

Why ? Please help. Thank you.






Testing.....

2003-03-07 Thread Li Ngok Lam


Testing.....

2003-03-07 Thread Li Ngok Lam