[19442] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1637 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 28 09:10:31 2001

Date: Tue, 28 Aug 2001 06:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <999004212-v10-i1637@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 28 Aug 2001     Volume: 10 Number: 1637

Today's topics:
    Re: one character at a time (Yves Orton)
    Re: Perl number conversion Utilities (Randal L. Schwartz)
    Re: Perl number conversion Utilities (Peter J. Acklam)
    Re: Perl number conversion Utilities (Randal L. Schwartz)
    Re: Strange behavior of perl5 on HP-UX 11.0 <wiu09524@rrzc2.rz.uni-regensburg.de>
    Re: Strange behavior of perl5 on HP-UX 11.0 <Martin.Jost@icn.siemens.de>
        use() versus import() changing semantics? (Tassilo v. Parseval)
    Re: use() versus import() changing semantics? <tinamue@zedat.fu-berlin.de>
    Re: use() versus import() changing semantics? <kristian.fischer@koehlershohn.de>
    Re: use() versus import() changing semantics? (Tassilo v. Parseval)
    Re: use() versus import() changing semantics? <Tassilo.Parseval@post.rwth-aachen.de>
    Re: use() versus import() changing semantics? <kristian.fischer@koehlershohn.de>
    Re: use() versus import() changing semantics? <tinamue@zedat.fu-berlin.de>
    Re: warnings with cgi will crash Win32 perl core <matthew.garrish@sympatico.ca>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 28 Aug 2001 03:05:38 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: one character at a time
Message-Id: <74f348f7.0108280205.798c833f@posting.google.com>

Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3B89C2D9.9D65A526@earthlink.net>...
> Yves Orton wrote:
> Not that it matters much, but I prefer to ask Benchmark to repeat each one for some number of seconds rather than some number of times...
> 
> That is, Time(-10); instead of Time(100_000);

Done.

> You should have two substr versions, the second being:
> 	push @output, substr( $string, $i, 1 )
> 		for( 0 .. length( $string )-1 );

Done

> You should have two versions of regexp, the second one being:
> 	@output = $string =~ /(.)/gs

See below....

> 
> Also, if . in the regex were replaced with [\x00-\xFF] it might go a bit faster, though I'm not sure.

Done, but that means 4 different types. Oh and the class is marginally
slower.

> You should have a second unpack version, with
> 	@output = unpack("C*", $string);
> 
> Also, you didn't do the split solution:
> 	@output = split //, $string;

Yeah I didnt do any @list= variants.  I kinda thought the idea was to
process each letter in turn not to turn the string into an array of
chars.  So now i am testing them, but seperately, its interesting the
differences.

Incidentally I have rewritten the test and ran it against string
10,20..100 200,300,400,500 char long strings.  The results are
slightly suprising.  For short (<20) strings the substr4 method does
quite well... Heres my code and results:

#!perl
use strict;
use warnings;
use Benchmark qw(cmpthese timethese);
use Data::Dumper;

my $types={
	Scalar_only=>{
	   'substr4'  => 'substr ($s, 0, 1, "") while length($s)',
	   'substr3'  => 'substr( $s, $_, 1 ) foreach (0..length($s)-1)',
	},
	Regexp=>{
	   'rex_dot'  => '$s =~ /(.)/gs',
	   'rex_class' => '$s =~ /([\x00-\xFF])/gs',
	},
	List_only=>{
	   'unpack'   => 'unpack("C*", $s)',
	   'split'    => 'split(//,$s)',
	},
};

sub build_test {
   my $TestString=shift || "TEST";
   my $Print=shift;
   my $h='{my ($s,$r,@l)=("TEST","");'."\n";
   $h=~s/(TEST)/$TestString/e;
   my $f="}\n";
   $f=";\n".'print "s=$s | r=$r | l=@l\n"'.$f if ($Print);
   my $hash={};

   foreach my $key (keys %{$types->{Scalar_only}}) {
   	$hash->{'@= '.$key}=$h.'push
@l,'.$types->{Scalar_only}->{$key}.$f;
        $hash->{'= '.$key}=$h.'$r='.$types->{Scalar_only}->{$key}.$f;
   }
   foreach my $key (keys %{$types->{Regexp}}) {
   	$hash->{'@= '.$key}=$h.'@l='.$types->{Regexp}->{$key}.$f;
        $hash->{'= $_ '.$key}=$h.'$r= $_ foreach
('.$types->{Regexp}->{$key}.')'.$f;
        $hash->{'= $1 '.$key}=$h.'$r= $1 while
'.$types->{Regexp}->{$key}.$f;
   }
   foreach my $key (keys %{$types->{List_only}}) {
   	$hash->{'@= '.$key}=$h.'@l='.$types->{List_only}->{$key}.$f;
   	$hash->{'= '.$key}=$h.'$r= $_ foreach
'.$types->{List_only}->{$key}.$f;
   }
   return $hash;
}



use Data::Dumper;
my $print =build_test("ABCDEF",1);
foreach my $name (sort keys %$print) {
	print $name."\t";
	eval $print->{$name};
	die $@ if $@;
}
{
	local $,="\n";
	local $\="\n";
	print '$hash={\n';
	while (my ($k,$v)=each(%$print)) {
		print "'$k'\t=>","'$v',";
	}
	print '};';
}
foreach my $mul (1..10,20,30,40,50) {
	my $test=build_test("01234567890" x $mul);
	my %list;
	my %process;
	map { (substr($_,0,1) eq "@")
	       ? $list{$_}=$test->{$_}
	       : $process{$_}=$test->{$_}
	    } keys %$test;
	print "-----------------------------------------------------
	       Testing against ".($mul*10)." char string....\n\n";
	my $t=timethese (-60,\%list,"none");
	my $p=timethese (-60,\%process,"none");
	cmpthese($t);
	print "\n";
	cmpthese($p);
}

__END__

********************
*  EDITED RESULTS  *
********************
= $1 rex_class	s=ABCDEF | r=F | l=
= $1 rex_dot	s=ABCDEF | r=F | l=
= $_ rex_class	s=ABCDEF | r=F | l=
= $_ rex_dot	s=ABCDEF | r=F | l=
= split	s=ABCDEF | r=F | l=
= substr3	s=ABCDEF | r=F | l=
= substr4	s= | r=F | l=
= unpack	s=ABCDEF | r=70 | l=
@= rex_class	s=ABCDEF | r= | l=A B C D E F
@= rex_dot	s=ABCDEF | r= | l=A B C D E F
@= split	s=ABCDEF | r= | l=A B C D E F
@= substr3	s=ABCDEF | r= | l=A B C D E F
@= substr4	s= | r= | l=A B C D E F
@= unpack	s=ABCDEF | r= | l=65 66 67 68 69 70
$hash={\n
'= unpack'	=>
'{my ($s,$r,@l)=("ABCDEF","");
$r= $_ foreach unpack("C*", $s);
print "s=$s | r=$r | l=@l\n"}
',
'@= unpack'	=>
'{my ($s,$r,@l)=("ABCDEF","");
@l=unpack("C*", $s);
print "s=$s | r=$r | l=@l\n"}
',
'= split'	=>
'{my ($s,$r,@l)=("ABCDEF","");
$r= $_ foreach split(//,$s);
print "s=$s | r=$r | l=@l\n"}
',
'= $_ rex_dot'	=>
'{my ($s,$r,@l)=("ABCDEF","");
$r= $_ foreach ($s =~ /(.)/gs);
print "s=$s | r=$r | l=@l\n"}
',
'= $_ rex_class'	=>
'{my ($s,$r,@l)=("ABCDEF","");
$r= $_ foreach ($s =~ /([\x00-\xFF])/gs);
print "s=$s | r=$r | l=@l\n"}
',
'= $1 rex_dot'	=>
'{my ($s,$r,@l)=("ABCDEF","");
$r= $1 while $s =~ /(.)/gs;
print "s=$s | r=$r | l=@l\n"}
',
'@= rex_class'	=>
'{my ($s,$r,@l)=("ABCDEF","");
@l=$s =~ /([\x00-\xFF])/gs;
print "s=$s | r=$r | l=@l\n"}
',
'@= split'	=>
'{my ($s,$r,@l)=("ABCDEF","");
@l=split(//,$s);
print "s=$s | r=$r | l=@l\n"}
',
'= substr3'	=>
'{my ($s,$r,@l)=("ABCDEF","");
$r=substr( $s, $_, 1 ) foreach (0..length($s)-1);
print "s=$s | r=$r | l=@l\n"}
',
'= substr4'	=>
'{my ($s,$r,@l)=("ABCDEF","");
$r=substr ($s, 0, 1, "") while length($s);
print "s=$s | r=$r | l=@l\n"}
',
'@= substr3'	=>
'{my ($s,$r,@l)=("ABCDEF","");
push @l,substr( $s, $_, 1 ) foreach (0..length($s)-1);
print "s=$s | r=$r | l=@l\n"}
',
'= $1 rex_class'	=>
'{my ($s,$r,@l)=("ABCDEF","");
$r= $1 while $s =~ /([\x00-\xFF])/gs;
print "s=$s | r=$r | l=@l\n"}
',
'@= substr4'	=>
'{my ($s,$r,@l)=("ABCDEF","");
push @l,substr ($s, 0, 1, "") while length($s);
print "s=$s | r=$r | l=@l\n"}
',
'@= rex_dot'	=>
'{my ($s,$r,@l)=("ABCDEF","");
@l=$s =~ /(.)/gs;
print "s=$s | r=$r | l=@l\n"}
',
};
REMOVE PRINT STATEMENTS FOR THE BELOW TESTS
-----------------------------------------------------
	       Testing against 10 char string....
@= substr3   33489/s   
@= rex_class 34165/s   
@= rex_dot   35212/s   
@= substr4   36117/s   
@= split     41859/s   
@= unpack    84778/s   

= $1 rex_class 28994/s 
= $1 rex_dot   29886/s 
= $_ rex_class 32732/s 
= $_ rex_dot   33915/s 
= split        34041/s 
= substr3      51807/s 
= unpack       57781/s 
= substr4      57959/s 
-----------------------------------------------------
	       Testing against 20 char string....
@= rex_class 18616/s   
@= rex_dot   19178/s   
@= substr3   19327/s   
@= substr4   19739/s   
@= split     22983/s   
@= unpack    49074/s   

= $1 rex_class 15850/s 
= $1 rex_dot   16360/s 
= $_ rex_class 18827/s 
= split        19421/s 
= $_ rex_dot   19668/s 
= substr3      31502/s 
= substr4      31870/s 
= unpack       35170/s 
-----------------------------------------------------
	       Testing against 30 char string....
@= rex_class 12732/s    
@= substr4   13177/s    
@= rex_dot   13307/s    
@= substr3   13465/s    
@= split     15849/s    
@= unpack    34655/s    

= $1 rex_class 10983/s  
= $1 rex_dot   11345/s  
= $_ rex_class 13335/s  
= split        13683/s  
= $_ rex_dot   13741/s  
= substr4      22059/s  
= substr3      22778/s  
= unpack       25335/s  
-----------------------------------------------------
	       Testing against 40 char string....
@= rex_class  9634/s  
@= rex_dot   10126/s  
@= substr4   10279/s  
@= substr3   10373/s  
@= split     12212/s  
@= unpack    26740/s  
                
= $1 rex_class  8192/s
= $1 rex_dot    8730/s
= $_ rex_class 10214/s
= split        10362/s
= $_ rex_dot   10687/s
= substr4      17088/s
= substr3      17783/s
= unpack       19785/s
-----------------------------------------------------
	       Testing against 50 char string....
@= rex_class  7856/s  
@= rex_dot    8175/s  
@= substr4    8295/s  
@= substr3    8435/s  
@= split      9817/s  
@= unpack    21827/s  
                
= $1 rex_class  6849/s
= $1 rex_dot    7158/s
= $_ rex_class  8317/s
= split         8544/s
= $_ rex_dot    8714/s
= substr4      13716/s
= substr3      14564/s
= unpack       16227/s
-----------------------------------------------------
	       Testing against 60 char string....
@= rex_class  6576/s  
@= rex_dot    6869/s  
@= substr4    6952/s  
@= substr3    7136/s  
@= split      8125/s  
@= unpack    18344/s  
                      
= $1 rex_class  5729/s
= $1 rex_dot    5876/s
= $_ rex_class  7022/s
= split         7208/s
= $_ rex_dot    7337/s
= substr4      11399/s
= substr3      12353/s
= unpack       13727/s
-----------------------------------------------------
	       Testing against 70 char string....
@= rex_class  5658/s         
@= rex_dot    5875/s         
@= substr4    5977/s         
@= substr3    6113/s         
@= split      7120/s         
@= unpack    15943/s         
                  
= $1 rex_class  5002/s       
= $1 rex_dot    5189/s       
= $_ rex_class  6053/s       
= split         6244/s       
= $_ rex_dot    6347/s       
= substr4       9951/s       
= substr3      10726/s       
= unpack       11922/s       
-----------------------------------------------------
	       Testing against 80 char string....
@= rex_class  4982/s      
@= rex_dot    5183/s      
@= substr4    5254/s      
@= substr3    5374/s      
@= split      6229/s      
@= unpack    14023/s      

= $1 rex_class  4352/s   
= $1 rex_dot    4519/s   
= $_ rex_class  5322/s   
= split         5482/s   
= $_ rex_dot    5598/s   
= substr4       8757/s   
= substr3       9461/s   
= unpack       10535/s   
----------------------------------------------------
Testing against 90 char string....
@= rex_class  4427/s  
@= substr4    4531/s  
@= rex_dot    4604/s  
@= substr3    4815/s  
@= split      5564/s  
@= unpack    12532/s  

= $1 rex_class 3874/s 
= $1 rex_dot   4029/s 
= $_ rex_class 4771/s 
= split        4900/s 
= $_ rex_dot   4987/s 
= substr4      7771/s 
= substr3      8478/s 
= unpack       9424/s 
-----------------------------------------------------
Testing against 100 char string....
@= rex_class  3992/s
@= rex_dot    4164/s
@= substr4    4221/s
@= substr3    4392/s
@= split      5019/s
@= unpack    11327/s

= $1 rex_class 3491/s
= $1 rex_dot   3664/s
= $_ rex_class 4311/s
= split        4408/s
= $_ rex_dot   4499/s
= substr4      7006/s
= substr3      7676/s
= unpack       8492/s
-----------------------------------------------------
Testing against 200 char string....
@= rex_class 2015/s
@= rex_dot   2100/s
@= substr4   2128/s
@= substr3   2203/s
@= split     2535/s
@= unpack    5760/s

= $1 rex_class 1729/s
= $1 rex_dot   1829/s
= $_ rex_class 2190/s
= split        2246/s
= $_ rex_dot   2291/s
= substr4      3569/s
= substr3      3941/s
= unpack       4365/s
-----------------------------------------------------
Testing against 300 char string....
@= rex_class 1345/s  
@= rex_dot   1402/s  
@= substr4   1408/s  
@= substr3   1496/s  
@= split     1658/s  
@= unpack    3853/s  

= $1 rex_class 1179/s
= $1 rex_dot   1237/s
= $_ rex_class 1463/s
= split        1500/s
= $_ rex_dot   1505/s
= substr4      2396/s
= substr3      2653/s
= unpack       2935/s
-----------------------------------------------------
Testing against 400 char string....
@= rex_class 1004/s  
@= rex_dot   1036/s  
@= substr4   1064/s  
@= substr3   1111/s  
@= split     1270/s  
@= unpack    2890/s  

= $1 rex_class  900/s
= $1 rex_dot    918/s
= $_ rex_class 1101/s
= split        1127/s
= $_ rex_dot   1154/s
= substr4      1724/s
= substr3      1999/s
= unpack       2212/s
----------------------------------------------------
Testing against 500 char string....
@= rex_class  799/s
@= rex_dot    833/s
@= substr4    847/s
@= substr3    877/s
@= split     1015/s
@= unpack    2236/s

= $1 rex_class  697/s
= $1 rex_dot    741/s
= $_ rex_class  864/s
= split         898/s
= $_ rex_dot    917/s
= substr4      1405/s
= substr3      1603/s
= unpack       1771/s


