CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Spliting!!!!

 



andy7t
User

Jun 16, 2002, 7:44 AM

Post #1 of 2 (587 views)
Spliting!!!! Can't Post

How would i split this so i can just make $login just andy:

LOGIN= andy; PAGE=example.html; SOMETHINGELSE = something;
Thanks.


davorg
Thaumaturge / Moderator

Jun 16, 2002, 8:47 AM

Post #2 of 2 (584 views)
Re: [andy7t] Spliting!!!! [In reply to] Can't Post

[I've just answered this in a private message. Here's a copy of what I said. Please don't send me private messages containing questions that you've posted to the public boards]

Depends how fixed your data format is, but with the data you've shown I'd do something like

Code
my $login = (split /[=;\s]+/, $txt)[1];

To be more flexible I'd set up a hash containing all of the values

Code
my %data = split /[=;\s]+/, $txt; 

print $data{LOGIN}, "\n";

# or

foreach (sort keys %data) {
print "$_ => $data{$_}\n";
}


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives