Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Parsing list

by ww (Bishop)
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!)

user:pass,user1:pass1,use:pas

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"; }

Output:

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


Comment on Re: Parsing list
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-12-25 02:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls