Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: split() Problem

by Omukawa (Acolyte)
on Jul 22, 2008 at 09:51 UTC ( [id://699247]=note: print w/replies, xml ) Need Help??


in reply to split() Problem

Sorry for the obscurities. As I said, I use hashes of hashes to store dictionary entries. So %edict{0} contains the first entry (0 is the key to the embedded hash) and &edict{0}{english} contains the english translation. That's mostly one word like "house" etc. but sometimes there are entries like "office; court; ....". That's why the split looks for "; ", since there is always a whitespace after the semicolon.

What I'm trying to do is to split the entry with more than one english words, put the them in the array @foo and then take the first word from @foo, put it in another array @engdict with other information belongs to it, so that I will have two seperate scalars in @engdict: One is office : xyz, and the other is court : xyz.

So that's what the code must do: 1. Find the entry about english translation with more than one word inside, seperated by "; " 2. Put them seperately in the array @foo 3. Take the first word from @foo and put it in $engdict[$no] with other information 4. Add one to $no 5. Take the second word and put it in $engdict[$no+1] and so on.

The problem is this is not working as I thought. The $foo[$_] is always empty so I think I'm doing something wrong with the split() command but I can't see the mistake. So here is my question: Can you tell me the mistake here?

Thank you

Replies are listed 'Best First'.
Re^2: split() Problem
by moritz (Cardinal) on Jul 22, 2008 at 10:08 UTC
    I think your problem is that you do too much at once without testing the result from the intermediate steps.

    Most of my scripts start with

    # always use those: use strict; use warnings; use Data::Dumper;

    When you suspect that split isn't working the way you think it is, try adding the line print Dumper \@foo; immediately after the split, and look if the results are what you execpted it to be.

    The $foo[$_] is always empty so

    for iterates over the values in the array, not the indexes. So instead of $foo[$_] just write $_.

      Changing $foo[$_] with $_ solved the problem. Thanks a lot. Also thank you for the advice about Data::Dumper

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://699247]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-29 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found