David->"Hmmm...  OK, so that explains it, but I still don't get it...  So
the match is going to spit out a scalar but in order to use it you have to
capture it in a list context?"

No, actually the opposite.  The match returns a list, but split() was
reading the list as a scalar.  Thus:

  ($fullpath =~ m:/mp3/(.+):)[0]

is element 0 of the list created by evaluating the match.  That way what
split sees is a scalar (the element), so it can split it accordingly.



-----Original Message-----
From: David T-G
To: perl beginners
Cc: Timothy Johnson
Sent: 6/9/02 7:51 PM
Subject: Re: shifting solved (was "Re: chomp-ing DOS lines, shifting, and a
variable variable")

Timothy, et al --

....and then Timothy Johnson said...
% 
% Ok, I finally got a chance to test it, and the problem with my code is
that
% split expects a scalar as the second argument.  This does work:
% 
%   ($temp) = $fullpath =~ m:/mp3/(.+):;
%   @working = split /\//,$temp;
% 
% because it is taking the list returned by the match and assigning it
to the
% list with $temp as the only element.  If I did this:

Hmmm...  OK, so that explains it, but I still don't get it...  So the
match is going to spit out a scalar but in order to use it you have to
capture it in a list context?


% 
%   $temp = $fullpath =~ m:/mp3/(.+):;
%   @working = split /\//,$temp;
% 
% then @working would be 1 because $temp is evaluating the list in
scalar
% context, which returns the number of elements.

I saw that.


% DISCLAIMER:  Someone please correct me if I am not using the
appropriate
% terminology.  The upside of what I mean is that if you do a $scalar =
% @array, then the variable $scalar now has the value of the number of
% elements in the array.

Right; that sounds familiar.


% 
% Anyhoo, now we know why my suggestion didn't work.  What we need to
do, then
% is give split the first element of the list.  Try this:
% 
% @working = split(/\//,($fullpath =~ m:/mp3/(.+):)[0]);

That works perfectly, but I'm still fuzzy.  So we match $fullpath and we
have to put it in () to bind the =~ properly, I suppose, and *that* is
what messes us up when we try to split and so we have to extract a
scalar
from that list, and we do that with [0], right?

I tried {} and [] and nothing and none of them bound the =~ properly, so
it looks like () is the only way to do that.  Is there a way to bind
that
won't force a list context?


Thanks a bunch! & TIA & HAND

:-D
-- 
David T-G                      * It's easier to fight for one's
principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune
cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/    Shpx gur Pbzzhavpngvbaf Qrprapl
Npg!


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to