Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Split Not Working Correctly?

by Random_Walk (Prior)
on Jan 08, 2014 at 15:21 UTC ( [id://1069820]=note: print w/replies, xml ) Need Help??


in reply to Split Not Working Correctly?

How are you assigning @subjects to PN? Where does the value of $call come from?

use strict; use warnings; use Data::Dumper; my @subjects = split /, /, "foo, bar, baz"; my %lc_class; $lc_class{PN} = \@subjects; print Dumper \%lc_class;

Update

Here is a more extensive example of splitting and storing...

use strict; use warnings; use Data::Dumper; # a home for our results my %lc_class; # read data from the end of the script # a handy testing tool while (my $line = <DATA>) { chomp $line; # remove newline # split each line on =, optionaly surounde by space, max 2 parts my ($class, $subj) = split /\s*=\s*/, $line, 2; # split the subject on , (optional space) my @subjects = split /\s*,\s*/, $subj; # store a reference to the @subjects array $lc_class{$class} = \@subjects; } # show and tell print Dumper \%lc_class; __DATA__ PN = this, that, the other GN = something RT = test with some space, testwithout, And more space
Output:
$VAR1 = { 'RT' => [ 'test with some space', 'testwithout', 'And more space' ], 'PN' => [ 'this', 'that', 'the other' ], 'GN' => [ 'something' ] };

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^2: Split Not Working Correctly?
by Hans Castorp (Sexton) on Jan 08, 2014 at 16:16 UTC

    Nice! Thanks RW. I'm going to try to post an abbreviated form of the script so people can have a better idea of what it's doing. Still working on it, though.

Re^2: Split Not Working Correctly?
by Hans Castorp (Sexton) on Feb 06, 2014 at 17:23 UTC

    Hi RW, I just figured out there was a subroutine running that took out all duplicate records. Split was working as it should. ;-)

    Thank you so much for your help. I learn a lot each time I ask for help here.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-16 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found