Help needed with CGI script (a very simple problem) 
Author Message
 Help needed with CGI script (a very simple problem)

Hello,

I'm trying to make my own CGI scripts but I'm a beginner. That's why I
need your help with this simple problem. How can I change a string of
words separated by spaces into a string of words separated by commas?

Example:
-------------
I will like to change

"please help me with this simple problem"

into

"please,help,me,with,this,simple,problem"

Best Regards,

Farley



Wed, 03 Jan 2001 03:00:00 GMT  
 Help needed with CGI script (a very simple problem)
i assume you want you want this?

my $a = 'i have no comma';
$a =~ s/ /,/g;

(probably a much better way to do it but I'm still learning Perl myself)
--
Ken C. - still learning Perl
remove zz's for reply



Wed, 03 Jan 2001 03:00:00 GMT  
 Help needed with CGI script (a very simple problem)
: i assume you want you want this?
: my $a = 'i have no comma';
: $a =~ s/ /,/g;
: (probably a much better way to do it but I'm still learning Perl myself)

        Well, you could use \s+ instead of just a single space to
        avoid creating "some,,,thing,like,,this", but that's about
        the only thing I'd do differently.  If I wanted to get real fancy
        I might match on word boundaries (\b), but I'd have to be looking
        for more work. :-)

        Nope, I'd say you've pretty much got the best basic idea down
        well. ;-)
--

BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".



Wed, 03 Jan 2001 03:00:00 GMT  
 Help needed with CGI script (a very simple problem)

Quote:

>: i assume you want you want this?
>: my $a = 'i have no comma';
>: $a =~ s/ /,/g;
>: (probably a much better way to do it but I'm still learning Perl myself)

>    Well, you could use \s+ instead of just a single space to
>    avoid creating "some,,,thing,like,,this", but that's about
>    the only thing I'd do differently.  If I wanted to get real fancy
>    I might match on word boundaries (\b), but I'd have to be looking
>    for more work. :-)

>    Nope, I'd say you've pretty much got the best basic idea down
>    well. ;-)

Or, you could split() the string, into an array, like this:

(and like you suggest, \s+ is probably cleaner/better)

s/// is probably the cleanest approach, but loading it into an array
may provide more options for manipulating the data later (like
allowing you to sort the words alphabetically, or whatever)



Thu, 04 Jan 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Need a Simple but Unique CGI script - please help

2. cgi script with path_info problem, some help needed

3. Need help with simple CGI procedure..

4. Need help with simple cgi code

5. need help with simple perl CGI form

6. need help with simple script

7. need help with simple script

8. need help with simple script

9. Need help debugging this simple script

10. need help with simple script

11. Perl idiot needs help with simple script

12. Need help with simple parsing script

 

 
Powered by phpBB® Forum Software