#!/usr/bin/perl -w
use strict;
use warnings;
#the problem started with using split with the space delimeter
#this code only demonstrates my attempts to respect quoted strings
#while a user enters space separated commands and parameters
#command usage: adduser userid password fullname location accesslevel
#example command entered by hand is:
#adduser emp09 password "Al Bundy" "Main Building" full
#
#a variable would become:
my $command = "adduser emp09 password \"Al Bundy\" \"Main Building\" full";
my @parameters;
print "Output 1\n";
print "$command\n";
#using split by a space delimeter would yeild 8 parameters, there should
#be only 6 if the quoted strings were not split
@parameters = split / /, $command;
print "$_\n" foreach @parameters;
#I've chosen to modify $command and add a ':' character (used as
reserved character)
#in place of any space that is inside of a quoted string
$command =~ s/(".*) (.*")/$1:$2/g;
#remove the quotes
$command =~ s/\"//g;
print "\nOutput 2\n";
print "$command\n";
@parameters = split / /, $command;
foreach (@parameters) {
$_ =~ s/:/ /g;
print "$_\n";
}
#This is start towards a solution, however it is not working for both
sets of quoted
#strings. Al Bundy should be one parameter instead of two as well.
#I assume this is caused by the reqex I've written. I also want to make
sure I'm not
#going about this the hard way or reinventing the wheel
_______________________________________________
Perl-Unix-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs