Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Parsing list

by ww (Archbishop)
on Mar 02, 2014 at 13:19 UTC ( #1076715=note: print w/replies, xml ) Need Help??

in reply to Parsing list

I think I understand that you have some data (we'll discuss list later) comprised of something like this:

user:pass user1:pass1 use:pas ^ ^

What is the separator (ie, the character my caret's point to)? A space, semi-colon, LF, null or something else (including no separator at all)?

Now, as to "list" -- what's shown is a list. But is that what your source looks like (minus the assignment and the rest of the Perl-ish elements, or does your source look like this?

user:pass user1:pass1 use:pas

or, perhaps, like this (markup typo fixed here; thanks, kcott!)


For the first, a simple split statement will do very nicely; the second begs that you read the data into an array and use for $_(@array){.... while the third looks like an invitation to use the appropriate csv module to put you data into a format you know how to mung.

Update (illustration):

#!/usr/bin/perl use 5.016; use warnings; # NOT JUST BTW: this will not work without modification for some possi +ble forms of data! my $list = "user:passer use:pass user1:pass1"; say $list; say "That was \$list; these are the elements of \@arr:"; my @arr= split / /, $list; for (@arr) { say $_; my $current_element = $_; my ($first, $second) = split /:/, $current_element; say "\$first: $first & \$second: $second"; }


user:passer use:pass user1:pass1 That was $list; these are the elements of @arr: user:passer $first: user & $second: passer use:pass $first: use & $second: pass user1:pass1 $first: user1 & $second: pass1
Come, let us reason together: Spirit of the Monastery

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1076715]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2017-09-25 23:35 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (291 votes). Check out past polls.