[ale] OFFTOPIC: Perl -w oddities?
Mike Fletcher
fletch at phydeaux.org
Mon Feb 1 14:31:27 EST 1999
>>>>> "Nomad" == Nomad the Wanderer <nomad at orci.com> writes:
Nomad> I ended up using @Name in the split isntead of $Name,
Nomad> otherwise I loose values if the name has spaces in it. If
Nomad> I wanted to do:
Nomad> ( $Track, $Name ) = (split( ' ', $_, 4 ))[1,3];
Nomad> but instead of 3, do 3-eol, what would I do?
That's in effect what the third argument to split (the 4)
does. That tells split that you want it to split $_ on whitespace
into at most 4 fields. So if you had:
Zagnut Frobnitz Spam This is the rest
$Track would be `Frobnitz' and $Name would be `This is the rest'.
`perldoc -f split' explains this (and the difference between splitting
on ' ' and /\s*/).
Nomad> The print statements give me this:
Nomad> $Track `01' $Name: `The Dam At Otter Creek'
[...]
Nomad> so they are all initialized. It also complains because I'm
Nomad> using @Name with $Track, saying it should be associative.
Are you trying to do:
$Hash{ $Track } = @Name;
Or what? In that case, you'ld be storing the size (number of
elements) of @Name, not the contents of @Name.
Nomad> I guess it's interpiting the 01 as a string. Know a way to
Nomad> clean this up? Using it as a numeric works fine.
Hash keys are always strings (e.g. `1' and `01' are distinct
keys in the hash). You could always use sprintf to normalize your
digits to zero-filled/non-zero-filled before using them as keys.
--
Fletch | __`'/|
fletch at phydeaux.org | "I drank what?" -- Socrates \ o.O'
678 443-6239(w) | =(___)=
| U
More information about the Ale
mailing list