[19499] in Perl-Users-Digest
Perl-Users Digest, Issue: 1696 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 5 08:45:32 2001
Date: Wed, 5 Sep 2001 03:15:18 -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: <999684917-v10-i1696@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 5 Sep 2001 Volume: 10 Number: 1696
Today's topics:
Undef'ing multiple variables <nobody@nowhere.com>
Re: Undef'ing multiple variables (Rafael Garcia-Suarez)
Re: Undef'ing multiple variables <nobody@nowhere.com>
Re: Undef'ing multiple variables <Tassilo.Parseval@post.rwth-aachen.de>
Re: Undef'ing multiple variables <nobody@nowhere.com>
Re: Undef'ing multiple variables <Tassilo.Parseval@post.rwth-aachen.de>
Re: Undef'ing multiple variables <nobody@nowhere.com>
Re: Undef'ing multiple variables <krahnj@acm.org>
Re: Undef'ing multiple variables (Damian Conway)
Re: Undef'ing multiple variables <tinamue@zedat.fu-berlin.de>
Re: Undef'ing multiple variables (Rafael Garcia-Suarez)
Re: Undef'ing multiple variables (Rafael Garcia-Suarez)
Re: Why doesn't this regex work? (Ian Boreham)
Re: Why doesn't this regex work? <krahnj@acm.org>
Re: Why doesn't this regex work? (Ian Boreham)
Re: Why doesn't this regex work? <bart.lateur@skynet.be>
Re: win32 rmdir questions <philippe.perrin@sxb.bsf.alcatel.fr>
Re: win32 rmdir questions <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 5 Sep 2001 17:51:18 +1000
From: "aL" <nobody@nowhere.com>
Subject: Undef'ing multiple variables
Message-Id: <9n4lpj$ev2$1@perki.connect.com.au>
G'day all,
I notice after a Perl upgrade my hard working scripts started returning the
error "Too many arguments for undef operator".
My code includes lines such as:
undef ($var, @array, %hash, $var2);
The new documentation also tells me that I can now only undef one array /
scalar / hash at a time.
My 2 Questions are:
1) Is there another way I can undef multiple scalars / arrays / hashes at
once under the newer versions of Perl without having to add undef functins
for EVERY variable I want to undef?
2) Why was this tedious and annoying limit imposed on the newer versions of
Perl?
Thanks
aL
------------------------------
Date: 5 Sep 2001 08:09:29 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Undef'ing multiple variables
Message-Id: <slrn9pbne0.r96.rgarciasuarez@rafael.kazibao.net>
aL wrote in comp.lang.perl.misc:
} G'day all,
}
} I notice after a Perl upgrade my hard working scripts started returning the
} error "Too many arguments for undef operator".
}
} My code includes lines such as:
} undef ($var, @array, %hash, $var2);
}
} The new documentation also tells me that I can now only undef one array /
} scalar / hash at a time.
undef LIST never worked. See the perldelta manpage (for 5.6.1) :
Expressions such as:
print defined(&foo,&bar,&baz);
print uc("foo","bar","baz");
undef($foo,&bar);
used to be accidentally allowed in earlier versions, and produced
unpredictable behaviour.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Wed, 5 Sep 2001 18:09:04 +1000
From: "aL" <nobody@nowhere.com>
Subject: Re: Undef'ing multiple variables
Message-Id: <9n4mqt$fqm$1@perki.connect.com.au>
Thanks,
As luck would have it, I just figured it out myself two secs ago... :)
For other who were ignorant like me, just ditch the brackets, ie:
undef $var, @array, %hash, $var2;
Thanks again.
aL
"Rafael Garcia-Suarez" <rgarciasuarez@free.fr> wrote in message
news:slrn9pbne0.r96.rgarciasuarez@rafael.kazibao.net...
> aL wrote in comp.lang.perl.misc:
> } G'day all,
> }
> } I notice after a Perl upgrade my hard working scripts started returning
the
> } error "Too many arguments for undef operator".
> }
> } My code includes lines such as:
> } undef ($var, @array, %hash, $var2);
> }
> } The new documentation also tells me that I can now only undef one array
/
> } scalar / hash at a time.
>
> undef LIST never worked. See the perldelta manpage (for 5.6.1) :
>
> Expressions such as:
>
> print defined(&foo,&bar,&baz);
> print uc("foo","bar","baz");
> undef($foo,&bar);
>
> used to be accidentally allowed in earlier versions, and produced
> unpredictable behaviour.
>
> --
> Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Wed, 05 Sep 2001 10:30:45 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Undef'ing multiple variables
Message-Id: <3B95E2B5.3010701@post.rwth-aachen.de>
aL wrote:
> As luck would have it, I just figured it out myself two secs ago... :)
No, you haven't.
> For other who were ignorant like me, just ditch the brackets, ie:
> undef $var, @array, %hash, $var2;
Wont work. This will only undef $var and leave the other variables
untouched.
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: Wed, 5 Sep 2001 18:31:19 +1000
From: "aL" <nobody@nowhere.com>
Subject: Re: Undef'ing multiple variables
Message-Id: <9n4o4m$gkg$1@perki.connect.com.au>
Arrrghh!
So is there, or isn't there, a way to undef multiple variables at once?
aL
"Tassilo von Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in
message news:3B95E2B5.3010701@post.rwth-aachen.de...
> aL wrote:
>
> > As luck would have it, I just figured it out myself two secs ago... :)
>
> No, you haven't.
>
> > For other who were ignorant like me, just ditch the brackets, ie:
> > undef $var, @array, %hash, $var2;
>
> Wont work. This will only undef $var and leave the other variables
> untouched.
>
> 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: Wed, 05 Sep 2001 10:40:37 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Undef'ing multiple variables
Message-Id: <3B95E505.1040405@post.rwth-aachen.de>
aL wrote:
> Arrrghh!
>
> So is there, or isn't there, a way to undef multiple variables at once?
Don't know any such built-in function. You can do:
map { undef $_ } ($a, $b, @c);
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: Wed, 5 Sep 2001 18:38:11 +1000
From: "aL" <nobody@nowhere.com>
Subject: Re: Undef'ing multiple variables
Message-Id: <9n4ohi$h2i$1@perki.connect.com.au>
Great!
Thanks for that.
"Tassilo von Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in
message news:3B95E505.1040405@post.rwth-aachen.de...
> aL wrote:
>
> > Arrrghh!
> >
> > So is there, or isn't there, a way to undef multiple variables at once?
>
> Don't know any such built-in function. You can do:
>
> map { undef $_ } ($a, $b, @c);
>
> 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: Wed, 05 Sep 2001 09:06:04 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Undef'ing multiple variables
Message-Id: <3B95EB72.B1A169A5@acm.org>
aL wrote:
>
> I notice after a Perl upgrade my hard working scripts started returning the
> error "Too many arguments for undef operator".
>
> My code includes lines such as:
> undef ($var, @array, %hash, $var2);
>
> The new documentation also tells me that I can now only undef one array /
> scalar / hash at a time.
>
> My 2 Questions are:
> 1) Is there another way I can undef multiple scalars / arrays / hashes at
> once under the newer versions of Perl without having to add undef functins
> for EVERY variable I want to undef?
> 2) Why was this tedious and annoying limit imposed on the newer versions of
> Perl?
The correct way to do this in later versions of Perl is to use lexical
variables in a code block.
#!/usr/bin/perl -w
use strict;
my $file_scope;
# do something with $file_scope
while ( <> ) {
my $block_scope;
# do something with $file_scope and/or $block_scope
}
# The variable $block_scope no longer exists
# do something with $file_scope
__END__
The variable $file_scope no longer exists
John
--
use Perl;
program
fulfillment
------------------------------
Date: 5 Sep 2001 09:09:30 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Undef'ing multiple variables
Message-Id: <9n4q4a$e2a$1@towncrier.cc.monash.edu.au>
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> writes:
>> So is there, or isn't there, a way to undef multiple variables
>> at once?
> Don't know any such built-in function. You can do:
> map { undef $_ } ($a, $b, @c);
Some people don't like to use C<map> in a void context.
An alternative would be:
undef $_ for $a, $b, @c;
Damian
------------------------------
Date: 5 Sep 2001 09:49:27 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Undef'ing multiple variables
Message-Id: <9n4sf7$5boqn$1@fu-berlin.de>
aL <nobody@nowhere.com> wrote:
> My 2 Questions are:
> 1) Is there another way I can undef multiple scalars / arrays / hashes at
> once under the newer versions of Perl without having to add undef functins
> for EVERY variable I want to undef?
you could do:
($scalar, @array, %hash) = ();
hth, tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 5 Sep 2001 09:41:05 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Undef'ing multiple variables
Message-Id: <slrn9pbspp.tlc.rgarciasuarez@rafael.kazibao.net>
Damian Conway wrote in comp.lang.perl.misc:
} Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> writes:
}
} >> So is there, or isn't there, a way to undef multiple variables
} >> at once?
}
} > Don't know any such built-in function. You can do:
}
} > map { undef $_ } ($a, $b, @c);
}
} Some people don't like to use C<map> in a void context.
} An alternative would be:
}
} undef $_ for $a, $b, @c;
Both solutions don't undef @c; they only undef @c elements.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 5 Sep 2001 09:59:42 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Undef'ing multiple variables
Message-Id: <slrn9pbtsm.tp7.rgarciasuarez@rafael.kazibao.net>
aL wrote in comp.lang.perl.misc:
} 1) Is there another way I can undef multiple scalars / arrays / hashes at
} once under the newer versions of Perl without having to add undef functins
} for EVERY variable I want to undef?
OK, I've got a solution that works :
#!/usr/local/bin/perl -wl
$s = 1;
@a = qw/foo bar/;
%h = ( a => 1, b => 2 );
print defined $s ? 'def' : 'undef';
print defined @a ? 'def' : 'undef';
print defined %h ? 'def' : 'undef';
eval "undef $_" for qw/$s @a %h/;
print defined $s ? 'def' : 'undef';
print defined @a ? 'def' : 'undef';
print defined %h ? 'def' : 'undef';
--> output
def
def
def
undef
undef
undef
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 4 Sep 2001 19:14:39 -0700
From: ianb@ot.com.au (Ian Boreham)
Subject: Re: Why doesn't this regex work?
Message-Id: <f02c4576.0109041814.1003b6ad@posting.google.com>
gauthier@circum.com (Benoit Gauthier) wrote in message news:<3b950ceb.22881610@news.videotron.ca>...
>In my view, this code should truncate the variable to 20 characters.
>It does not work. Why?
>$data = "1234567 101234567 201234567 30";
>print "$data\n";
>$data =~ s/(.{0-20})/$1/;
Others have explained why this doesn't work.
If the solution had to be a regex, you could use:
s/(?<=.{20}).*//s;
However, substr() should be your instinctive choice for a simple task like this.
Regards,
Ian
------------------------------
Date: Wed, 05 Sep 2001 03:27:07 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Why doesn't this regex work?
Message-Id: <3B959BFE.2466F1FA@acm.org>
Martien Verbruggen wrote:
>
> And this:
>
> $data = sprintf "%.20", $data;
$data = sprintf "%.20s", $data;
> or
>
> $data = pack "a20", $data;
John
--
use Perl;
program
fulfillment
------------------------------
Date: 4 Sep 2001 23:44:46 -0700
From: ianb@ot.com.au (Ian Boreham)
Subject: Re: Why doesn't this regex work?
Message-Id: <f02c4576.0109042244.2a906a58@posting.google.com>
ianb@ot.com.au (Ian Boreham) wrote in message news:<f02c4576.0109041814.1003b6ad@posting.google.com>...
> s/(?<=.{20}).*//s;
Actually,
s/(?<=.{20}).+//s;
would be better.
Ian
------------------------------
Date: Wed, 05 Sep 2001 08:06:34 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why doesn't this regex work?
Message-Id: <l7nbptg0spk6puu3uv22h1q1177jkpclke@4ax.com>
Martien Verbruggen wrote:
>And this:
>
>$data = sprintf "%.20", $data;
>
>or
>
>$data = pack "a20", $data;
What, no substr()?
--
Bart.
------------------------------
Date: Wed, 05 Sep 2001 08:47:58 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: Re: win32 rmdir questions
Message-Id: <3B95CA9E.DC47D25@sxb.bsf.alcatel.fr>
"John W. Krahn" wrote:
> Yes and the /s and /q switches to rd don't exist on Win9x. So the moral
> of the story is: if you want it portable, code it in perl. :-)
true ;-)
--
PhP
------------------------------
Date: Wed, 05 Sep 2001 08:47:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: win32 rmdir questions
Message-Id: <jdpbptcqdno7or1d7mcje5k5634te275cs@4ax.com>
Philippe PERRIN wrote:
>"John W. Krahn" wrote:
>> Yes and the /s and /q switches to rd don't exist on Win9x. So the moral
>> of the story is: if you want it portable, code it in perl. :-)
>
>true ;-)
Oh, this reminds me: File::Find is horribly slow on Win32 (at least on
Win98+FAT32). Simply listing a tree of 25000 files takes half an hour,
or an average of 15 files per second. Using the API is 60 times faster.
--
Bart.
------------------------------
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 1696
***************************************