toadi has asked for the wisdom of the Perl Monks concerning the following question:
I just wanted to parse the file to get all the values.testuser Authentication-Type = Unix-PW User-Service = Framed-user, Ascend-Idle-Limit = 600, Framed-Protocol = PPP, Framed-Address = 222.222.222.222, Framed-Netmask = 255.255.255.255, Ascend-Route-IP = Route-IP-Yes, Ascend-Metric = 3 test2user Password = "Testpassword" Framed-Protocol = PPP, Ascend-Idle-Limit = 600
I get always undefined values because I try to print out variables that haven't a value. Erm this is what I think is the problem.#!/usr/bin/perl -w # # ##################################################################### use strict; open (FILE,"<users.merit") or die ("users_merit nie ge-opend"); my ($login,$password,$user_service,$framed_protocol,$framed_address,$f +ramed_netmask,$ascend_route_IP,$ascend_metric,$ascend_idle_limit); while(<FILE>){ next if /^#/; chomp; if($_ =~ /^\w/){ m/(.*)(Password = |Authentication-Type = )(.*)/; ($login,$password) = ($1,$3); $login =~ s/\s+$//; $password =~ s/\"//g; }elsif($_ =~ /^\s/){ if($_ =~ /(User-Service = )(.*)(,)/){ $user_service = $2; } if($_ =~ /(Framed-Protocol = )(.*)(,)/){ $framed_protocol = $2; } if($_ =~ /(Framed-Address = )(.*)(,)/){ $framed_address = $2; } if($_ =~ /(Framed-Netmask = )(.*)(,)/){ $framed_netmask = $2; } if($_ =~ /(Ascend-Route-IP = )(.*)(,)/){ $ascend_route_IP = $2; } if($_ =~ /(Ascend-Metric = )(.*)(,)/){ $ascend_metric = $2; } if($_ =~ /(Ascend-Idle-Limit = )(.*)(,)/){ $ascend_idle_limit = $2; } } print "$login:$password\n"; print "$user_service\n"; print "$framed_protocol\n"; print "$framed_address\n"; print "$framed_netmask\n"; print "$ascend_route_IP\n"; print "$ascend_metric\n"; print "$ascend_idle_limit\n\n"; } close FILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: strict
by autark (Friar) on Nov 22, 2000 at 16:20 UTC | |
by toadi (Chaplain) on Nov 22, 2000 at 17:14 UTC | |
by ChOas (Curate) on Nov 22, 2000 at 17:28 UTC | |
|
Re: strict
by ChOas (Curate) on Nov 22, 2000 at 16:14 UTC | |
|
Re: strict
by rpc (Monk) on Nov 22, 2000 at 23:40 UTC | |
|
Re: strict
by curtisb (Monk) on Nov 23, 2000 at 03:56 UTC | |
by toadi (Chaplain) on Nov 23, 2000 at 13:42 UTC | |
by curtisb (Monk) on Nov 23, 2000 at 13:46 UTC |