Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: Parse a file into a hash

by kazak (Beadle)
on Apr 06, 2012 at 14:50 UTC ( #963829=note: print w/replies, xml ) Need Help??


in reply to Re^3: Parse a file into a hash
in thread [Resolved] Parse a file into a hash

Thanks for your reply. I don't know how to preserve initial format of the file here, so I'll replace empty cells of.csv with null.

Username; Asset Name

Corinna Mayer;JKDef4574

Janek Huska;NAdf8f48g5

Eric Shtits;JSd5345kPFl

null;A878rfgP56

null;KDLefrtgt

Erik Fisher;UiO8trve

As you can see Eric Shtits owns 3 asset names in according to this .csv file, so two fields that supposed to be keys are empty.And I need to implement a solution that will be able to detect that all three asset names belong to one person. Regards, Kazak

Replies are listed 'Best First'.
Re^5: Parse a file into a hash
by mendeepak (Scribe) on Apr 07, 2012 at 05:55 UTC

    hi check if this code works or not its not tested.

    my ($key,$val,$keyprev); open(fh,'< file.txt'); while (<fh>){ $keyprev=$key; ($key,$val)=split /\;/, $_; $key=$keyprev if($key eq""); print "$key :: $val\n"; } close fh;

      Yes it helped. Thanks to everyone.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://963829]
help
Chatterbox?
[robby_dobby]: LanX: Well volunteered!
[LanX]: ... just ... ppl would be to afraid of terrorist attacks
[choroba]: python guerrila?
[robby_dobby]: if I do make it, I can at least savour their local tea! :-)
[LanX]: oh they have sleper cells everywhere
[robby_dobby]: LanX: Not really, the only problems would be from religious divides. Coptics/Moslems/ Kurds/Jews
[erix]: Zzz
[erix]: Coptics? :)
[robby_dobby]: erix: Coptic Christians in Egypt
[choroba]: Robocoptic!

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (15)
As of 2017-04-24 16:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (442 votes). Check out past polls.