about Excel modules

2005-12-19 Thread Jennifer Garner
hi,Lists,

I use Spreadsheet::WriteExcel /  Spreadsheet::ParseExcel modules to access
and write excel files.
The questions is, how to move the cursor in some a column to the top of next
column?Thanks.

Merry  Xmas! :-)


Re: How to promote the efficiency

2005-12-08 Thread Jennifer Garner
Sorry, the file is more than 900M, too large to download.
I have run it for one day,and still have nothing to output.Crying...
I think maybe some arithmetic is useful for me,and now I'm thinking over it.


On 12/8/05, Xavier Noria [EMAIL PROTECTED] wrote:

 On Dec 8, 2005, at 9:37, Jennifer Garner wrote:

  hi,lists,
 
  I have a file which is so large,which looking as:
 
  61.156.49.18:28360
  61.183.148.130:27433
  222.90.207.251:25700
  202.117.64.161:25054
  218.58.59.73:24866
  221.233.24.9:22507
  222.187.124.4:21016
  ...
 
  and more than 4500 lines.

 Is the time spent on the file process or on printing to the console?
 If on the file process, would it be possible to put the file
 somewhere for download so we can benchmark alternatives against real
 data? If on printing try redirecting to a file with  for instance.

 -- fxn


 --
 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 promote the efficiency

2005-12-08 Thread Jennifer Garner
Thank you for John.I think your method would be much faster than mine.
Now I'm going to rewrite this program with C language,but I'll test it using
all the ways given by everyone here.Thanks.


On 12/8/05, John W. Krahn [EMAIL PROTECTED] wrote:

 Jennifer Garner wrote:
  hi,lists,

 Hello,

  I have a file which is so large,which looking as:
 
  61.156.49.18:28360
  61.183.148.130:27433
  222.90.207.251:25700
  202.117.64.161:25054
  218.58.59.73:24866
  221.233.24.9:22507
  222.187.124.4:21016
  ...
 
  and more than 4500 lines.
 
  the part after : is no use for me,I only need the IP.
 
  for each IP,such as '218.58.59.73', I want to get this result:
 
  218.58.59.  xxx yyy xxx+yyy
 
  I want to know how many IP are in the range of '218.58.59.1' to '
  218.58.59.127',this is 'xxx';
  and how many IP are in the range of '218.58.59.128' to '218.58.59.254
 ',this
  is 'yyy'.
 
  I write this code:
  open (FILE,$file) or die $!;
  while(FILE)
  {
  next if /unknown/o;
  next if /^192\.168\./o;
  chomp;
  my ($ip,$num) = split/:/,$_;
  if ($ip = ~  /^(\d+\.\d+\.\d+\.)(\d+)/o){
  my ($net,$bit) = ($1,$2);
  $total{$net}{low}{$bit} = 1 if $bit  128;
  $total{$net}{high}{$bit} = 1 if $bit =128 and $bit
 
  255;
  $total{$net}{total}{$bit} = 1;
  }
  }
  close FILE;
 
  foreach (sort { scalar keys %{$total{$b}{total}} = scalar keys
  %{$total{$a}{total}} } keys %total)
  {
  print RESULT $_,\t,scalar keys %{$total{$_}{low}},\t,
scalar keys %{$total{$_}{high}},\t,scalar keys
  %{$total{$_}{total}},\n;
  }
 
 
  but it's too slow for me to wait the result.How can I get it more
 effective
  and run less time?thanks.

 This is quite a bit faster then your version:

 open FILE, '', $file or die Cannot open '$file' $!;

 my ( %low, %high, %total );
 while ( FILE ) {
next if /unknown/;
next if /^192\.168\./;

next unless /^(\d+\.\d+\.\d+\.)(\d+)/;

if ( $2  128 ) {
$low{ $1 }++;
}
else {
$high{ $1 }++;
}

$total{ $1 }++;
}

 close FILE;


 for ( sort { $total{ $b } = $total{ $a } } keys %total ) {
print RESULT $_\t, $low{ $_ } || 0, \t, $high{ $_ } || 0, \t,
 $total{ $_ }, \n;
}


 John
 --
 use Perl;
 program
 fulfillment

 --
 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 promote the efficiency

