[Webinar] Streamline your web hosting managementRegister Today


Can't split() from %Hash element

Posted on 1999-11-29
Medium Priority
Last Modified: 2010-03-05
Have a hash table with tab delimited elements. 'split()' won't break out the tokens of the hash element. Short of moving the hash element to a scalar before the split, is there anyway to access the tokens directly from the hash element?

$Presidents{"Nixon"} = "Pat\tTricia";
($Wife,$Daughter) = split("\t",$Presidents{"Nixon"});

This does not work. The scalars remain undefined.
Question by:snazzyrags

Expert Comment

ID: 2240627
Change this line:
%Presidents{"Nixon"} = "Pat\tTricia";


$Presidents{"Nixon"} = "Pat\tTricia";

Author Comment

ID: 2242307
Edited text of question.

Author Comment

ID: 2242311
Sorry, the first line was in error. However, the problem is in the second line. The content of the hash was intact, but cannot split it out.
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 85

Accepted Solution

ozo earned 400 total points
ID: 2242336
The second line should work.  How did you determine that it wasn't working?

Expert Comment

ID: 2245085

($Wife,$Daughter) = split(/\t/,$Presidents{"Nixon"});

Author Comment

ID: 2250413
You are correct - there was nothing wrong wiht the sample code I provided in the question. I should have tried it out - I would have answered my own question. The sample code was a paraphrase of the real code which was a very long hash value from a spreadsheet (of several columns). Problem was that I had left out one column definition, which shifted my variables into empty cells - therefore, undefined. When I printed the values in a debug statement, they were, naturally, undefined. Hence, my assumption that the code was not working. Thanks, for the simple, but definitive answer. It was your short, no-nonsense unquestionable response that made me review the code and find the problem. Thanks, Doug.

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question