------------------------------

Date: 28 Aug 2001 03:48:11 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl number conversion Utilities
Message-Id: <m166b8o3ys.fsf@halfdome.holdit.com>

>>>>> "Joseph" == Joseph Hasting <hasting@agere.com> writes:

Joseph> Hi,  I spent some time putting these number conversion subroutines
Joseph> together.  It was very difficult to find the non-printf ways to convert
Joseph> number formats, so I thought I would share them:

Joseph> sub dec2hex {return sprintf("%lx ", shift);}
Joseph> sub hex2dec {return hex(shift);}
Joseph> sub bin2dec {return unpack("N", pack("B32", substr("0" x 32 . shift,
Joseph> -32)));}
Joseph> sub dec2bin {my $str = unpack("B32", pack("N", shift)); $str =~
Joseph> s/^0+(?=\d)//; return $str;}
Joseph> sub bin2hex {return dec2hex(bin2dec(shift));}
Joseph> sub hex2bin {return dec2bin(hex2dec(shift));}

But those aren't "dec2hex", "hex2dec" and so on.  Those are "num2hex"
and "hex2num", and so on.  They don't convert to decimal digits.  They
convert to internal numbers.  It's Perl's I/O routines that are
converting between internal numbers and external decimal digits.

Let's get the terminology right.  I keep seeing this meme go around,
and I intend on killing it!

print "Just another Perl hacker,"

-- 
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!


------------------------------

Date: 28 Aug 2001 13:13:39 +0200
From: jacklam@math.uio.no (Peter J. Acklam)
Subject: Re: Perl number conversion Utilities
Message-Id: <cxczo8kh1y4.fsf@tiamat.uio.no>

merlyn@stonehenge.com (Randal L. Schwartz) wrote:

> But those aren't "dec2hex", "hex2dec" and so on.  Those are
> "num2hex" and "hex2num", and so on.

Since they are all limited to dealing with integers, I prefer
"int2hex", "hex2int", etc.

Peter

-- 
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;


------------------------------

Date: 28 Aug 2001 05:47:40 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl number conversion Utilities
Message-Id: <m1g0acmjv7.fsf@halfdome.holdit.com>

>>>>> "Peter" == Peter J Acklam <jacklam@math.uio.no> writes:

Peter> merlyn@stonehenge.com (Randal L. Schwartz) wrote:
>> But those aren't "dec2hex", "hex2dec" and so on.  Those are
>> "num2hex" and "hex2num", and so on.

Peter> Since they are all limited to dealing with integers, I prefer
Peter> "int2hex", "hex2int", etc.

Ooh yes.  Thank you.  I'll add that to the Stamp Out dec2hex Crusade FAQ. :)

-- 
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!


------------------------------

Date: 28 Aug 2001 12:45:58 +0200
From: Ulrich Windl <wiu09524@rrzc2.rz.uni-regensburg.de>
Subject: Re: Strange behavior of perl5 on HP-UX 11.0
Message-Id: <snfofp04g49.fsf@rrzc2.rz.uni-regensburg.de>

I just checked it with our Perl 5.6.0 (also binary install), it works!

tanya.ruttenberg@ssa.gov (Tanya Ruttenberg) writes:

> I'm not sure if this is an HP OS problem or a Perl problem. That's why
> I'm posting it to both newsgroups.
> 
> The sys admin installed perl5.00503 yesterday (downloaded the binary 
> distribution from the HP developer resource website) but it is 
> unusable due to an inability to execute it:
> 
> s12da21: /usr/local/bin/perl -e 'print "Hello\n";'
> sh: /usr/local/bin/perl: Execute permission denied.
> 
> But it appears to be executable:
> 
> s12da21: ls -l /usr/local/bin/perl
> -rwxr-xr-x   2 bin        bin         384637 Jun 12 15:34 /usr/local/bin/perl
> 
> He (the sys admin) got the same error when trying to run it as root!?
> 
> I asked him to trace the process to see exactly which file was claiming
> insufficient permissions, but he either didn't hear me, didn't know
> how, or didn't want to for some other reason.  He said he'd "look into it"
> but I am skeptical he'll get back to me anytime soon.
> 
> Has anyone seen this problem before and do you know how to fix it?


------------------------------

Date: Tue, 28 Aug 2001 14:27:02 +0200
From: Martin Jost <Martin.Jost@icn.siemens.de>
Subject: Re: Strange behavior of perl5 on HP-UX 11.0
Message-Id: <3B8B8E16.71BC9795@icn.siemens.de>

Ulrich Windl wrote:
> 
> I just checked it with our Perl 5.6.0 (also binary install), it works!

So does mine ;-)
See below for some suggestions

> tanya.ruttenberg@ssa.gov (Tanya Ruttenberg) writes:
> 
> > The sys admin installed perl5.00503 yesterday (downloaded the binary
> > distribution from the HP developer resource website) but it is
> > unusable due to an inability to execute it:
> >
> > s12da21: /usr/local/bin/perl -e 'print "Hello\n";'
> > sh: /usr/local/bin/perl: Execute permission denied.
> >
> > But it appears to be executable:
> >
> > s12da21: ls -l /usr/local/bin/perl
> > -rwxr-xr-x   2 bin        bin         384637 Jun 12 15:34 /usr/local/bin/perl
> >

Ok, just wild guessing...
What does the following commands "say":
which perl
perl -v
perl -V

(One of my guesses are 'old' perl-parts laying around or something
like this)

Is your perl installed under /usr/local or /opt or .... ???

HTH

Martin


------------------------------

Date: 28 Aug 2001 10:30:53 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo v. Parseval)
Subject: use() versus import() changing semantics?
Message-Id: <9mfrst$nji$1@nets3.rz.RWTH-Aachen.DE>

I just hit a - for me - quite inexplicable behaviour related to
including modules with either use() or import. The below is part of a
subroutine and should illustrate it:

[...]
eval { require URI::Find; };
	if ($@) {
	 	carp <<EOW;
You need the URI::Find module in order to use
extract_urls.
EOW
	return;
}
else { use URI::Find; return find_uris($text, $coderef); }

The above works fine, with the only exception that 'make test' will fail
complaining about the missing URI::Find module on machines where it is
not installed. So I changed the else part to something like:

else { return URI::Find::find_uris($text, $coderef); }

Now, the test-scripts wont break at compile-time but instead at runtime,
complaining that :

t/5mbox.............ok 2/4Can't use string ("* Tassilo von Parseval
(tassilo.") as a SCALAR ref while "strict refs" in use at
/usr/local/share/perl/5.6.1/URI/Find.pm line 49.

I can make this work by passing \$text instead of $test to find_uris.
And now, I don't know why this is so. I can pass a simple scalar-vaiable
containing a string to find_uris when including it with use() but I have
to pass a reference otherwise.

Does anyone have an explanation for that?
								
Tassilo
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: 28 Aug 2001 11:40:29 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: use() versus import() changing semantics?
Message-Id: <9mfvvd$21ogl$2@fu-berlin.de>

Tassilo v. Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> I just hit a - for me - quite inexplicable behaviour related to
> including modules with either use() or import. The below is part of a
> subroutine and should illustrate it:

> [...]
> eval { require URI::Find; };
> 	if ($@) {
> 	 	carp <<EOW;
> You need the URI::Find module in order to use
> extract_urls.
> EOW
> 	return;
> }
> else { use URI::Find; return find_uris($text, $coderef); }

> The above works fine, with the only exception that 'make test' will fail
> complaining about the missing URI::Find module on machines where it is
> not installed. So I changed the else part to something like:

> else { return URI::Find::find_uris($text, $coderef); }

> Now, the test-scripts wont break at compile-time but instead at runtime,
> complaining that :

> t/5mbox.............ok 2/4Can't use string ("* Tassilo von Parseval
> (tassilo.") as a SCALAR ref while "strict refs" in use at
> /usr/local/share/perl/5.6.1/URI/Find.pm line 49.

> I can make this work by passing \$text instead of $test to find_uris.
> And now, I don't know why this is so. I can pass a simple scalar-vaiable
> containing a string to find_uris when including it with use() but I have
> to pass a reference otherwise.

> Does anyone have an explanation for that?

phew, i searched the perldocs, but i didn't find a clear
explanation. i think it might have something to do with
prototypes. the method find_uris() has (\$&) as a
prototype, that means it'll take the first argument
as a reference. it takes it and calls another method, find(),
and find expects a reference.
"normally" you'd say
use URI::Find;
find_uri($text, $code);

perl will pass $text as a reference, and everything's fine.
if you say:
require URI::Find;
i guess that you can't check prototypes. the only possibility is to
put that at the BEGIN()ning.
so the following does not work:
require URI::Find;                               
print URI::Find::find_uris($test,$code);

(errormessage:
Can't use string ("test") as a SCALAR ref while "strict refs"
     in use at /usr/lib/perl5/site_perl/5.6.0/URI/Find.pm line 124.
)
while this works:
BEGIN{require URI::Find;}
print URI::Find::find_uris($test,$code);

so i think require() not in a BEGIN-block disables prototype
checking. but i didn't find the corresponding explanation
in the docs. anyone can help?

regards,
tina
-- 
http://www.tinita.de \  enter__| |__the___ _ _ ___
tina's moviedatabase  \     / _` / _ \/ _ \ '_(_-< of
search & add comments  \    \ _,_\ __/\ __/_| /__/ perception
---   Warning: content of homepage hopelessly out-dated   ---


------------------------------

Date: Tue, 28 Aug 2001 13:50:02 +0200
From: Kristian Fischer <kristian.fischer@koehlershohn.de>
Subject: Re: use() versus import() changing semantics?
Message-Id: <3B8B856A.A93DC234@koehlershohn.de>

Hallo 

"Tassilo v. Parseval" wrote:
> 
> I just hit a - for me - quite inexplicable behaviour related to
> including modules with either use() or import. The below is part of a
> subroutine and should illustrate it:
> 
> [...]
> eval { require URI::Find; };
>         if ($@) {
>                 carp <<EOW;
> You need the URI::Find module in order to use
> extract_urls.
> EOW
>         return;
> }
> else { use URI::Find; return find_uris($text, $coderef); }
> 
> The above works fine, with the only exception that 'make test' will fail
> complaining about the missing URI::Find module on machines where it is
> not installed. So I changed the else part to something like:
> 
> else { return URI::Find::find_uris($text, $coderef); }
> 
> Now, the test-scripts wont break at compile-time but instead at runtime,
> complaining that :
> 
> t/5mbox.............ok 2/4Can't use string ("* Tassilo von Parseval
> (tassilo.") as a SCALAR ref while "strict refs" in use at
> /usr/local/share/perl/5.6.1/URI/Find.pm line 49.
> 
> I can make this work by passing \$text instead of $test to find_uris.
> And now, I don't know why this is so. I can pass a simple scalar-vaiable
> containing a string to find_uris when including it with use() but I have
> to pass a reference otherwise.
> 
> Does anyone have an explanation for that?

Try this for an example:
perl -e '$var = 1; unless($var){ use URI::Find; } print $@ if($@);'

The use statement is *allways* executed at compile-time.

Gruß
 Kristian


------------------------------

Date: 28 Aug 2001 11:50:39 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo v. Parseval)
Subject: Re: use() versus import() changing semantics?
Message-Id: <9mg0if$sqc$1@nets3.rz.RWTH-Aachen.DE>

On 28 Aug 2001 11:40:29 GMT, Tina Mueller <tinamue@zedat.fu-berlin.de> wrote:

> "normally" you'd say
> use URI::Find;
> find_uri($text, $code);
> perl will pass $text as a reference, and everything's fine.
> if you say:
> require URI::Find;
> i guess that you can't check prototypes. the only possibility is to
> put that at the BEGIN()ning.
> so the following does not work:
> require URI::Find;                               
> print URI::Find::find_uris($test,$code);
> 
> (errormessage:
> Can't use string ("test") as a SCALAR ref while "strict refs"
>      in use at /usr/lib/perl5/site_perl/5.6.0/URI/Find.pm line 124.
> )
> while this works:
> BEGIN{require URI::Find;}
> print URI::Find::find_uris($test,$code);
> 
> so i think require() not in a BEGIN-block disables prototype
> checking. but i didn't find the corresponding explanation
> in the docs. anyone can help?

Hmmh, thanks for your inquiry into that...this is quite interesting
really. I guess I will have to do it with a BEGIN-block instead of
passing a reference. Who knows whether future Perl releases will have
the same behaviour and - since it is a module - I can't maintain
several releases for each different Perl.

Tassilo
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: Tue, 28 Aug 2001 14:10:16 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: use() versus import() changing semantics?
Message-Id: <3B8B8A28.1060106@post.rwth-aachen.de>

Kristian Fischer wrote:

> perl -e '$var = 1; unless($var){ use URI::Find; } print $@ if($@);'
> 
> The use statement is *allways* executed at compile-time.

Yes, and this was my problem since I looked for a way to include 
URI::Find at runtime depending on whether the box has this module 
installed. It seems to work the way Tina suggested: Putting require into 
a BEGIN-block. In case of failure I now set a global-variable that is 
later checked when the method is invoked.

I think URI::Find::find_uris should change its function parameter 
profile from (\$&) to ($&) where there first parameter would have to be 
an explicit scalar-ref.

Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: Tue, 28 Aug 2001 14:37:48 +0200
From: Kristian Fischer <kristian.fischer@koehlershohn.de>
Subject: Re: use() versus import() changing semantics?
Message-Id: <3B8B909C.3F7230CC@koehlershohn.de>

Hallo

Tassilo von Parseval wrote:
> 
> Kristian Fischer wrote:
> 
> > perl -e '$var = 1; unless($var){ use URI::Find; } print $@ if($@);'
> >
> > The use statement is *allways* executed at compile-time.
> 
> Yes, and this was my problem since I looked for a way to include
> URI::Find at runtime depending on whether the box has this module
> installed. It seems to work the way Tina suggested: Putting require into
> a BEGIN-block. In case of failure I now set a global-variable that is
> later checked when the method is invoked.
> 
> I think URI::Find::find_uris should change its function parameter
> profile from (\$&) to ($&) where there first parameter would have to be
> an explicit scalar-ref.

AFAIK this is the right way:

eval { require URI::Find; import URI::Find; }
if($@){
  # error
}else{
  # do it
}

so you'll not run in problems later.

Kristian


------------------------------

Date: 28 Aug 2001 13:04:00 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: use() versus import() changing semantics?
Message-Id: <9mg4s0$22lto$1@fu-berlin.de>

Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> Kristian Fischer wrote:

>> perl -e '$var = 1; unless($var){ use URI::Find; } print $@ if($@);'
>> 
>> The use statement is *allways* executed at compile-time.

> Yes, and this was my problem since I looked for a way to include 
> URI::Find at runtime depending on whether the box has this module 
> installed. It seems to work the way Tina suggested: Putting require into 
> a BEGIN-block. In case of failure I now set a global-variable that is 
> later checked when the method is invoked.

> I think URI::Find::find_uris should change its function parameter 
> profile from (\$&) to ($&) where there first parameter would have to be 
> an explicit scalar-ref.

well, the author says, that find_uris() is deprecated, so you
shouldn't use it at all. maybe you can do the same using
find() and other methods, but i haven't looked into the
docs too much...

regards,
tina

-- 
http://www.tinita.de \  enter__| |__the___ _ _ ___
tina's moviedatabase  \     / _` / _ \/ _ \ '_(_-< of
search & add comments  \    \ _,_\ __/\ __/_| /__/ perception
---   Warning: content of homepage hopelessly out-dated   ---


------------------------------

Date: Tue, 28 Aug 2001 08:40:46 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: warnings with cgi will crash Win32 perl core
Message-Id: <AgMi7.26190$Hr2.1683001@news20.bellglobal.com>


"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3B8B21A7.B3E4258B@stomp.stomp.tokyo...

<all that crap sent to digital heaven>

I guess your pain comes from being so consistently wrong all the time. Maybe
you should start posting exclusively to alt.perl; you'd fit in well with all
the dimwits who post questions without checking the perldocs.

Matt




------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 1637
***************************************


home help back first fref pref prev next nref lref last post