Re: comparing srtings
Thanks guys, that helped alot!!! what about doing something like this: if ($slurp =~ /defaultusername=(.+)/i) { $usr = $1; } else { print no defualtusername entry!! for $file; } if ($slurp =~ /defaultpassword=(.+)/i) { $pass = $1; } else { print No default password entry; } as part of a larger script is that safe? becuase the $pass and $usr would be processed in the Larger part of the script. ? thoughts? and thanks! -Nex6 Nex6 wrote: I am trying to Compare 2 strings for an if statement in an admin script. $slurp is an entire file, and $file is a name. what i would like to do is compare the 2, basicly saying if this = that do this otherwise do this. i have the if statement and stuff right i just need help with the compare. $slurp =~ /defaultusername=(.+)/i; $usr = $1; print printing the value of the test var: $usr\n; if ($file = $usr){ print username: $file; -Nex6 ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: comparing srtings
Nex6 wrote: Thanks guys, that helped alot!!! what about doing something like this: if ($slurp =~ /defaultusername=(.+)/i) { (.+) should probably be (.+?) to limit the match to the shortest path unless you know there are no more s after it. The RE will try for the longest match without the ?. $usr = $1; } else { print no defualtusername entry!! for $file; } if ($slurp =~ /defaultpassword=(.+)/i) { Same here. $pass = $1; } else { print No default password entry; } as part of a larger script is that safe? becuase the $pass and $usr would be processed in the Larger part of the script. ? thoughts? -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: comparing srtings
$Bill Luebkert [EMAIL PROTECTED] wrote: Nex6 wrote: if ($slurp =~ /defaultusername=(.+)/i) { (.+) should probably be (.+?) to limit the match to the shortest path unless you know there are no more s after it. In this case it makes no difference, but in general a negated character class is less likely to lead to unexpected matching than a nongreedy modifier is. That is, I'd use '([^]+)' rather than '(.+?)'. To see why I prefer the negated character class, consider a regex like /a href=(.*?)/ Because of the nongreediness, it's true that the matching won't get completely out of control, but suppose the string being matched against is a href=/whatever/ target=_blankLink img src=abc.gif/a Now the captured string is '/whatever/ target=_blankLink img src=abc.gif', which presumably was not intended. With '([^]+)', the match would have failed, which may have been the intent. If not, the failure should at least indicate there may be a problem with the regex. -- Keith C. Ivey [EMAIL PROTECTED] Washington, DC ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: comparing srtings
[EMAIL PROTECTED] wrote: I am trying to Compare 2 strings for an if statement in an admin script. $slurp is an entire file, and $file is a name. what i would like to do is compare the 2, basicly saying if this = that do this otherwise do this. i have the if statement and stuff right i just need help with the compare. $slurp =~ /defaultusername=(.+)/i; $usr = $1; print printing the value of the test var: $usr\n; if ($file = $usr){ This is assigning $usr to $file and if $file ture then print. What you are realy trying to do is string compare which would be eq. To do a numeric compare reguires ==. So if ( $file eq $usr ) { # true }else { #false } Wags ;) print username: $file; -Nex6 *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: comparing srtings
Try: if ($file eq $usr) since your comparing strings. FYI, the single = is an assignment, -vs- == -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nex6 Sent: Wednesday, June 30, 2004 7:00 AM To: perl-win32-users Subject: comparing srtings I am trying to Compare 2 strings for an if statement in an admin script. $slurp is an entire file, and $file is a name. what i would like to do is compare the 2, basicly saying if this = that do this otherwise do this. i have the if statement and stuff right i just need help with the compare. $slurp =~ /defaultusername=(.+)/i; $usr = $1; print printing the value of the test var: $usr\n; if ($file = $usr){ print username: $file; -Nex6 ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs