From HPhillips at harrahs.com Tue Nov 12 10:23:52 2002 From: HPhillips at harrahs.com (Hal Phillips) Date: Thu Aug 5 00:07:20 2004 Subject: [Memphis.pm] quotes in program arguments Message-ID: Hey, does anyone know how to tell perl to interpret quotes in a program argument as just part of a string? More precicely, I need something that basically will take the equivalant of echo's $* as a command argument. What I neet to do is have a perl program that I can to this with: >program.pl -o [2002-11-12 09:00:00]: subject=SOMETEXT, message={SEVERITY="ERROR", ACTION="None", MOREKEYS="MOREVALUES", ETC="ETC ETC ETC"} You may ask, why not just redirect the message as STDIN? Well, the calling program is very limited in it's interface in that it collects the message information into a variable via java, then provides an opportunity for you to fill in a box with a UNIX command. So, I'd need to somehow push it into STDIN through a pipe, and echo is out for the same reasons I'm trying to solve with the quotes in $message. i.e. echo $message | program.pl doesn't work because of the content of $message. So, I need it to do: program.pl -o $message I've tried to be sneaky and read in the option a char at at time, but the quotes are still being interpreted on the command line. #!/usr/bin/perl use Getopt::Std; getopt("o:"); @array = split (//, $opt_o); foreach $char (@array) { if ( $char eq "\"" ) { $char = "\\$char"; } $message .= $char; } print $message; > program.pl -o Sam"I"am SamIam what I need is Sam"I"am to actually make it through uninterpreted. Anyway, sorry to ramble, let me know if you have any suggestions. -Hal ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From STurman at harrahs.com Tue Nov 12 11:16:05 2002 From: STurman at harrahs.com (Steven Turman) Date: Thu Aug 5 00:07:20 2004 Subject: [Memphis.pm] quotes in program arguments Message-ID: <66777692ADA76C4D9C2CA3D519BE3ED00CC394@entcmail1.harrahs.org> When program.pl is called, put $message in double quotes. quotes.pl as: #!/usr/bin/perl print( join( "\n", @ARGV ), "\n" ); $>quotes.pl 1 2 3 4 1 2 3 4 $>quotes.pl "1 2 3 4" 1 2 3 4 $>message="stuff \"stuff\" more stuff" $>print $message stuff "stuff" more stuff $>quotes.pl "$message" stuff "stuff" more stuff -Steven -----Original Message----- From: Hal Phillips Sent: Tuesday, November 12, 2002 10:24 AM To: 'memphis-pm-list@pm.org' Subject: [Memphis.pm] quotes in program arguments Hey, does anyone know how to tell perl to interpret quotes in a program argument as just part of a string? More precicely, I need something that basically will take the equivalant of echo's $* as a command argument. What I neet to do is have a perl program that I can to this with: >program.pl -o [2002-11-12 09:00:00]: subject=SOMETEXT, message={SEVERITY="ERROR", ACTION="None", MOREKEYS="MOREVALUES", ETC="ETC ETC ETC"} You may ask, why not just redirect the message as STDIN? Well, the calling program is very limited in it's interface in that it collects the message information into a variable via java, then provides an opportunity for you to fill in a box with a UNIX command. So, I'd need to somehow push it into STDIN through a pipe, and echo is out for the same reasons I'm trying to solve with the quotes in $message. i.e. echo $message | program.pl doesn't work because of the content of $message. So, I need it to do: program.pl -o $message I've tried to be sneaky and read in the option a char at at time, but the quotes are still being interpreted on the command line. #!/usr/bin/perl use Getopt::Std; getopt("o:"); @array = split (//, $opt_o); foreach $char (@array) { if ( $char eq "\"" ) { $char = "\\$char"; } $message .= $char; } print $message; > program.pl -o Sam"I"am SamIam what I need is Sam"I"am to actually make it through uninterpreted. Anyway, sorry to ramble, let me know if you have any suggestions. -Hal ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From sml at zfx.com Tue Nov 12 11:20:21 2002 From: sml at zfx.com (Steve Lane) Date: Thu Aug 5 00:07:20 2004 Subject: [Memphis.pm] quotes in program arguments References: Message-ID: <3DD13855.2995985F@zfx.com> Hal Phillips wrote: > > Hey, does anyone know how to tell perl to interpret quotes in a program > argument as just part of a string? More precicely, I need something that > basically will take the equivalant of echo's $* as a command argument. > > What I neet to do is have a perl program that I can to this with: > >program.pl -o [2002-11-12 09:00:00]: subject=SOMETEXT, > message={SEVERITY="ERROR", ACTION="None", MOREKEYS="MOREVALUES", ETC="ETC > ETC ETC"} [snip] > > program.pl -o Sam"I"am > SamIam > > what I need is Sam"I"am to actually make it through uninterpreted. this has nothing to do with Perl; it's a shell question. your shell acts on the double-quotes before they ever reach perl. the same would happen if you had any of [*?'><&] (etc) in your argument. just single-quote your argument: $ echo Sam"I"am SamIam $ echo 'Sam"I"am' Sam"I"am if your argument has single-quotes, you'll have to escape them, in your preferred way of shell-single-quote-escaping, such as: $ echo 'Sam"I"a'"'"'m' Sam"I"a'm -- Steve Lane ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From HPhillips at harrahs.com Tue Nov 12 11:40:25 2002 From: HPhillips at harrahs.com (Hal Phillips) Date: Thu Aug 5 00:07:20 2004 Subject: [Memphis.pm] quotes in program arguments Message-ID: Thanks, but I can't modify the message to put the \s in... -----Original Message----- From: Steven Turman Sent: Tuesday, November 12, 2002 11:16 AM To: 'memphis-pm-list@pm.org' Subject: RE: [Memphis.pm] quotes in program arguments When program.pl is called, put $message in double quotes. quotes.pl as: #!/usr/bin/perl print( join( "\n", @ARGV ), "\n" ); $>quotes.pl 1 2 3 4 1 2 3 4 $>quotes.pl "1 2 3 4" 1 2 3 4 $>message="stuff \"stuff\" more stuff" $>print $message stuff "stuff" more stuff $>quotes.pl "$message" stuff "stuff" more stuff -Steven -----Original Message----- From: Hal Phillips Sent: Tuesday, November 12, 2002 10:24 AM To: 'memphis-pm-list@pm.org' Subject: [Memphis.pm] quotes in program arguments Hey, does anyone know how to tell perl to interpret quotes in a program argument as just part of a string? More precicely, I need something that basically will take the equivalant of echo's $* as a command argument. What I neet to do is have a perl program that I can to this with: >program.pl -o [2002-11-12 09:00:00]: subject=SOMETEXT, message={SEVERITY="ERROR", ACTION="None", MOREKEYS="MOREVALUES", ETC="ETC ETC ETC"} You may ask, why not just redirect the message as STDIN? Well, the calling program is very limited in it's interface in that it collects the message information into a variable via java, then provides an opportunity for you to fill in a box with a UNIX command. So, I'd need to somehow push it into STDIN through a pipe, and echo is out for the same reasons I'm trying to solve with the quotes in $message. i.e. echo $message | program.pl doesn't work because of the content of $message. So, I need it to do: program.pl -o $message I've tried to be sneaky and read in the option a char at at time, but the quotes are still being interpreted on the command line. #!/usr/bin/perl use Getopt::Std; getopt("o:"); @array = split (//, $opt_o); foreach $char (@array) { if ( $char eq "\"" ) { $char = "\\$char"; } $message .= $char; } print $message; > program.pl -o Sam"I"am SamIam what I need is Sam"I"am to actually make it through uninterpreted. Anyway, sorry to ramble, let me know if you have any suggestions. -Hal ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From HPhillips at harrahs.com Tue Nov 12 11:41:10 2002 From: HPhillips at harrahs.com (Hal Phillips) Date: Thu Aug 5 00:07:20 2004 Subject: [Memphis.pm] quotes in program arguments Message-ID: Thanks, but the problem is that I can't modify the incoming message before I see it. -----Original Message----- From: Steve Lane [mailto:sml@zfx.com] Sent: Tuesday, November 12, 2002 11:20 AM To: memphis-pm-list@pm.org Subject: Re: [Memphis.pm] quotes in program arguments Hal Phillips wrote: > > Hey, does anyone know how to tell perl to interpret quotes in a program > argument as just part of a string? More precicely, I need something that > basically will take the equivalant of echo's $* as a command argument. > > What I neet to do is have a perl program that I can to this with: > >program.pl -o [2002-11-12 09:00:00]: subject=SOMETEXT, > message={SEVERITY="ERROR", ACTION="None", MOREKEYS="MOREVALUES", ETC="ETC > ETC ETC"} [snip] > > program.pl -o Sam"I"am > SamIam > > what I need is Sam"I"am to actually make it through uninterpreted. this has nothing to do with Perl; it's a shell question. your shell acts on the double-quotes before they ever reach perl. the same would happen if you had any of [*?'><&] (etc) in your argument. just single-quote your argument: $ echo Sam"I"am SamIam $ echo 'Sam"I"am' Sam"I"am if your argument has single-quotes, you'll have to escape them, in your preferred way of shell-single-quote-escaping, such as: $ echo 'Sam"I"a'"'"'m' Sam"I"a'm -- Steve Lane ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From sml at zfx.com Tue Nov 12 11:58:13 2002 From: sml at zfx.com (Steve Lane) Date: Thu Aug 5 00:07:20 2004 Subject: [Memphis.pm] quotes in program arguments References: Message-ID: <3DD14135.B88F2874@zfx.com> Hal Phillips wrote: > Thanks, but the problem is that I can't modify the incoming message before I > see it. i don't understand why you can't just put single quotes around the argument, but anyway... you're S-O-L then. again, it's the shell, not perl, that's the cause of your problem. -- Steve > -----Original Message----- > From: Steve Lane [mailto:sml@zfx.com] > Sent: Tuesday, November 12, 2002 11:20 AM > To: memphis-pm-list@pm.org > Subject: Re: [Memphis.pm] quotes in program arguments > > Hal Phillips wrote: > > > > Hey, does anyone know how to tell perl to interpret quotes in a program > > argument as just part of a string? More precicely, I need something that > > basically will take the equivalant of echo's $* as a command argument. > > > > What I neet to do is have a perl program that I can to this with: > > >program.pl -o [2002-11-12 09:00:00]: subject=SOMETEXT, > > message={SEVERITY="ERROR", ACTION="None", MOREKEYS="MOREVALUES", ETC="ETC > > ETC ETC"} > [snip] > > > program.pl -o Sam"I"am > > SamIam > > > > what I need is Sam"I"am to actually make it through uninterpreted. > > this has nothing to do with Perl; it's a shell question. > your shell acts on the double-quotes before they ever reach > perl. the same would happen if you had any of [*?'><&] (etc) > in your argument. > > just single-quote your argument: > > $ echo Sam"I"am > SamIam > $ echo 'Sam"I"am' > Sam"I"am > > if your argument has single-quotes, you'll have to escape them, > in your preferred way of shell-single-quote-escaping, such as: > > $ echo 'Sam"I"a'"'"'m' > Sam"I"a'm > > -- > Steve Lane > ---------------------------------------------------------------------------- > To unsubscribe, please send email to majordomo@pm.org > with 'unsubscribe memphis-pm-list' in the body of the message. > ---------------------------------------------------------------------------- > > ---------------------------------------------------------------------------- > To unsubscribe, please send email to majordomo@pm.org > with 'unsubscribe memphis-pm-list' in the body of the message. > ---------------------------------------------------------------------------- -- Steve Lane ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From HPhillips at harrahs.com Tue Nov 12 13:39:01 2002 From: HPhillips at harrahs.com (Hal Phillips) Date: Thu Aug 5 00:07:20 2004 Subject: [Memphis.pm] quotes in program arguments Message-ID: Hmmm,... I'll try the single quote thing. Thanks for the tip. It may work as long as the incomming message has no single quotes,... unfortunately the possibility is there and I cannot modify the message. Yes, I agree it is a shell issue and not a perl one specifically, however the shell is the interface used to call the perl, it would be nice to have away around this issue via an argument or switch... It's interesting that if the message is strictly STDIN, it works. i.e. >cat file_containing_message|program.pl while() { @array = split //; } foreach $c (@array) { if ( $c eq "\"" ) { $c = "\\$c"; } $newstring .= $c; } print $newstring; -----Original Message----- From: Steve Lane [mailto:sml@zfx.com] Sent: Tuesday, November 12, 2002 11:58 AM To: memphis-pm-list@pm.org Subject: Re: [Memphis.pm] quotes in program arguments Hal Phillips wrote: > Thanks, but the problem is that I can't modify the incoming message before I > see it. i don't understand why you can't just put single quotes around the argument, but anyway... you're S-O-L then. again, it's the shell, not perl, that's the cause of your problem. -- Steve > -----Original Message----- > From: Steve Lane [mailto:sml@zfx.com] > Sent: Tuesday, November 12, 2002 11:20 AM > To: memphis-pm-list@pm.org > Subject: Re: [Memphis.pm] quotes in program arguments > > Hal Phillips wrote: > > > > Hey, does anyone know how to tell perl to interpret quotes in a program > > argument as just part of a string? More precicely, I need something that > > basically will take the equivalant of echo's $* as a command argument. > > > > What I neet to do is have a perl program that I can to this with: > > >program.pl -o [2002-11-12 09:00:00]: subject=SOMETEXT, > > message={SEVERITY="ERROR", ACTION="None", MOREKEYS="MOREVALUES", ETC="ETC > > ETC ETC"} > [snip] > > > program.pl -o Sam"I"am > > SamIam > > > > what I need is Sam"I"am to actually make it through uninterpreted. > > this has nothing to do with Perl; it's a shell question. > your shell acts on the double-quotes before they ever reach > perl. the same would happen if you had any of [*?'><&] (etc) > in your argument. > > just single-quote your argument: > > $ echo Sam"I"am > SamIam > $ echo 'Sam"I"am' > Sam"I"am > > if your argument has single-quotes, you'll have to escape them, > in your preferred way of shell-single-quote-escaping, such as: > > $ echo 'Sam"I"a'"'"'m' > Sam"I"a'm > > -- > Steve Lane > ---------------------------------------------------------------------------- > To unsubscribe, please send email to majordomo@pm.org > with 'unsubscribe memphis-pm-list' in the body of the message. > ---------------------------------------------------------------------------- > > ---------------------------------------------------------------------------- > To unsubscribe, please send email to majordomo@pm.org > with 'unsubscribe memphis-pm-list' in the body of the message. > ---------------------------------------------------------------------------- -- Steve Lane ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From HPhillips at harrahs.com Tue Nov 12 13:46:40 2002 From: HPhillips at harrahs.com (Hal Phillips) Date: Thu Aug 5 00:07:20 2004 Subject: [Memphis.pm] quotes in program arguments Message-ID: Hah! The single quotes worked! So, as long as I never encounter those in the message body, I'm ok. Thanks Steve! -----Original Message----- From: Hal Phillips Sent: Tuesday, November 12, 2002 1:39 PM To: 'memphis-pm-list@pm.org' Subject: RE: [Memphis.pm] quotes in program arguments Hmmm,... I'll try the single quote thing. Thanks for the tip. It may work as long as the incomming message has no single quotes,... unfortunately the possibility is there and I cannot modify the message. Yes, I agree it is a shell issue and not a perl one specifically, however the shell is the interface used to call the perl, it would be nice to have away around this issue via an argument or switch... It's interesting that if the message is strictly STDIN, it works. i.e. >cat file_containing_message|program.pl while() { @array = split //; } foreach $c (@array) { if ( $c eq "\"" ) { $c = "\\$c"; } $newstring .= $c; } print $newstring; -----Original Message----- From: Steve Lane [mailto:sml@zfx.com] Sent: Tuesday, November 12, 2002 11:58 AM To: memphis-pm-list@pm.org Subject: Re: [Memphis.pm] quotes in program arguments Hal Phillips wrote: > Thanks, but the problem is that I can't modify the incoming message before I > see it. i don't understand why you can't just put single quotes around the argument, but anyway... you're S-O-L then. again, it's the shell, not perl, that's the cause of your problem. -- Steve > -----Original Message----- > From: Steve Lane [mailto:sml@zfx.com] > Sent: Tuesday, November 12, 2002 11:20 AM > To: memphis-pm-list@pm.org > Subject: Re: [Memphis.pm] quotes in program arguments > > Hal Phillips wrote: > > > > Hey, does anyone know how to tell perl to interpret quotes in a program > > argument as just part of a string? More precicely, I need something that > > basically will take the equivalant of echo's $* as a command argument. > > > > What I neet to do is have a perl program that I can to this with: > > >program.pl -o [2002-11-12 09:00:00]: subject=SOMETEXT, > > message={SEVERITY="ERROR", ACTION="None", MOREKEYS="MOREVALUES", ETC="ETC > > ETC ETC"} > [snip] > > > program.pl -o Sam"I"am > > SamIam > > > > what I need is Sam"I"am to actually make it through uninterpreted. > > this has nothing to do with Perl; it's a shell question. > your shell acts on the double-quotes before they ever reach > perl. the same would happen if you had any of [*?'><&] (etc) > in your argument. > > just single-quote your argument: > > $ echo Sam"I"am > SamIam > $ echo 'Sam"I"am' > Sam"I"am > > if your argument has single-quotes, you'll have to escape them, > in your preferred way of shell-single-quote-escaping, such as: > > $ echo 'Sam"I"a'"'"'m' > Sam"I"a'm > > -- > Steve Lane > ---------------------------------------------------------------------------- > To unsubscribe, please send email to majordomo@pm.org > with 'unsubscribe memphis-pm-list' in the body of the message. > ---------------------------------------------------------------------------- > > ---------------------------------------------------------------------------- > To unsubscribe, please send email to majordomo@pm.org > with 'unsubscribe memphis-pm-list' in the body of the message. > ---------------------------------------------------------------------------- -- Steve Lane ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From philarete at mindspring.com Thu Nov 14 18:22:18 2002 From: philarete at mindspring.com (Brock Sides) Date: Thu Aug 5 00:07:20 2004 Subject: [Memphis.pm] perl quiz of the week Message-ID: <20021114182218.A27650@harmless.yellowsnow.org> There's a new "Perl Quiz of the Week" list that the subscribers of this list might be interested in. Every Wednesday, there are two new Perl programming problems, one regular and one "expert". The expert problems have been very difficult so far. Solutions and discussion are posted the following week, and there's a separate discussion mailing list as well. You can subscribe by sending email to perl-qotw-subscribe@plover.com, or browse the mailing list archives (it's now in week 5) at . -- Brock Sides philarete@mindspring.com ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ----------------------------------------------------------------------------