2005-12-08 Thread Jennifer Garner
Hi,John

I think you have  understanded wrongly with my meaning.
The result of  $low{ $1 }++ is no use for me.I just want the frequency of IP
exists.
For example, if there are some IPs exists in '22.33.44.0' :

22.33.44.11
22.33.44.22
22.33.44.22
22.33.44.33
22.33.44.33
22.33.44.44
22.33.44.55

Now I only want  the uniq times of all IP appeared,this is 5.

On 12/8/05, John W. Krahn [EMAIL PROTECTED] wrote:

 Jennifer Garner wrote:
  hi,lists,

 Hello,

  I have a file which is so large,which looking as:
 
  61.156.49.18:28360
  61.183.148.130:27433
  222.90.207.251:25700
  202.117.64.161:25054
  218.58.59.73:24866
  221.233.24.9:22507
  222.187.124.4:21016
  ...
 
  and more than 4500 lines.
 
  the part after : is no use for me,I only need the IP.
 
  for each IP,such as '218.58.59.73', I want to get this result:
 
  218.58.59.  xxx yyy xxx+yyy
 
  I want to know how many IP are in the range of '218.58.59.1' to '
  218.58.59.127',this is 'xxx';
  and how many IP are in the range of '218.58.59.128' to '218.58.59.254
 ',this
  is 'yyy'.
 
  I write this code:
  open (FILE,$file) or die $!;
  while(FILE)
  {
  next if /unknown/o;
  next if /^192\.168\./o;
  chomp;
  my ($ip,$num) = split/:/,$_;
  if ($ip = ~  /^(\d+\.\d+\.\d+\.)(\d+)/o){
  my ($net,$bit) = ($1,$2);
  $total{$net}{low}{$bit} = 1 if $bit  128;
  $total{$net}{high}{$bit} = 1 if $bit =128 and $bit
 
  255;
  $total{$net}{total}{$bit} = 1;
  }
  }
  close FILE;
 
  foreach (sort { scalar keys %{$total{$b}{total}} = scalar keys
  %{$total{$a}{total}} } keys %total)
  {
  print RESULT $_,\t,scalar keys %{$total{$_}{low}},\t,
scalar keys %{$total{$_}{high}},\t,scalar keys
  %{$total{$_}{total}},\n;
  }
 
 
  but it's too slow for me to wait the result.How can I get it more
 effective
  and run less time?thanks.

 This is quite a bit faster then your version:

 open FILE, '', $file or die Cannot open '$file' $!;

 my ( %low, %high, %total );
 while ( FILE ) {
next if /unknown/;
next if /^192\.168\./;

next unless /^(\d+\.\d+\.\d+\.)(\d+)/;

if ( $2  128 ) {
$low{ $1 }++;
}
else {
$high{ $1 }++;
}

$total{ $1 }++;
}

 close FILE;


 for ( sort { $total{ $b } = $total{ $a } } keys %total ) {
print RESULT $_\t, $low{ $_ } || 0, \t, $high{ $_ } || 0, \t,
 $total{ $_ }, \n;
}


 John
 --
 use Perl;
 program
 fulfillment

 --
 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 promote the efficiency

2005-12-08 Thread Jennifer Garner
Now I have resolved this problem,still using perl.
Just a little modification to that code,shown as below:


foreach my $file (@files)
{
open (FILE,$file) or die $!;
while(FILE)
{
next if /unknown/o;
next if /^192\.168\./o;
next unless /^(\d+\.\d+\.\d+\.)(\d+)/o;
if ( $2  128 ) {
$low{$1}{$2}=1;
   }

$total{$1}{$2}=1;

}
close FILE;
}


open (RESULT,,allIP.txt) or die $!;

for ( sort { scalar keys %{$total{$b}} = scalar keys %{$total{$a}} } keys
%total ) {
   print RESULT $_\t, scalar keys %{$low{$_}}, \t,
   (scalar keys %{$total{$_}}) - (scalar keys %{$low{$_}}), \t,scalar
keys %{$total{$_}}, \n;
  }

close RESULT;


Now it run very fast,get the results in 20 minutes.Thanks for all.


On 12/9/05, John W. Krahn [EMAIL PROTECTED] wrote:

 Jennifer Garner wrote:
  Hi,John

 Hello,

  I think you have  understanded wrongly with my meaning.
  The result of  $low{ $1 }++ is no use for me.I just want the frequency
 of IP
  exists.
  For example, if there are some IPs exists in '22.33.44.0' :
 
  22.33.44.11
  22.33.44.22
  22.33.44.22
  22.33.44.33
  22.33.44.33
  22.33.44.44
  22.33.44.55
 
  Now I only want  the uniq times of all IP appeared,this is 5.

 Do you mean something like this:

 use Socket;

 my ( %seen, %total );
 while ( FILE ) {
next if /unknown/;
next if /^192\.168\./;

next unless /^(\d+\.\d+\.\d+\.\d+)/;

my $ip = inet_aton $1;

$total{ $ip  \xFF\xFF\xFF\0 }++ unless $seen{ $ip }++;
}

 close FILE;

 for ( sort { $total{ $b } = $total{ $a } } keys %total ) {
print RESULT inet_ntoa( $_ ), \t, $total{ $_ }, \n;
}




 John
 --
 use Perl;
 program
 fulfillment

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





which is more effective between map and foreach?

2005-12-06 Thread Jennifer Garner
Hi,lists,

I have a small script,when it run,it generate much more lines and put them
into a file.
The code for printing I writed:

 map { print RESULT $_,:,$ips{$_},\n }
sort { $ips{$b} = $ips{$a} } keys %ips;

Certainly, I can write that code with foreach style.
I want to know which method is more effective between foreach and map?

ps: the result file is very large,shown as below:

$ wc -l  loginIP.re.152
9260754


Thanks.


Re: which is more effective between map and foreach?

2005-12-06 Thread Jennifer Garner
Thanks for all.maybe I would use Benchmark.pm http://benchmark.pm/ to find
out a good choice.

And, I have another syntax question here. I can't know clearly the
difference between eval  and eval {}. I have run perldoc -f eval and
read it,but still can't know clearly.Can you help me on this?

On 12/6/05, Bob Showalter [EMAIL PROTECTED] wrote:

 Jennifer Garner wrote:
  Hi,lists,
 
  I have a small script,when it run,it generate much more lines and put
  them
  into a file.
  The code for printing I writed:
 
   map { print RESULT $_,:,$ips{$_},\n }
  sort { $ips{$b} = $ips{$a} } keys %ips;

 I would write it like this:

print RESULT $_:$ips{$_}\n
for sort { $ips{b} = $ips{$a} } keys %ips;

 
  Certainly, I can write that code with foreach style.
  I want to know which method is more effective between foreach and map?

 I don't know without benchmarking, but map() is typically used to build
 a resulting



Re: A Strange Syntax

2005-12-06 Thread Jennifer Garner
Thanks for Adriano Ferreira.Your explaination is good for me.I have known
that.

On 12/7/05, Adriano Ferreira [EMAIL PROTECTED] wrote:

 On 12/5/05, Jennifer Garner [EMAIL PROTECTED] wrote:
  As we know, $::{sym} == *main::sym, it's a typeglob.
  but what is **main::sym? and the same,what is *{$glob}?thanks.

 **main::sym is a syntax error, but *{*main::sym}==*main::sym.

 But don't be fooled by the equality $::{sym} == *main::sym. It just
 means they numerically compare the same. Taking references you get
 that $::{sym} returns a scalar and *main::sym a glob.

 $ perl -e 'print \($::sym, *main::sym)'
 SCALAR(0x1002f094)GLOB(0x10010fa8)

 So *{$glob} is the way to tell Perl to go from the scalar to the glob,
 when we'll be able to access its HASH part.

 That's why

 $ perl -e 'our %sym = (name = flower); print
 ${*{$::{sym}}{HASH}}{name};

 prints flower, but

 $ perl -e 'our %sym = (name = flower); print ${$::{sym}{HASH}}{name};

 prints nothing ($::{sym}{HASH} returns undef). As Wiggins wisely said,
 $sym-{name} is more sane.



A Strange Syntax

2005-12-05 Thread Jennifer Garner
Hi,lists,

Seeing this code please:

our %sym = (
name = 'flower',
age  = 23,
);

print ${*{$::{sym}}{HASH}}{name};

The result of printing is : flower.

How to analyse the last sentence of that code?Thanks.


Re: A Strange Syntax

2005-12-05 Thread Jennifer Garner
${*{$::{sym}}{HASH}}{name};

As we know, $::{sym} == *main::sym, it's a typeglob.
but what is **main::sym? and the same,what is *{$glob}?thanks.


On 12/6/05, Flemming Greve Skovengaard [EMAIL PROTECTED] wrote:

 Wiggins d'Anconia wrote:
 
  Now that you understand it, replace it with $sym-{name} so the next
  person doesn't have to ask. Unless you are using a really old Perl.
 

 Actually that should be *sym-{name} instead of $sym-{name} ( or
 %sym-{name}
 but that's deprecated ).
 Else you get Variable $sym is not imported at ... when using 'use
 strict;'
 ( as you should ).

 --
 Flemming Greve SkovengaardThe prophecy of the holy
 Norns
 a.k.a Greven, TuxPowerThe world is doomed to die
 [EMAIL PROTECTED]   Fire in the sky
 4112.38 BogoMIPS  The end is coming soon

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





what use of the closure?

2005-12-02 Thread Jennifer Garner
Hi,lists,

I usually meet some problems of closure when do development under mod_perl.
Can anyone tell me that what use of a closure in perl?thanks.


Re: recursive search

2005-12-02 Thread Jennifer Garner
#!/usr/local/bin/perl
#
# recurs.pl
#
# This script executes recursively on subdirs the command you supply as a
parameter
#
# Run program -h to see the run options
#
# Last modified:  Apr 10 1997
# Author: Bekman Stas   [EMAIL PROTECTED];
#   [EMAIL PROTECTED];

$|=1;


# Set here the pattern extensions of your image files

# Usage

(@ARGV == 1 ) || die (Usage: recurs.pl [-h]  \n\t-h this help\n\n);

$command=$ARGV[0];
#$command=~s/(.*)/'$1'/;

recursive();


# Subroutine recursive goes recursively down at the dir tree and
# and runs the $ARGV[0] for you. After comming to the end it's coming back
up
# at the tree.


sub recursive {
system($command);
#print $command\n;
#die;
foreach $dir (*;) {
if (-d $dir) {
#print $dir\n;
chdir $dir;
recursive();
chdir ..;
}
}
}


On 12/2/05, The Ghost [EMAIL PROTECTED] wrote:

 I want to know how many new line chars there are in all files in a
 directory (and it's subdirectories).  What's the best way?

 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: what use of the closure?

2005-12-02 Thread Jennifer Garner
Thanks.Now I'm skilled to handled closure problems when developing under
mod_perl environment,including Apache::Register,Apache::DBI,and something
ohters.The thing I want to know is that if a closure is useful or not in
common perl program?

On 12/3/05, Dermot Paikkos [EMAIL PROTECTED] wrote:

 On 2 Dec 2005 at 23:44, Jennifer Garner wrote:

  Hi,lists,
 
  I usually meet some problems of closure when do development under
  mod_perl. Can anyone tell me that what use of a closure in
  perl?thanks.

 Have a look at this doc. It is as full an explanation as your'll ever
 get.

 http://perl.apache.org/docs/general/perl_reference/perl_reference.html

 Dp.





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





Re: Re: how to get file's creation time

2005-11-29 Thread Jennifer Garner

Thanks for Schwartz and Jay.I have known something from your words.

On 28 Nov 2005 08:48:28 -0800, merlyn@stonehenge.com (Randal L. Schwartz) wrote:
 Jay == Jay Savage [EMAIL PROTECTED] writes:
 
 Jay It depends on what you mean by creation. stat() on POSIXish systems
 Jay returns ctime, which is the inode creation time,
 
 Nope.  Inode *change* time.  Will update any time you write to the
 file, or change any metadata (owner, permissions, number of links
 [including renaming], other timestamps).
 
 Jay  which is the time the
 Jay physical location on disk was first written to (actually, these days
 Jay it's the time the vnode was fist written to, but you don't really
 care
 Jay that much about disk geometry, do you?). The time will not be
 Jay preserved across relocations (i.e. mv and cp will destroy it),
 Jay although many archivers reinstate the file's original ctime when
 files
 Jay are restored from backup.
 
 This is not possible at a user-level.  You can set atime and mtime from
 a system call, but not ctime.  ctime is always set to now.
 
 Jay  For most applications, though, when this
 Jay particular disk space was reserved for data is an effective synonym
 Jay for when this file was created. When you start moving files around,
 Jay the questions merlyn raises become much more important.
 
 Jay For the record, Kirk McKusick--one of the original implemetors of
 Jay UFS/FFS and the creator of UFS2--tells the story a little
 differently.
 Jay  According to him, the FFS originally intended to use ctime as the
 Jay creation time, but they discovered that dump needed a record of inode
 Jay creation to make incrimental backups effectively. In fact, UFS2
 Jay includes a btime (call it birth time if you want) field that is
 Jay stable across inode relocations when the system uses btime aware file
 Jay system operations. I don't know, though, if the Perl team has plans
 to
 Jay update stat() to support it on systems where it is available.
 
 Jay Of course, that isn't completely at odds with merlyn's comments: the
 Jay original unix developers started implementing file systems a decade
 Jay before Berkely started work on FFS.
 
 And, the whole notion of creation time doesn't make sense in the
 first place.  If I add a word, is it a new file, or an old file?  If I
 gut the entire contents, replace it with entirely new contents, is it
 new or old?  What if I rename it?  Is it new, or old?  There are no
 consistent answers to any of those questions, so why bother?
 
 --
 Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
 0095
 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/
 Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
 See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
 training!
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response


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




how to hide passwd from INPUT

2005-11-29 Thread Jennifer Garner

HI,Lists,

Sorry, this time I can't login into my primary mailbox of 30gigs.So I 
change another email for this question.


When I get something from input such as:

my $passwd=STDIN;

the password typed on screen is clear plain text.How can I get it input 
as hide type such as ***?Thanks.



---
 Jennifer

--
Sent using Laszlo Mail. Try it yourself.
http://www.laszlomail.com


--
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 hide passwd from INPUT

2005-11-29 Thread Jennifer Garner


Thanks for John and all.

On Tue, Nov 29, 2005 at 10:53 PM, John Doe wrote:


Jennifer Garner am Dienstag, 29. November 2005 15.40:

HI,Lists,

Sorry, this time I can't login into my primary mailbox of 30gigs.So I
change another email for this question.

When I get something from input such as:

my $passwd=STDIN;

the password typed on screen is clear plain text.How can I get it 
input

as hide type such as ***?Thanks.


perldoc -q password
=
How do I ask the user for a password?
...
   use Term::ReadKey;

   ReadMode('noecho');
   $password = ReadLine(0);
...

I would add a
ReadMode('normal');

otherwise your terminal could stay in noecho mode.

hth, joe

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





--
Sent using Laszlo Mail. Try it yourself.
http://www.laszlomail.com


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




how to get file's creation time

2005-11-27 Thread Jennifer Garner

hi,

How to get file's creation time,NOT last modify time?Thanks.


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




about deleting subroutine

2005-11-21 Thread Jennifer Garner

hi,lists,
I have seen this thread on perlmonk,and it make me confused too.Can anyone here 
explain that?Thanks.

Quote:
---
Basically, deleting subroutines from a symbol table seems a bit buggy, but I
don't know if this behavior is documented or not.

#!/usr/bin/perl -l

sub this { 'this' }
print this;
undef main::this; # undefine the code slot
print main-can('this') ? 'main-can(this)' : '! main-can(this)';
eval {print this};
print $@;
undef *main::this; # undefine the entire glob
print main-can('this') ? 'main-can(this)' : '! main-can(this)';

__END__
# result
this
main-can(this)
Undefined subroutine main::this called at sub.pl line 7.

! main-can(this)

  The first time I try to remove the subroutine via undef it still leaves a
CODE slot in the symbol table's *this glob. I can't just use delete because it's
not an array or a hash (it fails if you try). This is bad in procedural code but
it's awful in OO code because $object-can('this') will succeed even if the
method has been deleted.

  This leaves me with having to undefine the entire glob but that's a
horrible solution because the other slots in the glob, if any, are blown away.
Is this a known/documented bug/feature in Perl? Is there a workaround?



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




Re: Re: about deleting subroutine

2005-11-21 Thread Jennifer Garner

hi,Randys,
Bug #37128: undefing *foo{CODE} does not fully work

http://rt.perl.org/rt3/Ticket/Display.html?id=37128

When I try to access that url,it require me to be verified by username and 
passwd.
So I can't access that url.

On Mon, 21 Nov 2005 22:30:00 -0500, Randy W. Sims [EMAIL PROTECTED] wrote:
 Jennifer Garner wrote:
 hi,lists,
 
 Hi Jennifer,
 
 I have seen this thread on perlmonk,and it make me confused too.Can
 anyone here explain that?Thanks.

 Quote:
 ---
 Basically, deleting subroutines from a symbol table seems a bit buggy,
 but I
 don't know if this behavior is documented or not.
 
 Bug #37128: undefing *foo{CODE} does not fully work
 
 http://rt.perl.org/rt3/Ticket/Display.html?id=37128
 
 Randy.


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




help explaining for this script

2005-11-15 Thread Jennifer Garner

Hi,lists,

I can't understand for this script below,I want somebody here to give me some 
help.Thanks.

sub is_tainted{
my $var=shift;
my $blank=substr($var,0,0);
return not eval {eval 1 || $blank || 1};
}

That subroutine estimate for if some given var is tainted or not.But I can't 
know how it 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: Re: help explaining for this script

2005-11-15 Thread Jennifer Garner

Thanks for Jeff's explaining.I'm appreciated for that.

On Tue, 15 Nov 2005 18:48:40 -0500 (EST), Jeff 'japhy' Pinyan [EMAIL 
PROTECTED] wrote:
 On Nov 15, Jennifer Garner said:
 
 I can't understand for this script below,I want somebody here to give me
 some help.Thanks.

 sub is_tainted{
my $var=shift;
my $blank=substr($var,0,0);
return not eval {eval 1 || $blank || 1};
 }

 That subroutine estimate for if some given var is tainted or not.But I
 can't know how it works.
 
 If a variable is tainted, then any substring of that variable is also
 tainted.  In addition, it is illegal to eval() any string that is tainted.
 The inclusion of a tainted string inside another string makes that whole
 string tainted.
 
 Therefore:  if $var is tainted, the $blank will also be tainted (even
 though it's a substring of zero characters).  If $blank is then tainted,
 then the code
 
eval { eval 1 || $blank || 1 }
 
 will return false (since the eval { ... } catches fatal errors, and the
 eval 1 || $blank raises a fatal error because $blank is tainted), and
 therefore,
 
return not eval { eval 1 || $blank || 1 };
 
 returns true, stating that $var is indeed tainted.  If $var wasn't
 tainted, then
 
eval 1 || $blank || 1
 
 returns 1, and
 
return not eval { 1 }
 
 returns false, stating that $var wasn't tainted.
 
 *whew*
 
 Frankly, I find the 'eval 1 || $blank || 1' silly, since the whole
 reason the '... || 1' is needed is since $blank is a blank string and the
 code '1 || ' is invalid Perl.  Long story short, I'd have written:
 
sub is_tainted {
  return not eval { eval 1 . substr($_[0], 0, 0) };
}
 
 It's much more concise.  If $_[0] isn't tainted, then
 
not eval { eval 1 . substr($_[0], 0, 0) }
-
not eval { eval 1 }
-
not eval { 1 }
-
not 1
-
false
 
 whereas if $_[1] is tainted, then the eval { ... } returns false since a
 fatal error is raised because
 
eval 1 . substr($_[0], 0, 0)
 
 is illegal if $_[0] is tainted.
 
 --
 Jeff japhy Pinyan%  How can we ever be the sold short or
 RPI Acacia Brother #734%  the cheated, we who for every service
 http://www.perlmonks.org/  %  have long ago been overpaid?
 http://princeton.pm.org/   %-- Meister Eckhart
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response


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