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:pasFor 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
|
---|