Michael -- As I had earlier posited, it was just out of curiosity and the question was
more in tune with academic curiosity rather than pragmatic correctiveness.
I always used to have "named iterators", but when I was programming without them
today, this question came up to my mind instantaneou
On Mon, Sep 09, 2002 at 02:29:24PM -0700, RTO RTO wrote:
> $_ variable points to list in the outer-loop or
> inner-loop depending upon the scope. I prefer to not
> use aliases. In such a case, when I am in the scope of
> inner loop, can I access the looping variable on the
> outer without using an
Note: forwarded message attached.
__
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com
--- Begin Message ---
Tim -- Thanks for your rejoinder.
Mostly, I do use 'aliased' variables within nested
loops. However, t
You can't, exactly. You have just overwritten $_ with the second loop. The
only way you COULD do this is maybe by declaring $_ with local() somehow? I
don't know. Even if you could figure out how to do that, however, you would
be doing the same thing as creating a new variable, only you will
Here's one way:
#\d represents a digit
#this regex checks to see if every character (besides possibly a trailing
\n) is a digit
if($var =~ /^\d+$/){
do something...
}else{
don't
}
-Original Message-
From: Helen Dynah [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 17, 2002 11:4
On Wed, Apr 17, 2002 at 02:44:32PM -0400, Helen Dynah wrote:
> I was wondering how you would determine whether a variable is a number or
> not.
Use a regex, see perldoc -q 'is a number' or
http://www.perldoc.com/perl5.6.1/pod/perlfaq4.html, second question in the
"Data: Misc" section.
Michael
On Wed, 2002-04-10 at 11:10, Randal L. Schwartz wrote:
> > "Bob" == Bob Ackerman <[EMAIL PROTECTED]> writes:
>
> >> At no point do you have an "array" in a scalar context, or a "list"
> >> in a scalar context. Really. You don't. Ever. Get it?
> >>
> >> And why I'm harping on this is that
> "Bob" == Bob Ackerman <[EMAIL PROTECTED]> writes:
>> At no point do you have an "array" in a scalar context, or a "list"
>> in a scalar context. Really. You don't. Ever. Get it?
>>
>> And why I'm harping on this is that I've seen this myth continue to
>> perpetuate, started from some b
On Monday, April 8, 2002, at 12:15 PM, Randal L. Schwartz wrote:
>> "Chas" == Chas Owens <[EMAIL PROTECTED]> writes:
>
> Chas> I emphasize again, that is how I _read_ it. I know that there is no
> Chas> array() and I know why, but that doesn't change how I read things.
> This
> Chas> hac
> "Chas" == Chas Owens <[EMAIL PROTECTED]> writes:
Chas> I emphasize again, that is how I _read_ it. I know that there is no
Chas> array() and I know why, but that doesn't change how I read things. This
Chas> hack forces the far left hand bit to return as a list (by making
Chas> wantarray r
> $count = () = $string =~ /,/g;
> >>
> >> $string =~ /,/g;
> >>
> >> assigns the result in a list context - the anonymous list '()'. by
> >> assigning this to a scalar, $count, we get a value that is
> the size
> >> of the list, which is the number of matches that the regex
> made. that
On Mon, 2002-04-08 at 14:37, Randal L. Schwartz wrote:
> > "Chas" == Chas Owens <[EMAIL PROTECTED]> writes:
>
> >> There is no meaning for "list in a scalar context", so your statement
> >> makes no sense.
>
> Chas> my $some_scalar = () = /\s/g;
>
> Chas> I emphasize again, that is how I _r
> "Chas" == Chas Owens <[EMAIL PROTECTED]> writes:
>> There is no meaning for "list in a scalar context", so your statement
>> makes no sense.
Chas> my $some_scalar = () = /\s/g;
Chas> I emphasize again, that is how I _read_ it. I know that there is no
Chas> array() and I know why, but tha
> "Chas" == Chas Owens <[EMAIL PROTECTED]> writes:
Chas> With the downside that you have an array that you never use. Using ()
Chas> to force list context is one of those strange little quirks that you
Chas> just get used to. These days I read () as the array equivalent of
Chas> scalar().
On Monday, April 8, 2002, at 10:40 AM, Chas Owens wrote:
> On Mon, 2002-04-08 at 12:00, bob ackerman wrote:
>>
>> On Monday, April 8, 2002, at 06:24 AM, David Gray wrote:
>>
I believe it is as simple as:
$count = () = $string =~ /,/g;
>>>
>>> I can't seem to get my brain around
On Mon, 2002-04-08 at 12:00, bob ackerman wrote:
>
> On Monday, April 8, 2002, at 06:24 AM, David Gray wrote:
>
> >> I believe it is as simple as:
> >>
> >> $count = () = $string =~ /,/g;
> >
> > I can't seem to get my brain around what's happening here... would
> > someone be kind enough to ex
On Monday, April 8, 2002, at 06:24 AM, David Gray wrote:
>> I believe it is as simple as:
>>
>> $count = () = $string =~ /,/g;
>
> I can't seem to get my brain around what's happening here... would
> someone be kind enough to explain?
>
> -dave
$string =~ /,/g;
that finds all occurrences of
> I believe it is as simple as:
>
> $count = () = $string =~ /,/g;
I can't seem to get my brain around what's happening here... would
someone be kind enough to explain?
-dave
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
On Sat, Apr 06, 2002 at 11:32:01PM -0800, John W. Krahn wrote:
> And if you really want to get cute you can put it all on one line:
>
> substr( $ARGV[0], $_, 1 ) eq $ARGV[1] and $cnt++ for 0 .. length(
> $ARGV[0] ) - 1;
> print $cnt;
I count two lines ;-)
Both of these are a little obfuscated,
Aman Cgiperl wrote:
>
> Execute the following on cmd line as follows
> $./cnt.pl ,
> You can replace the comma (,) on the command line to find any other
> character's occurrence in the string
> ___
> #!/usr/bin/perl
>
> for(;$i $str[i] = substr($ARGV[0],$i,1);
>
Execute the following on cmd line as follows
$./cnt.pl ,
You can replace the comma (,) on the command line to find any other
character's occurrence in the string
___
#!/usr/bin/perl
for(;$imailto:[EMAIL PROTECTED]]
Sent: Friday, April 05, 2002 11:53 AM
To: [EMAIL PROTECTED]
On Fri, 2002-04-05 at 13:46, bob ackerman wrote:
> or, to continue to discussion:
> @s = $string =~ /,/g;
> print scalar @s,"\n";
>
> i don't know how to get count directly assigned to variable. someone?
>
I believe it is as simple as:
$count = () = $string =~ /,/g;
--
Today is Setting Ora
the /g switch of
> m//.
>
> while($string =~ /,/g){
>$num++;
> }
>
> -Original Message-
> From: Tanton Gibbs [mailto:[EMAIL PROTECTED]]
> Sent: Friday, April 05, 2002 10:06 AM
> To: Helen Dynah; [EMAIL PROTECTED]
> Subject: Re: Variable question
>
>
>
Just for the sake of argument, you can also do it using the /g switch of
m//.
while($string =~ /,/g){
$num++;
}
-Original Message-
From: Tanton Gibbs [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 05, 2002 10:06 AM
To: Helen Dynah; [EMAIL PROTECTED]
Subject: Re: Variable question
The tr operator will translate one character to another. For example:
my $string = "abc";
$string =~ tr/a/d/;
print $string;
prints
dbc;
However, it also returns the number of changes it did. So, if you don't
give it anything to change to, you can count how many occurrences of a
character we
25 matches
Mail list logo