But I thought this was related to more than just with(), so if we have
foreach (1..10)
{
print;
### But if you are trying to use it in a string
print "This is number $_ of 10\n";
### Would now have to be printed as
print "This is number ";
print;
print " of 10\n";
### Which is three extra statement.
}
I still believe that although not defining a variable source will use the
temp variable there is still a need for an explicit scalar like $_.
Unless there is something I am missing from this discussion.
Ilya
-----Original Message-----
From: Stuart Rocks
To: [EMAIL PROTECTED]
Sent: 07/19/2001 11:31 AM
Subject: Re: aliasing - was:[nice2haveit]
> >Then how would you write "I am not a coward"
>
> with ($foo)
> {
> print "I am not a"; ##What do I use here or do I have to issue a
> ##separate print like...
> print;
> }
>
> Ilya
Well in Perl5, for the print to use default value it's just 'print;'.
The
same applies for alot (all?) of Perl5 functions. The default value is
always
(as far as I know) $_ or @_ depending on the context.
Both the following would work:
with($foo){
print "I am not a $foo\n";
# or:
print "I am not a ";
print;
}
The idea for this style of C<With>, came because I don't see why the
default
has to always be $_. Often the amount of code required would be able to
be
dramatically reduced if 'default value' was userdefinable for blocks
with
the With command.
(All opinions in this post are not representative of Monkey Coward)